-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/hugomods/seo/modules/json-ld | ||
|
||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[params.hugopress.modules.seo-json-ld.hooks.head-begin] | ||
|
||
[params.hugopress.modules.seo-json-ld.hooks.body-end] |
1 change: 1 addition & 0 deletions
1
modules/json-ld/layouts/partials/hugopress/modules/seo-json-ld/hooks/body-end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{- partial "seo/modules/json-ld/script" .Page -}} |
1 change: 1 addition & 0 deletions
1
modules/json-ld/layouts/partials/hugopress/modules/seo-json-ld/hooks/head-begin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{- partial "seo/modules/json-ld/index" .Page -}} |
3 changes: 3 additions & 0 deletions
3
modules/json-ld/layouts/partials/seo/modules/json-ld/append.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{- $page := .page }} | ||
{{- $structure := partial (printf "seo/modules/json-ld/structures/%s" .structure) $page }} | ||
{{- $page.Store.SetInMap "seo-json-ld" (index $structure "@type") $structure }} |
10 changes: 10 additions & 0 deletions
10
modules/json-ld/layouts/partials/seo/modules/json-ld/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{- if .IsHome }} | ||
{{- partial "seo/modules/json-ld/append" (dict "page" . "structure" "website") }} | ||
{{- end }} | ||
{{- $params := default dict .Params.json_ld }} | ||
{{- $structures := slice "news-article" }} | ||
{{- range $structures }} | ||
{{- if isset $params . }} | ||
{{- partial "seo/modules/json-ld/append" (dict "page" . "structure" .) }} | ||
{{- end }} | ||
{{- end }} |
9 changes: 9 additions & 0 deletions
9
modules/json-ld/layouts/partials/seo/modules/json-ld/script.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{- with .Store.Get "seo-json-ld" }} | ||
{{- $json := . }} | ||
{{- if eq (len .) 1 }} | ||
{{- $json = jsonify (index (sort .) 0) }} | ||
{{- else }} | ||
{{- $json = jsonify . }} | ||
{{- end }} | ||
{{- $json | printf `<script type="application/ld+json">%s</script>` | safeHTML }} | ||
{{- end -}} |
13 changes: 13 additions & 0 deletions
13
modules/json-ld/layouts/partials/seo/modules/json-ld/structures/news-article.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{- $s := newScratch }} | ||
{{- $s.Set "@context" "https://schema.org" }} | ||
{{- $s.Set "@type" "NewsArticle" }} | ||
{{- $s.Set "headline" .Title }} | ||
{{- $s.Set "datePublished" .Date }} | ||
{{- with .Lastmod }} | ||
{{- $s.Set "dateModified" . }} | ||
{{- end }} | ||
{{- range partial "_funcs/get-page-images" . }} | ||
{{- $s.Add "image" (slice .Permalink) }} | ||
{{- end }} | ||
{{/* TODO: author */}} | ||
{{- return $s.Values }} |
6 changes: 6 additions & 0 deletions
6
modules/json-ld/layouts/partials/seo/modules/json-ld/structures/website.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{- return dict | ||
"@context" "https://schema.org" | ||
"@type" "WebSite" | ||
"name" (default site.Title site.Params.seo.json_ld.website.name) | ||
"url" site.Home.Permalink | ||
}} |