Refactor schema values into vars

master
Will Faught 5 months ago
parent d13a32311e
commit 6b9a85a283

@ -15,25 +15,37 @@
{{ if $auto }} {{ if $auto }}
{{ $audio := $page.Params.audio | default slice }} {{ $audio := $page.Params.audio | default slice }}
{{ $authors := partial "paige/func-authors.html" $page }} {{ $authors := partial "paige/func-authors.html" $page }}
{{ $copyright := site.Copyright | markdownify | plainify | htmlUnescape }}
{{ $created := cond (and (not $page.Date.IsZero) (ne $page.Date $page.PublishDate)) $page.Date false }}
{{ $description := $page.Description | markdownify | plainify | htmlUnescape }}
{{ $expires := cond (not $page.ExpiryDate.IsZero) $page.ExpiryDate false }}
{{ $images := $page.Params.images | default slice }} {{ $images := $page.Params.images | default slice }}
{{ $keywords := sort (union (union $page.Keywords $page.Params.tags) $page.Params.categories) }} {{ $keywords := sort (union (union $page.Keywords $page.Params.tags) $page.Params.categories) }}
{{ $language := site.Language.LanguageCode }}
{{ $license := $page.Param "paige.site.license" | markdownify | plainify | htmlUnescape }} {{ $license := $page.Param "paige.site.license" | markdownify | plainify | htmlUnescape }}
{{ $modified := cond (not $page.Lastmod.IsZero) $page.Lastmod false }}
{{ $published := cond (and (not $page.PublishDate.IsZero) (ne $page.Date $page.PublishDate)) $page.PublishDate false }}
{{ $schema := newScratch }} {{ $schema := newScratch }}
{{ $section := $page.CurrentSection.Title }}
{{ $summary := $page.Summary | markdownify | plainify | htmlUnescape | chomp }}
{{ $time := printf "PT%dM" $page.ReadingTime }}
{{ $title := $page.Title | markdownify | plainify | htmlUnescape }}
{{ $videos := $page.Params.videos | default slice }} {{ $videos := $page.Params.videos | default slice }}
{{ $words := $page.WordCount }}
{{ $schema.Set "@context" "https://schema.org" }} {{ $schema.Set "@context" "https://schema.org" }}
{{ $schema.Set "@type" "Article" }} {{ $schema.Set "@type" "Article" }}
{{ $schema.Set "url" $page.Permalink }} {{ $schema.Set "url" $page.Permalink }}
{{ with $page.Summary }} {{ with $summary }}
{{ $schema.Set "abstract" (. | markdownify | plainify | htmlUnescape | chomp) }} {{ $schema.Set "abstract" . }}
{{ end }} {{ end }}
{{ with $page.Description }} {{ with $description }}
{{ $schema.Set "alternativeHeadline" (. | markdownify | plainify | htmlUnescape) }} {{ $schema.Set "alternativeHeadline" . }}
{{ end }} {{ end }}
{{ with $page.CurrentSection.Title }} {{ with $section }}
{{ $schema.Set "articleSection" . }} {{ $schema.Set "articleSection" . }}
{{ end }} {{ end }}
@ -78,32 +90,32 @@
{{ $schema.Set "author" $objects }} {{ $schema.Set "author" $objects }}
{{ end }} {{ end }}
{{ with site.Copyright }} {{ with $copyright }}
{{ $schema.Set "copyrightNotice" (. | markdownify | plainify | htmlUnescape) }} {{ $schema.Set "copyrightNotice" . }}
{{ end }} {{ end }}
{{ if and (not $page.Date.IsZero) (ne $page.Date $page.PublishDate) }} {{ with $created }}
{{ $schema.Set "dateCreated" $page.Date }} {{ $schema.Set "dateCreated" . }}
{{ end }} {{ end }}
{{ if not $page.Lastmod.IsZero }} {{ with $modified }}
{{ $schema.Set "dateModified" $page.Lastmod }} {{ $schema.Set "dateModified" . }}
{{ end }} {{ end }}
{{ with and (not $page.PublishDate.IsZero) (ne $page.Date $page.PublishDate) }} {{ with $published }}
{{ $schema.Set "datePublished" $page.PublishDate }} {{ $schema.Set "datePublished" . }}
{{ end }} {{ end }}
{{ with $page.Description }} {{ with $description }}
{{ $schema.Set "description" (. | markdownify | plainify | htmlUnescape) }} {{ $schema.Set "description" . }}
{{ end }} {{ end }}
{{ if not $page.ExpiryDate.IsZero }} {{ with $expires }}
{{ $schema.Set "expiresAt" $page.ExpiryDate }} {{ $schema.Set "expiresAt" . }}
{{ end }} {{ end }}
{{ with $page.Title }} {{ with $title }}
{{ $schema.Set "headline" (. | markdownify | plainify | htmlUnescape) }} {{ $schema.Set "headline" . }}
{{ end }} {{ end }}
{{ with $images }} {{ with $images }}
@ -189,8 +201,8 @@
{{ $schema.Set "image" $objects }} {{ $schema.Set "image" $objects }}
{{ end }} {{ end }}
{{ with site.Language }} {{ with $language }}
{{ $schema.Set "inLanguage" .Lang }} {{ $schema.Set "inLanguage" . }}
{{ end }} {{ end }}
{{ with $keywords }} {{ with $keywords }}
@ -201,12 +213,12 @@
{{ $schema.Set "license" . }} {{ $schema.Set "license" . }}
{{ end }} {{ end }}
{{ with $page.Title }} {{ with $title }}
{{ $schema.Set "name" (. | markdownify | plainify | htmlUnescape) }} {{ $schema.Set "name" . }}
{{ end }} {{ end }}
{{ with $page.ReadingTime }} {{ with $time }}
{{ $schema.Set "timeRequired" (printf "PT%dM" .) }} {{ $schema.Set "timeRequired" . }}
{{ end }} {{ end }}
{{ with $videos }} {{ with $videos }}
@ -219,7 +231,7 @@
{{ $schema.Set "video" $objects }} {{ $schema.Set "video" $objects }}
{{ end }} {{ end }}
{{ with $page.WordCount }} {{ with $words }}
{{ $schema.Set "wordCount" . }} {{ $schema.Set "wordCount" . }}
{{ end }} {{ end }}

Loading…
Cancel
Save