From 3ce92e4534975918a3559ec4f77caf15c797d663 Mon Sep 17 00:00:00 2001
From: Alexander Bilz <mail@alexbilz.com>
Date: Wed, 21 Jul 2021 16:02:09 +0000
Subject: [PATCH] feat: added schema.org structured data

---
 layouts/partials/schema.html |  120 ++++++++++++++++++++++++++++++++++++++++
 layouts/partials/head.html   |    4 +
 2 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 768d0a3..5b20033 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -185,4 +185,8 @@
 
 
   {{- end }}
+
+
+  <!-- Schema.org-->
+  {{ partial "schema.html" . }}
 </head>
diff --git a/layouts/partials/schema.html b/layouts/partials/schema.html
new file mode 100644
index 0000000..f4778d5
--- /dev/null
+++ b/layouts/partials/schema.html
@@ -0,0 +1,120 @@
+{{ if .IsHome -}}
+  <script type="application/ld+json">
+    {
+      "@context": "http://schema.org",
+      "@type": "WebSite",
+      "name": "{{ .Site.Title }}",
+      "url": "{{ .Site.BaseURL }}",
+      "description": "{{ .Site.Params.description }}",
+      "thumbnailUrl": "{{ .Site.Params.Logo | absURL }}",
+      "license": "{{ .Site.Params.Copyright }}"
+    }
+  </script>
+
+{{ else if .IsPage }}
+  {{ $author :=  or (.Params.author) (.Site.Params.author) }}
+  {{ $org_name :=  .Site.Title }}
+  {{ $favicon := .Site.Params.favicon | absURL }}
+  <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" : {
+            "@type": "Person",
+            "name": "{{ $author }}"
+        },
+        "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 }},
+            "logo": {
+                "@type": "ImageObject",
+                "url": "{{ (printf "%s%s" $favicon "favicon-32x32.png") }}",
+                "width":"32",
+                "height":"32"
+            }
+        },
+        "image": {{ if .Params.images }}
+      [{{ range $i, $e := .Params.images }}
+        {{ if $i }}
+          ,
+
+        {{ end }}
+        {{ $e | absURL }}
+
+
+      {{ end }}
+      ]
+
+    {{ else }}
+      [{{ range $i, $e := .Site.Params.images }}
+        {{ if $i }}
+          ,
+
+        {{ end }}
+        {{ $e | absURL }}
+
+
+      {{ end }}
+      ]
+
+    {{ end }},
+        "url" : "{{ .Permalink }}",
+        "wordCount" : "{{ .WordCount }}",
+        "genre" : [ {{ range $index, $tag := .Params.categories }}
+      {{ if $index }}
+        ,
+
+      {{ end }}
+      "{{ $tag }}"
+
+    {{ end }}],
+        "keywords" : [ {{ range $index, $keyword := .Params.tags }}
+      {{ if $index }}
+        ,
+
+      {{ end }}
+      "{{ $keyword }}"
+
+    {{ end }}]
+    }
+  </script>
+
+{{ end }}

--
Gitblit v1.10.0