article.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {{ $page := .page }}
  2. {{ $summary := .summary }}
  3. {{ $featured_image := ($page.Resources.ByType "image").GetMatch "*featured*" }}
  4. {{/* Get schema type. */}}
  5. {{ $schema := "Article" }}
  6. {{ if eq $page.Type "post" }}
  7. {{ $schema = "BlogPosting" }}
  8. {{ end }}
  9. {{/* Get author name. */}}
  10. {{ $author_username := "" }}
  11. {{ if and (not $page.Params.authors) ($page.Scratch.Get "superuser_username") }}
  12. {{ $author_username = $page.Scratch.Get "superuser_username" }}
  13. {{ else if $page.Params.authors }}
  14. {{ $author_username = index $page.Params.authors 0 }}
  15. {{ end }}
  16. {{ $author := "" }}
  17. {{ $taxonomy := "authors" }}
  18. {{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_username) }}
  19. {{ with $profile_page }}
  20. {{ $author = .Params.name | default .Title }}
  21. {{ end }}
  22. {{ $publisher := site.Params.org_name | default site.Title }}
  23. {{ $logo_url := printf "img/%s" (site.Params.logo | default "icon-512.png") | absURL }}
  24. <script type="application/ld+json">
  25. {
  26. "@context": "https://schema.org",
  27. "@type": {{$schema}},
  28. "mainEntityOfPage": {
  29. "@type": "WebPage",
  30. "@id": {{$page.Permalink}}
  31. },
  32. "headline": {{$page.Title}},
  33. {{ if $featured_image }}
  34. "image": [
  35. {{$featured_image.Permalink}}
  36. ],
  37. {{end}}
  38. "datePublished": {{ $page.PublishDate.Format "2006-01-02T15:04:05Z07:00" }},
  39. "dateModified": {{ $page.Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
  40. {{with $author}}
  41. "author": {
  42. "@type": "Person",
  43. "name": {{.}}
  44. },
  45. {{end}}
  46. "publisher": {
  47. "@type": "Organization",
  48. "name": {{$publisher}},
  49. "logo": {
  50. "@type": "ImageObject",
  51. "url": {{$logo_url}}
  52. }
  53. },
  54. "description": {{$summary}}
  55. }
  56. </script>