opengraph.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {{- $summary := truncate 160 .Summary }}
  2. {{- $s := .Site.Params }}
  3. {{- $p := .Params }}
  4. {{- with $p.description }}
  5. {{- $summary = truncate 160 . }}
  6. {{- end }}
  7. {{- if .IsHome }}
  8. {{- $summary = $s.description }}
  9. {{- with $p.description }}
  10. {{- $summary = . }}
  11. {{- end }}
  12. {{- end }}
  13. {{- $site := .Site.Title }}
  14. {{- $title := .Title }}
  15. {{- $permalink := .Permalink }}
  16. {{- $logo := absURL $s.logo }}
  17. {{- $author := $s.author }}
  18. {{- with $p.author }}
  19. {{ $author := . }}
  20. {{- end }}
  21. {{- $image := absURL $s.fallBackOgImage }}
  22. {{- with $p.featureImage }}
  23. {{- $image = absURL . }}
  24. {{- end }}
  25. {{- with $p.thumbnail }}
  26. {{- $image = absURL . }}
  27. {{- end }}
  28. {{- with $p.shareImage }}
  29. {{- $image = absURL . }}
  30. {{- end }}
  31. <meta property="og:locale" content="{{ .Lang }}" />
  32. {{ range .Translations }}
  33. <meta property="og:locale:alternate" content="{{ .Lang }}" />
  34. {{ end }}
  35. {{- if .IsHome }}
  36. <meta property="og:type" content="website">
  37. {{- else }}
  38. <meta property="og:type" content="article">
  39. {{- end }}
  40. <meta name="description" content="{{ $summary }}">
  41. <meta name="twitter:card" content="{{ if $s.largeTwitterCard }}summary_large_image{{ else }}summary{{ end }}" />
  42. <meta name="twitter:creator" content="{{ $s.twitter }}">
  43. <meta name="twitter:title" content="{{ .Title }}" />
  44. <meta property="og:url" content="{{ $permalink }}" />
  45. <meta property="og:title" content="{{ $title }}" />
  46. <meta property="og:description" content="{{ $summary }}" />
  47. <meta property="og:image" content="{{ $image }}" />
  48. {{- if eq .Section $s.blogDir -}}
  49. {{- $date := ( .Date.Format "2006-02-01") -}}
  50. {{- $date := (time .Date) }}
  51. {{- $lastMod := (time .Lastmod) }}
  52. <script type="application/ld+json">
  53. {
  54. "@context": "http://schema.org",
  55. "@type": "BlogPosting",
  56. "mainEntityOfPage":"{{ $permalink }}",
  57. "name": "{{ $site }}",
  58. "headline": {{ $title }},
  59. "description": {{ $summary }},
  60. "url": "{{ $permalink }}",
  61. "datePublished": {{ $date }},
  62. "dateModified": {{ $lastMod }},
  63. "author": {
  64. "@type": "Person",
  65. "name": "{{ $author }}"
  66. },
  67. "image":{
  68. "@type":"ImageObject",
  69. "url": "{{ $image }}"
  70. },
  71. "publisher": {
  72. "@type": "Organization",
  73. "logo": {
  74. "@type":"ImageObject",
  75. "url": "{{ $logo }}"
  76. },
  77. "name": "{{ $site }}"
  78. }
  79. }
  80. </script>
  81. {{- end }}