Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opengraph partial ld+json never activated #476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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