97 lines
No EOL
3.6 KiB
HTML
97 lines
No EOL
3.6 KiB
HTML
{{- define "partials/inline/breadcrumbData" -}}
|
|
{{- $scratchCtx := .scratch -}}
|
|
{{- with .parent }}
|
|
{{ partial "inline/breadcrumbData" (dict "scratch" $scratchCtx "parent" .Parent) }}
|
|
{{- $scratchCtx.Add "listItem" (slice (dict
|
|
"@type" "ListItem"
|
|
"position" ($scratchCtx.Get "count")
|
|
"name" (.Title | humanize | title)
|
|
"item" .Permalink
|
|
)) -}}
|
|
{{- $scratchCtx.Add "count" 1 -}}
|
|
{{- end }}
|
|
{{- end -}}
|
|
|
|
{{ if .IsHome -}}
|
|
<script type="application/ld+json">
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "WebSite",
|
|
"@id": "{{ (site.GetPage "/").Permalink | safeURL }}",
|
|
"name": "{{ .Site.Title | safeJS }}",
|
|
{{ with .Site.Params.description }}"description": "{{ . | safeJS }}",{{ end }}
|
|
{{ with .Site.LanguageCode }}"inLanguage": "{{ . }}",{{ end }}
|
|
"url": "{{ (site.GetPage "/").Permalink | safeURL }}",
|
|
{{ with .Site.Params.keywords }}"keywords": {{ . }},{{ end }}
|
|
"publisher" : {
|
|
"@type": "Person",
|
|
"name": "{{ .Site.Language.Params.Author.name | safeJS }}"
|
|
}
|
|
}
|
|
</script>
|
|
{{ else if .IsPage }}
|
|
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
|
|
{{- $summary := .Summary -}}
|
|
{{- $summary := replaceRE "<h[1-6][^>]*>(.*?)</h[1-6]>" "$1" $summary -}}
|
|
{{- $summary := replaceRE "\\s*<br\\s*/?>" " " $summary -}}
|
|
{{- $summary := replaceRE "\\s+" " " $summary -}}
|
|
{{- $summary := trim $summary " " -}}
|
|
<script type="application/ld+json">
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "Article",
|
|
"articleSection": "{{ (site.GetPage .Section).Title | safeJS }}",
|
|
"name": "{{ .Title | safeJS }}",
|
|
"headline": "{{ .Title | safeJS }}",
|
|
{{ with .Description }}"description": "{{ . | safeJS }}",{{ end }}
|
|
{{ with $summary }}"abstract": "{{ . | safeJS }}",{{ end }}
|
|
{{ with .Site.LanguageCode }}"inLanguage": "{{ . }}",{{ end }}
|
|
"url" : "{{ .Permalink }}",
|
|
"author" : {
|
|
"@type": "Person",
|
|
"name": "{{ .Site.Language.Params.Author.name | safeJS }}"
|
|
},
|
|
{{ with .PublishDate }}"copyrightYear": "{{ .Format "2006" }}",{{ end }}
|
|
{{ with .Date }}"dateCreated": "{{ .Format $iso8601 }}",{{ end }}
|
|
{{ with .PublishDate }}"datePublished": "{{ .Format $iso8601 }}",{{ end }}
|
|
{{ with .ExpiryDate }}"expires": "{{ .Format $iso8601 }}",{{ end }}
|
|
{{ with .Lastmod }}"dateModified": "{{ .Format $iso8601 }}",{{ end }}
|
|
{{ if .Keywords }}
|
|
{{ with .Keywords }}"keywords": {{ . }},{{ end }}
|
|
{{ else }}
|
|
{{ with .Params.tags }}"keywords": {{ . }},{{ end }}
|
|
{{ end }}
|
|
"mainEntityOfPage": "true",
|
|
"wordCount": "{{ .WordCount }}"
|
|
}
|
|
</script>
|
|
{{- /* Source: https://bullaki.com/projects/web-design/seo-with-hugo-5-breadcrumbs/ */}}
|
|
{{- $scratch := newScratch -}}
|
|
{{- $scratch.Set "count" 1 -}}
|
|
{{ partial "inline/breadcrumbData" (dict "scratch" $scratch "parent" .Parent) }}
|
|
|
|
{{- with index (.GetTerms "categories") 0 -}}
|
|
{{- $scratch.Add "listItem" (slice (dict
|
|
"@type" "ListItem"
|
|
"position" ($scratch.Get "count")
|
|
"name" .LinkTitle
|
|
"item" .Permalink
|
|
)) -}}
|
|
{{- $scratch.Add "count" 1 -}}
|
|
{{- end }}
|
|
|
|
|
|
{{- $scratch.Add "listItem" (slice (dict
|
|
"@type" "ListItem"
|
|
"position" ($scratch.Get "count")
|
|
"name" (.Title | humanize | title)
|
|
)) -}}
|
|
|
|
{{- $scratch.SetInMap "breadcrumb" "@context" "https://schema.org" -}}
|
|
{{- $scratch.SetInMap "breadcrumb" "@type" "BreadcrumbList" -}}
|
|
{{- $scratch.SetInMap "breadcrumb" "itemListElement" ($scratch.Get "listItem") -}}
|
|
|
|
<script type="application/ld+json">
|
|
{{ $scratch.Get "breadcrumb" | jsonify (dict "prefix" " " "indent" " ") | safeJS }}
|
|
</script>
|
|
{{- end }} |