adding event schema for seo (#2528)

This commit is contained in:
trean
2026-07-24 12:01:30 +02:00
committed by GitHub
parent 068dd6d2d5
commit b03b657eca
5 changed files with 117 additions and 30 deletions
@@ -15,23 +15,16 @@
{{ end }}
{{ if .Params.seo_schema_json }}
<!-- if schema is defined in front matter as a list of json files -->
<!-- if schema is defined in front matter as a list of json files -->
{{- $context := . -}}
{{- range $index, $element := .Params.seo_schema_json -}}
{{- $template := resources.Get $element -}}
{{- $schema := $template | resources.ExecuteAsTemplate (printf "schema%d.json" $index) $context -}}
{{- $data := merge (dict "@context" "https://schema.org") ($schema | unmarshal) -}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph":
[
{{- $context := . -}}
{{- range $index, $element := .Params.seo_schema_json -}}
{{- $template := resources.Get $element -}}
{{- $schema := $template | resources.ExecuteAsTemplate (printf "schema%d.json" $index) $context -}}
{{ $schema | unmarshal }}
{{- if not (eq $index (sub (len $.Params.seo_schema_json) 1)) -}},
{{- end -}}
{{- end -}}
]
}
{{ $data | jsonify | safeJS }}
</script>
{{- end -}}
{{ else if .IsHome }}
{{ $organizationTemplate := resources.Get "schema/organization-schema.json" }}
{{ $organizationSchema := $organizationTemplate | resources.ExecuteAsTemplate "schema-organization-home.json" . }}
@@ -47,6 +40,24 @@
]
}
</script>
{{ else if and (eq .Section "events") (not .IsPage) }}
{{ $organizationTemplate := resources.Get "schema/organization-schema.json" }}
{{ $organizationTarget := printf "schema-org-events-%s.json" (replaceRE "(\\s)" "" .Params.title) }}
{{ $organizationSchema := $organizationTemplate | resources.ExecuteAsTemplate $organizationTarget . }}
{{- $orgData := merge (dict "@context" "https://schema.org") ($organizationSchema | unmarshal) -}}
<script type="application/ld+json">
{{ $orgData | jsonify | safeJS }}
</script>
{{- $eventTemplate := resources.Get "schema/event-schema.json" -}}
{{- range $index, $event := .Pages -}}
{{- if not $event.Params.start -}}{{- continue -}}{{- end -}}
{{- $target := printf "schema-event-%d-%s.json" $index (replaceRE "[^a-zA-Z0-9]+" "" $event.Title) -}}
{{- $schema := $eventTemplate | resources.ExecuteAsTemplate $target $event -}}
{{- $data := merge (dict "@context" "https://schema.org") ($schema | unmarshal) -}}
<script type="application/ld+json">
{{ $data | jsonify | safeJS }}
</script>
{{- end -}}
{{ else if or (in (slice "documentation" "benchmarks") .Section) (and (in (slice "blog" "articles") .Section) .IsPage) }}
{{ $organizationTemplate := resources.Get "schema/organization-schema.json" }}
{{ $organizationTarget := printf "schema-org-1-%s.json" (replaceRE "(\\s)" "" .Params.title) }}