Skip to content

Commit

Permalink
feat: extend with keywords and categories
Browse files Browse the repository at this point in the history
Signed-off-by: barefootstache <[email protected]>
  • Loading branch information
barefootstache committed Sep 9, 2024
1 parent ba40802 commit 779c7e1
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions layouts/partials/opengraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,46 @@
<meta property="og:title" content="{{ $title }}" />
<meta property="og:description" content="{{ $summary }}" />
<meta property="og:image" content="{{ $image }}" />
{{- $keywords := "" }}
{{- $mergedKeywords := slice }}
{{- with $s.keywords }}
{{- $keywords = delimit $s.keywords "," }}
{{- range . }}
{{- $mergedKeywords = $mergedKeywords | append . }}
{{- end }}
{{- end }}
{{- with $p.keywords }}
{{- $keywords = delimit . "," }}
{{- range . }}
{{- $mergedKeywords = $mergedKeywords | append . }}
{{- end }}
{{- end }}
{{- with $s.tags }}
{{- range . }}
{{- $mergedKeywords = $mergedKeywords | append . }}
{{- end }}
{{- end }}
{{- with $keywords }}
<meta name="keywords" content="{{ $keywords }}" />
{{- with $p.tags }}
{{- range . }}
{{- $mergedKeywords = $mergedKeywords | append . }}
{{- end }}
{{- end }}
{{- $mergedKeywordsString := delimit $mergedKeywords "," }}
{{- with $mergedKeywordsString }}
<meta name="keywords" content="{{ $mergedKeywordsString }}" />
{{- end }}
{{- if eq .Section $s.blogDir -}}
{{- $date := ( .Date.Format "2006-02-01") -}}
{{- $date := (time .Date) }}
{{- $lastMod := (time .Lastmod) }}
{{- $categories := slice }}
{{- with $s.categories }}
{{- range . }}
{{- $categories = $categories | append . }}
{{- end }}
{{- end }}
{{- with $p.categories }}
{{- range . }}
{{- $categories = $categories | append . }}
{{- end }}
{{- end }}
<script type="application/ld+json">
{
"@context": "http://schema.org",
Expand All @@ -84,6 +110,10 @@
"url": "{{ $permalink }}",
"datePublished": {{ $date }},
"dateModified": {{ $lastMod }},
"keywords": {{ $mergedKeywords }},
{{- with $categories }}
"articleSection": {{ $categories }},
{{- end }}
"author": {
"@type": "Person",
"name": "{{ $author }}"
Expand Down

0 comments on commit 779c7e1

Please sign in to comment.