Help with schema.org structure

Hi guys, i’m developing my first hugo website and i’m trying to do the site schema.
The problem is that when i use google search console, i have this error:

Parsing error: Missing '}' or object member name

All day that i search for some } missing but i can’t found it.
Do you know what is the problem?
This is the code of my site schema:
Thank you very much

{{ if .IsHome -}}
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "url": "{{ .Site.BaseURL }}",
  {{ if .Site.Params.author -}}
  "author": {
    "@type": "Person",
    "name": "{{ .Site.Params.author }}"
  },
  {{- end }}
  {{ if .Site.Params.description -}}
  "description": "{{ .Site.Params.description }}",
  {{- end }}
  {{ with .Site.Params.image -}}
  "image": "{{ .url | absURL }}",
  {{- end }}
  {{ with .Site.Params.logo -}}
  "thumbnailUrl": "{{ .url | absURL }}",
  {{- end }}
  "name": "{{ .Site.Title }}"
}
</script>
{{/*
  "potentialAction": {
    "@type": "SearchAction",
    "target": "http://example.com/search?&q={query}",
    "query-input": "required"
  } */}}
{{- else if .IsPage -}}
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "BlogPosting",
  "headline": "{{ .Title }}",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "{{ .Permalink }}"
  },
  "genre": "{{ .Type }}",
  {{ with .Params.tags -}}
  "keywords": "{{ delimit . ", " }}",
  {{- end }}
  "wordcount": {{ .WordCount }},
  "url": "{{ .Permalink }}",
  {{ if not .PublishDate.IsZero -}}
  "datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
  {{- else if not .Date.IsZero -}}
  "datePublished": "{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
  {{- end }}
  {{ with .Lastmod -}}
  "dateModified": "{{ .Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
  {{- end }}
  {{ with .Site.Params.publisher -}}
  "publisher": {
    "@type": "Organization",
    "name": "{{ .name }}",
    "logo": {
      "@type": "ImageObject",
      "url": "{{ .logo.url | absURL }}",
      "width": {{ .logo.width }},
      "height": {{ .logo.height }}
    }
  },
  {{- end }}
  {{ if .Params.author -}}
  "author": {
    "@type": "Person",
    "name": "{{ .Params.author }}"
  },
  {{- else if .Site.Author.name -}}
  "author": {
    "@type": "Person",
    "name": "{{ .Site.Author.name }}"
  },
  {{- end }}
  "description": "{{ .Description }}"
}
</script>
{{- end }}

You are already inside a JSON context and Hugo can handle it fairly well. Try removing the " you have in the variables:

"url": "{{ .Site.BaseURL }}",
becomes
"url": {{ .Site.BaseURL }},

1 Like

for correct value formats - use this function

It didn’t work, always same problem

I’ve tried to add jsonify to all my params like this:
{{ .Site.Params.author | jsonify}}

but nothing change :frowning:

change

{{ if .Site.Params.author -}}

to

{{ with .Site.Params.author -}}

from my config

[Author]
    name               = "my name"
    email              = "my e-mail"

from my templates

{{ with site.Author.name  }}
      {  "name"  : {{ . | jsonify }}  },  
{{ end }}

No way i really don’t understand, also because testing my site with google website testing tool i have no error.
As you can see below.

this is the link of the repo if it could be helpfull

HI

the source looks good. What’s now your problem???

PS:

I use the Dublin Core tags (not the Google own tags)

Hi, this morning I’ve done a modify to the code and it seems to work, google has started the convalidation phase. If it will works I’m going to update you.
For now thank you very much for helping me :smiley:
This is the new code’s version:

<script type="application/ld+json">
  {
    "@context": "https://schema.org",
    {{ if .IsPage -}}
    "@type": {{ if or (eq .Section "blog") (eq .Section "post") }}"BlogPosting"{{ else }}"WebPage"{{ end }},
    "headline": {{ .Title }},
    "datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
    "dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
    "url" : {{ .Permalink }},
    "description": {{ with (.Description | default (replaceRE "\n" " " (.Summary | truncate 170))) }}{{ . }}{{ end }},
    {{ with .Params.tags -}}
    "keywords": {{ . }},
    {{ end -}}
    {{ else -}}
    "@type": "WebPage",
    "url" : {{ .Permalink }},
    "name": {{ .Title }},
    {{ with $.Param "description" -}}
    "description": {{ . }},
    {{ end -}}
    {{ end -}}
    {{ with $.Param "image" -}}
    "image" : {{ . | absURL }},
    {{ end -}}
    {{ with $.Param "author" -}}
    "author": {
      "@type": "Person",
      "name": {{ . }}
    },
    {{ end -}}
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": {{ .Site.BaseURL }}
    },
    "publisher": {
      "@type": "Organization",
      "name": {{ .Site.Title  }},
      {{ with $.Param "icon" -}}
      "logo" : {
        "@type": "ImageObject",
        "url": {{ . | absURL }}
      },
      {{ end -}}
      "url": {{ .Site.BaseURL }}
    }
  }
</script>
1 Like

https://www.dublincore.org/ is built with Hugo!

@ju52 can you share your Dublin Core head.html partial?

it’s here

and the rest of my sample

Thanks!

Hi, I’m using your schema partial in my site, and I have in config.toml

[params.logo]
url = “logo.png”

and a logo.png in /static/ but the schema output in page source does not include the logo.png:

@context": “https://schema.org”,
@type”: “WebPage”,
“url” : “http://localhost:1313/”,
“name”: “Example Site”,
“description”: “Example Site”,
“mainEntityOfPage”: {
@type”: “WebPage”,
@id”: “http://localhost:1313/
},
“publisher”: {
@type”: “Organization”,
“name”: “Example Site”,
“url”: “http://localhost:1313/

I’ve looked at your git https://github.com/hobbit-xD/eventi-biella/blob/master/themes/eventi/layouts/partials/site-schema.html but that doesn’t help. Does your site-schema.html partial output the logo?

Thanks

Hi dude, if you want to add the logo image in your schema, try adding the following line:

“image” : “{{ .Params.logo | absURL }}”,

You can check another my schema file of another one my website at the following link: https://github.com/hobbit-xD/LuBlog/blob/master/themes/lublog-theme/layouts/partials/site-schema.html
Im here if you have any questions.

Good luck

Thanks! Finally figured out what I was doing wrong.

For this in the partial

{{ with $.Param “image” -}}
“image” : {{ . | absURL }},

use this in config.toml

image = “og-image.png”

for the image og-image.png in /static/

Nice to hear, very good
have a good time