How can I assign schema markup (JSON) to certain pages of my website?
I have a website with tutorials and most pages use https://schema.org/TechArticle.
But:
I also have an about page, which should get: https://schema.org/AboutPage.
And a contact page, which should get:https://schema.org/ContactPage.
And a few pages that I want to give: https://schema.org/WebPage (other pages of my website).
I now have a site-schema.html file with the following lines:
{{- if .IsHome -}}
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"WebSite",
"name":"{{ .Site.Params.name }}",
"url":"{{ .Site.BaseURL }}",
"image":"{{ .Site.Params.image }}"
}}
</script>
{{- end }}
{{- if .IsPage -}}
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"TechArticle",
"name":"{{ .Title }}",
"headline":"{{ .Title }}",
"description":"{{ .Description }}",
"url":"{{ .Permalink }}",
"image":"{{ .Site.BaseURL }}{{ .Params.image }}",
"author":{
"@type":"Person",
"name":"{{ .Site.Params.author }}"},
"publisher":{
"@type":"Organization",
"name":"{{ .Site.Params.name }}",
"logo":{
"@type":"ImageObject",
"url":"{{ .Site.Params.logo }}"}},
"mainEntityOfPage": {
"@type":"WebPage",
"@id":"{{ .Permalink }}"},
{{ if not .Date.IsZero -}}"datePublished":"{{ .Date.Format "2006-01-02" | safeHTML }}",{{- end }}
{{ with .Lastmod -}}"dateModified":"{{ .Format "2006-01-02" | safeHTML }}"{{- end }}
},}
</script>
{{- end }}