Skip to content

Commit

Permalink
Merge pull request #476 from barefootstache/475-bug-opengraph-partial
Browse files Browse the repository at this point in the history
Fix opengraph partial ld+json never activated
  • Loading branch information
chipzoller authored Sep 23, 2024
2 parents 174847b + ec1894a commit c7cc97c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ These options set global values that some pages or all pages in the site use by
| showRelatedInSidebar | boolean | no |
| footerLogo | string | N/A |
| enableSearch | boolean | N/A |
| blogDir | string | no |

### Page Parameters

Expand Down
3 changes: 3 additions & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ languageMenuName = "🌐"
# Enable or disable comments globally. Default to true.
# comments = false

# Activate meta ld+json for blog
blogDir = "post"

# Enable or disable Utterances (https://github.com/utterance/utterances) Github Issue-Based Commenting
# utterances = true # Run the utterances script in the single.html layout to load https://utteranc.es comments
# utterancesRepo = "GHUsername/Repository.Name" # Utterances is enabled when this param is set
Expand Down
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 c7cc97c

Please sign in to comment.