Skip to content

Commit

Permalink
Add structure data JSON-LD
Browse files Browse the repository at this point in the history
  • Loading branch information
chringel21 committed Aug 25, 2022
1 parent e64bd69 commit 34cfe9e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{ template "partials/favicons.html" . }}
{{ template "partials/site_schema.html" . }}
<link
rel="preload"
href="/fonts/Comfortaa-Light.ttf"
Expand Down
66 changes: 66 additions & 0 deletions layouts/partials/site_schema.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/* https://codingnconcepts.com/hugo/structure-data-json-ld-hugo/ */}}
{{ if .IsHome -}}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "{{ .Site.Title }}",
"url": "{{ .Site.BaseURL }}",
"description": "{{ .Site.Params.description }}",
{{ with .Site.Params.favicons.icon32 }}"thumbnailUrl": "{{ . | absURL }}",{{ end }}
"license": "{{ .Site.Copyright }}"
}
</script>
{{ else if .IsPage }}
{{ $author := or (.Params.author) (.Site.Author.name) }}
{{ $org_name := .Site.Title }}<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"articleSection": "{{ .Section }}",
"name": "{{ .Title | safeJS }}",
"headline": "{{ .Title | safeJS }}",
"alternativeHeadline": "{{ .Params.lead }}",
"description": "{{ if .Description }}{{ .Description | safeJS }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}",
"inLanguage": {{ .Site.LanguageCode | default "en-us" }},
"isFamilyFriendly": "true",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ .Permalink }}"
},
"author" : {
"@type": "Person",
"name": "{{ $author }}"
},
"creator" : {
"@type": "Person",
"name": "{{ $author }}"
},
"accountablePerson" : {
"@type": "Person",
"name": "{{ $author }}"
},
"copyrightHolder" : "{{ $org_name }}",
"copyrightYear" : "{{ .Date.Format "2006" }}",
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"publisher":{
"@type":"Organization",
"name": {{ $org_name }},
"url": {{ .Site.BaseURL }},
{{ with .Site.Params.favicons.icon32 }}"logo": {
"@type": "ImageObject",
"url": "{{ . | absURL }}",
"width":"32",
"height":"32"{{ end }}
}
},
"image": {{ if .Params.images }}[{{ range $i, $e := .Params.images }}{{ if $i }}, {{ end }}{{ $e | absURL }}{{ end }}]{{ else if .Params.cover.src }}{{ ($.Page.Resources.GetMatch .Params.cover.src).Permalink }}{{ else}}{{ .Site.Params.favicons.icon32 | absURL }}{{ end }},
"url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}",
"genre" : [ {{ range $index, $category := .Params.categories }}{{ if $index }}, {{ end }}"{{ $category }}" {{ end }}],
"keywords" : [ {{ range $index, $tag := .Params.tags }}{{ if $index }}, {{ end }}"{{ $tag }}" {{ end }}]
}
</script>
{{ end }}

0 comments on commit 34cfe9e

Please sign in to comment.