Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Unparsable Structured Data #113

Closed
PhasecoreX opened this issue Feb 12, 2022 · 2 comments
Closed

Google Unparsable Structured Data #113

PhasecoreX opened this issue Feb 12, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@PhasecoreX
Copy link

What happened?

Google's site crawler notified me of an "unparsable structured data" issue, located on the main page.

"publisher" : {
"@type": "Person",
"name": "{{ .Site.Author.name | safeJS }}",
},
{{ with .Site.Params.keywords }}"keywords": {{ . }},{{ end }}
}
</script>

Since I didn't have keywords on my home page, line 15 doesn't happen, leaving line 14 with a trailing comma that Google and JSON doesn't like:

<script type="[application/ld+json]()">
  {
    "@context": "https://schema.org",
    "@type": "WebSite",
    "@id": "http:\/\/localhost:1313\/",
    "name": "My Blog",
    "description": "My description",
    "inLanguage": "en",
    "url": "http:\/\/localhost:1313\/",
    "publisher" : {
      "@type": "Person",
      "name": "PhasecoreX",
    },
    
  }
  </script>

I figured I would try to add keywords to my blog, so I added them to my languages.en.toml like so:

keywords = ["keyword1", "keyword2", "keyword3"]

Not sure if this is where they are supposed to go or if it's the correct format, as I couldn't find any documentation, but it does populate it on the home page. However, it too has a trailing comma:

<script type="[application/ld+json]()">
  {
    "@context": "https://schema.org",
    "@type": "WebSite",
    "@id": "http:\/\/localhost:1313\/",
    "name": "My Blog",
    "description": "My description",
    "inLanguage": "en",
    "url": "http:\/\/localhost:1313\/",
    "publisher" : {
      "@type": "Person",
      "name": "PhasecoreX",
    },
    "keywords": ["keyword1","keyword2","keyword3"],
  }
  </script>

I think maybe it's just taking that whole list and placing it on the page as is, with that extra comma from {{ . }},{{ end }} after it. Thought it would loop over the values, but I guess not.

Theme version

v2.0.4

Hugo version

v0.92.2

What browsers are you seeing the problem on?

Firefox

Relevant Hugo log output

No response

@PhasecoreX PhasecoreX added the bug Something isn't working label Feb 12, 2022
@jpanther
Copy link
Owner

Thanks, this is definitely a bug. I'll make some adjustments to try to remove these erroneous commas.

keywords is a Hugo front matter parameter separate to the theme. You can find the documentation on these predefined params at the official Hugo docs: https://gohugo.io/content-management/front-matter#predefined

@PhasecoreX
Copy link
Author

Ah that makes sense, forgot that there are Hugo predefined front matter parameters. Thanks for fixing this! Very clean, just having to swap the two lines around to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants