From bcacae10c0fd46f89b98b124fe871be731eca437 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Tue, 21 Jan 2025 22:30:44 -0800 Subject: [PATCH] Add microdata --- README.md | 14 ++++++++++++++ layouts/_default/baseof.html | 11 ++++++++++- layouts/partials/paige/page-header.html | 17 +++++++++-------- layouts/partials/paige/site-footer.html | 3 ++- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a0885234..90f9a17b 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,17 @@ disable_toc = false # url = "https://example.com" base_schema = {} +# paige.page.microdata specifies the SEO microdata non-property attributes (all except itemprop) for the web page. +# +# Example: +# +# [paige.page.microdata] +# itemid = "123" +# itemref = "foo" +# itemscope = "" +# itemtype = "https://schema.org/Chapter +microdata = {} + # paige.page.schemas is the page JSON-LD schemas. # # Examples: @@ -453,6 +464,9 @@ or for pages with `paige.pages.schemas`, at the site or page level. A base schema can be specified for site schemas with `paige.site.base_schema`, and for page schemas with `paige.page.base_schema`. +HTML microdata is generated from the page parameters +if the non-property attributes are specified in `paige.page.microdata`. + ## Layouts ### Cloud diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index b5be4afd..667f82e3 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,5 +1,14 @@ {{ $page := . }} +{{ $itemattrs := slice }} +{{ $microdata := $page.Params.paige.page.microdata }} + +{{ range $k, $v := $microdata }} + {{ $itemattrs = $itemattrs | append (printf `%s="%v"` $k $v) }} +{{ end }} + +{{ $itemattrs = delimit (sort $itemattrs) " " }} + {{ partial "paige/tag-html.html" $page }} {{ partial "paige/tag-head.html" $page }} @@ -10,7 +19,7 @@
-
+
{{ if templates.Exists "partials/paige/site-first.html" }} {{ partial "paige/site-first.html" $page }} {{ end }} diff --git a/layouts/partials/paige/page-header.html b/layouts/partials/paige/page-header.html index da1f0153..933e906c 100644 --- a/layouts/partials/paige/page-header.html +++ b/layouts/partials/paige/page-header.html @@ -9,6 +9,7 @@ {{ $first := templates.Exists "partials/paige/page-header-first.html" }} {{ $last := templates.Exists "partials/paige/page-header-last.html" }} {{ $link := $page.Params.link }} +{{ $microdata := $page.Params.paige.page.microdata }} {{ $readingtime := $page.ReadingTime | and ($page.Param "paige.page.disable_reading_time" | not) }} {{ $series := $page.GetTerms "series" | and ($page.Param "paige.page.disable_series" | not) }} {{ $tags := $page.GetTerms "tags" }} @@ -26,11 +27,11 @@ {{ end }} {{ with $title }} -

{{ if $link }}{{ . }}{{ else }}{{ . }}{{ end }}

+

{{ if $link }}{{ . }}{{ else }}{{ . }}{{ end }}

{{ end }} {{ with $description }} -

{{ . }}

+

{{ . }}

{{ end }} {{ if or $authors $date $keywords $readingtime $series }} @@ -49,11 +50,11 @@ {{- if $textkeywords -}} {{- if gt $i 0 }} · {{ end -}} - {{ .Title }} + {{ .Title }} {{- else -}} {{- if gt $i 0 }} {{ end -}} - {{ .Title }} + {{ .Title }} {{- end -}} {{- end }}

@@ -64,7 +65,7 @@ {{ range $i, $series := . -}} {{- if gt $i 0 }} · {{ end -}} - {{ .Title }} + {{ .Title }} {{- end }}

{{ end }} @@ -74,19 +75,19 @@ {{ range $i, $author := . -}} {{- if gt $i 0 }} · {{ end -}} - {{ .Title }} + {{- end }}

{{ end }} {{ with $date }}

- +

{{ end }} {{ with $readingtime }} -

{{ . }} {{ i18n "paige_minutes" . }}

+

{{ . }} {{ i18n "paige_minutes" . }}

{{ end }}
{{ end }} diff --git a/layouts/partials/paige/site-footer.html b/layouts/partials/paige/site-footer.html index 8ed2ba14..d5ebb1d8 100644 --- a/layouts/partials/paige/site-footer.html +++ b/layouts/partials/paige/site-footer.html @@ -5,6 +5,7 @@ {{ $first := templates.Exists "partials/paige/footer-first.html" }} {{ $last := templates.Exists "partials/paige/footer-last.html" }} {{ $license := $page.Param "paige.license" | markdownify | and ($page.Param "paige.site.disable_license" | not) }} +{{ $microdata := $page.Params.paige.page.microdata }} {{ $theme := "https://github.com/willfaught/paige" }} {{ $target := partial "paige/target.html" (dict "page" $page "url" $theme) }} @@ -30,7 +31,7 @@ {{ end }} {{ with $copyright }} - + {{ end }} {{ with $license }}