-
-
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.
feat(json-ld): add support for FAQs structure (#27)
fix(json-ld): correct page context and transform structure template name
- Loading branch information
Showing
3 changed files
with
41 additions
and
5 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
7 changes: 4 additions & 3 deletions
7
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
{{- with .Store.Get "seo-json-ld" }} | ||
{{- $json := . }} | ||
{{- $structures := sort . }} | ||
{{- $json := "" }} | ||
{{- if eq (len .) 1 }} | ||
{{- $json = jsonify (index (sort .) 0) }} | ||
{{- $json = jsonify (index $structures 0) }} | ||
{{- else }} | ||
{{- $json = jsonify . }} | ||
{{- $json = jsonify $structures }} | ||
{{- end }} | ||
{{- $json | printf `<script type="application/ld+json">%s</script>` | safeHTML }} | ||
{{- end -}} |
34 changes: 34 additions & 0 deletions
34
modules/json-ld/layouts/partials/seo/modules/json-ld/structures/faq-page.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,34 @@ | ||
{{- $s := newScratch }} | ||
{{- $s.Set "@context" "https://schema.org" }} | ||
{{- $s.Set "@type" "FAQPage" }} | ||
{{- $params := default dict .Params.json_ld.faq_page }} | ||
{{- $data := default "" $params.data }} | ||
{{- $questionField := default "question" $params.question_field }} | ||
{{- $answerField := default "answer" $params.answer_field }} | ||
{{- $questions := slice }} | ||
{{- with index site.Data $data }} | ||
{{- range . }} | ||
{{- $question := "" }} | ||
{{- $answer := "" }} | ||
{{- with index . $questionField }} | ||
{{- $question = . }} | ||
{{- else }} | ||
{{- warnf "[seo|json-ld/faq] no such question field in %q data: %s" $data $questionField }} | ||
{{- continue }} | ||
{{- end }} | ||
{{- with index . $answerField }} | ||
{{- $answer = . | $.RenderString }} | ||
{{- else }} | ||
{{- warnf "[seo/json-ld/faq] no such answer field in %q data: %s" $data $questionField }} | ||
{{- continue }} | ||
{{- end }} | ||
{{- $s.Add "mainEntity" (slice (dict | ||
"@type" "Question" | ||
"name" $question | ||
"acceptedAnswer" (dict "@type" "Answer" "text" $answer))) | ||
}} | ||
{{- end }} | ||
{{- else }} | ||
{{- warnf "[seo/json-ld/faq] no such FAQs data: %q" $data }} | ||
{{- end }} | ||
{{- return $s.Values }} |