Browse Source

refactor: convert Event Microdata to JSONLD

Requires further work to add support for full semantic event address.

Forms part of the transition from Microdata to JSON-LD.

See #413
George Cushen 5 năm trước cách đây
mục cha
commit
1b2e20cc2a

+ 23 - 23
layouts/partials/jsonld/article.html

@@ -23,27 +23,27 @@
 {{ end }}
 
 <script type="application/ld+json">
-  {
-    "@context": "https://schema.org",
-    "@type": {{$schema}},
-    "mainEntityOfPage": {
-      "@type": "WebPage",
-      "@id": {{$page.Permalink}}
-    },
-    "headline": {{$page.Title}},
-    {{ if $featured_image }}
-    "image": [
-      {{$featured_image.Permalink}}
-    ],
-    {{end}}
-    "datePublished": {{ $page.PublishDate.Format "2006-01-02T15:04:05Z07:00" }},
-    "dateModified": {{ $page.Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
-    {{with $author}}
-    "author": {
-      "@type": "Person",
-      "name": {{.}}
-    },
-    {{end}}
-    "description": {{$summary}}
-  }
+{
+  "@context": "https://schema.org",
+  "@type": {{$schema}},
+  "mainEntityOfPage": {
+    "@type": "WebPage",
+    "@id": {{$page.Permalink}}
+  },
+  "headline": {{$page.Title}},
+  {{ if $featured_image }}
+  "image": [
+    {{$featured_image.Permalink}}
+  ],
+  {{end}}
+  "datePublished": {{ $page.PublishDate.Format "2006-01-02T15:04:05Z07:00" }},
+  "dateModified": {{ $page.Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
+  {{with $author}}
+  "author": {
+    "@type": "Person",
+    "name": {{.}}
+  },
+  {{end}}
+  "description": {{$summary}}
+}
 </script>

+ 51 - 0
layouts/partials/jsonld/event.html

@@ -0,0 +1,51 @@
+{{ $page := .page }}
+{{ $summary := .summary }}
+{{ $featured_image := ($page.Resources.ByType "image").GetMatch "*featured*" }}
+
+{{/* Get author name. */}}
+{{ $author_username := "" }}
+{{ if and (not $page.Params.authors) ($page.Scratch.Get "superuser_username") }}
+  {{ $author_username = $page.Scratch.Get "superuser_username" }}
+{{ else if $page.Params.authors }}
+  {{ $author_username = index $page.Params.authors 0 }}
+{{ end }}
+{{ $author := "" }}
+{{ $taxonomy := "authors" }}
+{{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_username) }}
+{{ with $profile_page }}
+  {{ $author = .Params.name | default .Title }}
+{{ end }}
+
+<script type="application/ld+json">
+{
+  "@context": "https://schema.org",
+  "@type": "Event",
+  "mainEntityOfPage": {
+    "@type": "WebPage",
+    "@id": {{$page.Permalink}}
+  },
+  "name": {{$page.Title}},
+  {{ with $page.Params.location }}
+  "location": {
+    "@type": "Place",
+    "name": {{. | plainify}}
+  },
+  {{end}}
+  {{ if $featured_image }}
+  "image": [
+    {{$featured_image.Permalink}}
+  ],
+  {{end}}
+  "startDate": {{ $page.Date.Format "2006-01-02T15:04:05Z07:00" }},
+  {{with $page.Params.date_end}}
+  "endDate": {{ (time .).Format "2006-01-02T15:04:05Z07:00" }},
+  {{end}}
+  {{with $author}}
+  "performer": {
+    "@type": "Person",
+    "name": {{.}}
+  },
+  {{end}}
+  "description": {{$summary}}
+}
+</script>

+ 4 - 0
layouts/partials/jsonld/main.html

@@ -11,4 +11,8 @@
     {{ partial "jsonld/article.html" (dict "page" $page "summary" $summary) }}
   {{ end }}
 
+  {{ if eq $page.Type "talk" }}
+    {{ partial "jsonld/event.html" (dict "page" $page "summary" $summary) }}
+  {{ end }}
+
 {{- end }}

+ 3 - 3
layouts/talk/single.html

@@ -1,6 +1,6 @@
 {{- define "main" -}}
 
-<div class="pub" itemscope itemtype="http://schema.org/Event">
+<div class="pub">
 
   {{ partial "page_header.html" . }}
 
@@ -8,7 +8,7 @@
 
     {{ if .Params.abstract }}
       <h3>{{ i18n "abstract" }}</h3>
-      <p class="pub-abstract" itemprop="text">{{ .Params.abstract | markdownify | emojify }}</p>
+      <p class="pub-abstract">{{ .Params.abstract | markdownify | emojify }}</p>
     {{ else }}
       <br>
     {{ end }}
@@ -18,7 +18,7 @@
       <div class="col-md-10">
         <div class="row">
           <div class="col-12 col-md-3 pub-row-heading">{{ i18n "date" }}</div>
-          <div class="col-12 col-md-9" itemprop="datePublished">
+          <div class="col-12 col-md-9">
             {{ partial "functions/get_event_dates" . }}
           </div>
         </div>