adityatelange / hugo-PaperMod

A fast, clean, responsive Hugo theme.
https://adityatelange.github.io/hugo-PaperMod/
MIT License
9.53k stars 2.58k forks source link

[BUG] Minified build errors with: expected comma character or an array or object ending on line... #1441

Closed pierreprinetti closed 6 months ago

pierreprinetti commented 6 months ago

Describe the bug I am getting this error when running hugo --minify:

Error: error building site: render: failed to render pages: failed to process "/posts/2024-02-27_reproducer/index.html": "/tmp/hugo-transform-error250503843:83:40": expected comma character or an array or object ending on line 83 and column 40
   12:     {
           ^

and indeed the tempfile has a scheme.org JSON array with two elements and no comma between them:

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position":  1 ,
      "name": "Posts",
      "item": "/posts/"
    }
    {
      "@type": "ListItem",
      "position":  1 ,
      "name": "This is a reproducer for a PaperMod bug",
      "item": "/posts/2024-02-27_reproducer/"
    }
  ]
}
</script>

I am not sure what triggers the error. Anyway, I could build a reproducer (see below).

Steps to reproduce the behavior:

  1. Create a minimal post
  2. Generate a minified build
  3. enjoy

Expected behavior: I expected the site to build, just like it does when no --minify is passed.

Repo/Source where this issue can be reproduced:

cd $(mktemp -d)
git clone --recurse-submodules git@github.com:pierreprinetti/papermod-bug-reproducer.git .
hugo --minify
pierreprinetti commented 6 months ago

Something interesting happens when I set a base URL.

$ HUGO_BASEURL=https://example.com/ hugo --minify
Start building sites …
hugo v0.123.6+extended linux/amd64 BuildDate=unknown

                   | EN
-------------------+-----
  Pages            | 11
  Paginator pages  |  0
  Non-page files   |  0
  Static files     |  0
  Processed images |  0
  Aliases          |  2
  Cleaned          |  0

Total in 41 ms

First of all, it succeeds. And the breadcrumb JSON items now have the correct "position" numbers:

{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "name": "Posts",
      "item": "https://example.com/posts/"
    },
    {
      "@type": "ListItem",
      "position": 2,
      "name": "This is a reproducer for a PaperMod bug",
      "item": "https://example.com/posts/2024-02-27_reproducer/"
    }
  ]
}

(it was minified in the file; I have pretty-printed it here for readability)

adityatelange commented 6 months ago

Yes you are supposed to use a baseURL and not build with a / in baseURL, not recommended

pierreprinetti commented 6 months ago

Yes you are supposed to use a baseURL and not build with a / in baseURL, not recommended

Do I understand correctly that not setting a baseURL is not a valid use-case with PaperMod?

adityatelange commented 6 months ago

Yes you are supposed to use a baseURL and not build with a / in baseURL, not recommended

Do I understand correctly that not setting a baseURL is not a valid use-case with PaperMod?

It's not only about use cases but what implementation works with the rest of the functions without breaking anything.