gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.64k stars 7.45k forks source link

Setting publishDate = [":filename"] will cause hugo new content to fail with future dates #11908

Open justuswilhelm opened 7 months ago

justuswilhelm commented 7 months ago

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154 darwin/arm64 BuildDate=2024-01-05T12:21:15Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Setting the date to today is fine, setting the date to something in the future breaks.

Here's how to reproduce (terminal session in fish shell):

~/Downloads$tar xvfz hugo_0.121.2_darwin-universal.tar.gz
x hugo
x README.md
x LICENSE
~/Downloads$./hugo new site test
Congratulations! Your new Hugo site was created in /Users/justusperlwitz/Downloads/test.
[...]
~/Downloads$cd test
~/D/test$../hugo new content content/posts/2024-01-26-(random).md
Content "/Users/justusperlwitz/Downloads/test/content/posts/2024-01-26-10004.md" created
~/D/test$echo '[frontmatter]
         publishDate = [":filename"]
         ' > hugo.toml
~/D/test$../hugo new content content/posts/2024-01-26-(random).md
panic: [BUG] no Page found for "/Users/justusperlwitz/Downloads/test/content/posts/2024-01-26-7265.md"

goroutine 1 [running]:
github.com/gohugoio/hugo/create.(*contentBuilder).applyArcheType(0x140000f95c0, {0x140000545a0, 0x45}, {0x140009adad0, 0xa})
        /root/project/hugo/create/content.go:278 +0x238
github.com/gohugoio/hugo/create.(*contentBuilder).buildFile(0x140000f95c0)
        /root/project/hugo/create/content.go:246 +0x16c
github.com/gohugoio/hugo/create.NewContent.func1()
        /root/project/hugo/create/content.go:105 +0x24c
github.com/gohugoio/hugo/create.NewContent(0x14000993cc0, {0x0, 0x0}, {0x16b2e6984, 0x20}, 0x0)
        /root/project/hugo/create/content.go:109 +0x498
github.com/gohugoio/hugo/commands.newNewCommand.func1({0x0?, 0x0?}, 0x0?, 0x0?, {0x14000795c50, 0x0?, 0x0?})
        /root/project/hugo/commands/new.go:60 +0x160
github.com/gohugoio/hugo/commands.(*simpleCommand).Run(0x0?, {0x108232a18?, 0x109510780?}, 0x0?, {0x14000795c50?, 0x0?, 0x0?})
        /root/project/hugo/commands/commandeer.go:588 +0x48
github.com/bep/simplecobra.(*Commandeer).compile.func1(0x140007c4500?, {0x14000795c50?, 0x4?, 0x1065db95c?})
        /root/project/gomodcache/github.com/bep/simplecobra@v0.4.0/simplecobra.go:113 +0x54
github.com/spf13/cobra.(*Command).execute(0x140008cf800, {0x14000795c10, 0x1, 0x1})
        /root/project/gomodcache/github.com/spf13/cobra@v1.8.0/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x14000023800)
        /root/project/gomodcache/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        /root/project/gomodcache/github.com/spf13/cobra@v1.8.0/command.go:1048
github.com/bep/simplecobra.(*Exec).Execute(0x140005ced18, {0x108232a18?, 0x109510780?}, {0x1400004c0d0?, 0x1400008a648?, 0x104b202ec?})
        /root/project/gomodcache/github.com/bep/simplecobra@v0.4.0/simplecobra.go:155 +0xb4
github.com/gohugoio/hugo/commands.Execute({0x1400004c0d0, 0x3, 0x3})
        /root/project/hugo/commands/commandeer.go:65 +0x284
main.main()
        /root/project/hugo/main.go:25 +0x70
~/D/test$../hugo version
hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154 darwin/arm64 BuildDate=2024-01-05T12:21:15Z VendorInfo=gohugoio
justuswilhelm commented 7 months ago

Here's a quick workaround:

hugo new content --clock 2030-12-31T15:00:00Z content/posts/2024-01-30-(random).md

This will take care of the issue until 2030 👍 adjust for 2040, 2050 and so on if you live further in the future (hi!!)