- layouts/partials/head.html: full <head> partial with meta partials + CSS pipeline - layouts/partials/meta/seo.html: canonical URL + robots directives - layouts/partials/meta/og.html: Open Graph + Twitter Card meta tags - layouts/partials/meta/ai-disclosure.html: AI content disclosure (EU AI Act) - layouts/partials/meta/json-ld.html: Schema.org JSON-LD structured data - layouts/partials/tag-nav.html: site-wide tag cloud partial - layouts/_default/baseof.html: simplified to use partial head.html - layouts/_default/single.html: removed inline head block (now in head.html) Verified: canonical, robots, OG tags, ai-content-disclosure on live pages. 96 pages build clean. Closes: asw#15
101 lines
3.6 KiB
HTML
101 lines
3.6 KiB
HTML
{{- /*
|
|
partials/meta/json-ld.html — JSON-LD structured data (Schema.org)
|
|
|
|
Emits one <script type="application/ld+json"> block per page.
|
|
Uses dict → jsonify → safeHTML to avoid Hugo's JS-context escaping.
|
|
|
|
Schema selection:
|
|
Home page → WebSite (with SearchAction if params.search_url set)
|
|
Docs pages → TechArticle (front matter: type = "docs")
|
|
Dated pages → Article
|
|
Everything else → WebPage
|
|
|
|
BreadcrumbList appended when .Ancestors is non-empty.
|
|
|
|
Configure in hugo.toml:
|
|
[params]
|
|
author = "Trentuna" # publisher/author name
|
|
logo = "/images/logo.png" # site logo for publisher
|
|
search_url = "/search/?q={q}" # enables SearchAction on WebSite
|
|
*/ -}}
|
|
{{- $author := or .Site.Params.author .Site.Title -}}
|
|
{{- $logo := .Site.Params.logo | default "" -}}
|
|
{{- $desc := or .Description .Site.Params.description "" -}}
|
|
{{- $image := or .Params.image .Site.Params.og_image "" -}}
|
|
|
|
{{- if .IsHome -}}
|
|
|
|
{{- /* ── WebSite ──────────────────────────────────────────────────── */}}
|
|
{{- $data := dict
|
|
"@context" "https://schema.org"
|
|
"@type" "WebSite"
|
|
"name" .Site.Title
|
|
"url" .Site.BaseURL
|
|
"description" $desc
|
|
-}}
|
|
{{- with .Site.Params.search_url -}}
|
|
{{- $action := dict
|
|
"@type" "SearchAction"
|
|
"target" (dict "@type" "EntryPoint" "urlTemplate" (printf "%s%s" $.Site.BaseURL .))
|
|
"query-input" "required name=q"
|
|
-}}
|
|
{{- $data = merge $data (dict "potentialAction" $action) -}}
|
|
{{- end -}}
|
|
{{- printf "<script type=\"application/ld+json\">%s</script>" ($data | jsonify) | safeHTML -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- /* ── Article / TechArticle / WebPage ─────────────────────────── */}}
|
|
{{- $schemaType := "WebPage" -}}
|
|
{{- if and .IsPage (not .IsSection) -}}
|
|
{{- if eq .Params.type "docs" -}}
|
|
{{- $schemaType = "TechArticle" -}}
|
|
{{- else if .Date -}}
|
|
{{- $schemaType = "Article" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $publisher := dict "@type" "Organization" "name" $author -}}
|
|
{{- with $logo -}}
|
|
{{- $publisher = merge $publisher (dict "logo" (dict "@type" "ImageObject" "url" (. | absURL))) -}}
|
|
{{- end -}}
|
|
|
|
{{- $data := dict
|
|
"@context" "https://schema.org"
|
|
"@type" $schemaType
|
|
"headline" .Title
|
|
"description" $desc
|
|
"url" .Permalink
|
|
"author" $publisher
|
|
"publisher" $publisher
|
|
-}}
|
|
|
|
{{- with $image -}}
|
|
{{- $data = merge $data (dict "image" (. | absURL)) -}}
|
|
{{- end -}}
|
|
|
|
{{- if and .Date (not .IsSection) -}}
|
|
{{- $data = merge $data (dict
|
|
"datePublished" (.Date.Format "2006-01-02T15:04:05Z07:00")
|
|
"dateModified" (.Lastmod.Format "2006-01-02T15:04:05Z07:00")
|
|
) -}}
|
|
{{- end -}}
|
|
|
|
{{- /* BreadcrumbList: .Ancestors is nearest→root; iterate by index to reverse */}}
|
|
{{- with .Ancestors -}}
|
|
{{- $ancs := . -}}
|
|
{{- $len := len $ancs -}}
|
|
{{- $items := slice -}}
|
|
{{- range $i := seq $len -}}
|
|
{{- $a := index $ancs (sub $len $i) -}}
|
|
{{- $item := dict "@type" "ListItem" "position" $i "name" $a.Title "item" $a.Permalink -}}
|
|
{{- $items = $items | append $item -}}
|
|
{{- end -}}
|
|
{{- $last := dict "@type" "ListItem" "position" (add $len 1) "name" $.Title "item" $.Permalink -}}
|
|
{{- $items = $items | append $last -}}
|
|
{{- $crumb := dict "@type" "BreadcrumbList" "itemListElement" $items -}}
|
|
{{- $data = merge $data (dict "breadcrumb" $crumb) -}}
|
|
{{- end -}}
|
|
|
|
{{- printf "<script type=\"application/ld+json\">%s</script>" ($data | jsonify) | safeHTML -}}
|
|
{{- end }}
|