Skip to content

[Bug]: schema_json.html#1773

@cnzixn

Description

@cnzixn

What happened?

机器翻译:

I encountered an error while building the website:

hugo --gc --noBuildLock Start building sites … hugo v0.141.0+extended android/arm64 BuildDate=unknown Total in 3471 ms Error: error building site: render: failed to render pages: failed to process "/aaa/bbb/index.html": "/data/data/com.termux/files/usr/tmp/hugo-transform-error231535155:95:40": expected comma character or an array or object ending on line 95 and column 40 12:{^ 

After troubleshooting, I found that the issue was with schema_json.html . With the help of AI, I have fixed it. Here's part of the code (lines 1-22):

{{if .IsHome }} <script type="application/ld+json">{"@context": "https://schema.org", "@type": "{{(site.Params.schema.publisherType | default "Organization") | title }}", "name": "{{site.Title }}", "url": "{{site.Home.Permalink }}", "description": "{{site.Params.description | plainify | truncate 180 | safeHTML }}",{{- if eq site.Params.schema.publisherType "Person" }} "image": "{{site.Params.assets.favicon | default "favicon.ico" | absURL }}",{{- else }} "logo": "{{site.Params.assets.favicon | default "favicon.ico" | absURL }}",{{- end }} "sameAs": [{{- if site.Params.schema.sameAs }}{{range $i, $e := site.Params.schema.sameAs }}{{if $i }},{{end }}"{{trim $e " " }}"{{end }}{{- else}}{{range $i, $e := site.Params.SocialIcons }}{{if $i }},{{end }}"{{trim $e.url " " | safeURL }}"{{end }}{{- end}} ] } </script> 

Here's the explanation of the fixes provided by the AI:

  • All fields (such as name , url , description , etc.) are enclosed in double quotes "" to comply with JSON syntax requirements (e.g., changing{{site.Title }} to "{{site.Title }}" ).

  • Fixed comma issues in lists:

  • Added double quotes to each element in arrays like sameAs and keywords (e.g., changing{{$e }} to "{{$e }}" ).

  • In the breadcrumb navigation, fixed the potential extra comma after the last element (controlled by{{- if ge (len $bc_list) 1 }},{{end }} ).

  • Standardized date formats: datePublished and dateModified are output in ISO 8601 format (e.g., 2006-01-02T15:04:05Z07:00 ) using Format to avoid date format errors.

  • Cleaned up redundant commas: Removed extra commas after fields like author (JSON does not allow trailing commas after the last element).

  • Truncated long text: Truncated articleBody (using truncate 5000 ) to avoid potential issues caused by excessively long content.

Steps to reproduce

1.Create a test page at my-hugo-paper/content/aaa/bbb.html

 --- title: "bbb" --- 
  1. run hugo
hugo --gc --noBuildLock Start building sites … hugo v0.141.0+extended android/arm64 BuildDate=unknown Total in 3471 ms Error: error building site: render: failed to render pages: failed to process "/aaa/bbb/index.html": "/data/data/com.termux/files/usr/tmp/hugo-transform-error231535155:95:40": expected comma character or an array or object ending on line 95 and column 40 12:{^ 

Hugo Version

Hugo < 0.146.0 (Incompatible - Not recommended to build PaperMod on lower versions)

PaperMod Version

72615b6 refs/remotes/origin/master

What kind of devices are you seeing the problem on?

No response

What browsers are you seeing the problem on?

No response

Browser Version

No response

Relevant log output

hugo --gc --noBuildLock Start building sites … hugo v0.141.0+extended android/arm64 BuildDate=unknown Total in 3471 ms Error: error building site: render: failed to render pages: failed to process "/aaa/bbb/index.html": "/data/data/com.termux/files/usr/tmp/hugo-transform-error231535155:95:40": expected comma character or an array or object ending on line 95 and column 40 12:{^

Repository/Source Code link where this issue can be reproduced

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions