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

Panic when creating new content _index.md then index.md #12194

Open irkode opened 6 months ago

irkode commented 6 months ago

edit: added generated files


Hugo crashed when I accidently executed a rather strange sequence of new content commands:

I consider that as an edge case - but message itself states it as bug

I accidently [^1] tried to create *index.md files in the following order (one without underscore)

  1. _index.md
  2. index.md

Hugo crashed with: panic: [BUG] no Page found for "C:\_my\test\content\index.md"

Steps to reproduce: on Windows 10

PS C:_my> hugo version

hugo v0.123.7-312735366b20d64bd61bff8627f593749f86c964+extended windows/amd64 BuildDate=2024-03-01T16:16:06Z VendorInfo=gohugoio

PS C:_my> hugo new site test

Congratulations! Your new Hugo site was created in C:\_my\test.
 ...
See documentation at https://gohugo.io/.

PS C:_my> pushd test PS C:_my\test> hugo new content _index.md

Content "C:\\_my\\test\\content\\_index.md" created

PS C:_my\test> hugo new content index.md


panic: [BUG] no Page found for "C:\\_my\\test\\content\\index.md"

goroutine 1 [running]:
github.com/gohugoio/hugo/create.(*contentBuilder).applyArcheType(0xc000a30840, {0xc000a58150, 0x1c}, {0x4a0bde0, 0xc0003097c0})
       /root/project/hugo/create/content.go:275 +0x354
github.com/gohugoio/hugo/create.(*contentBuilder).buildFile(0xc000a30840)
       /root/project/hugo/create/content.go:244 +0x1ad
github.com/gohugoio/hugo/create.NewContent.func1()
       /root/project/hugo/create/content.go:105 +0x28c
github.com/gohugoio/hugo/create.NewContent(0xc0007d8c80, {0x0, 0x0}, {0xc00000a100, 0x8}, 0x0)
       /root/project/hugo/create/content.go:108 +0x5c6
github.com/gohugoio/hugo/commands.newNewCommand.func1({0x0?, 0x0?}, 0x0?, 0xc000612dc0, {0xc00049bd50, 0x0?, 0x0?})
       /root/project/hugo/commands/new.go:60 +0x15f
github.com/gohugoio/hugo/commands.(*simpleCommand).Run(0x0?, {0x4a010d8?, 0x5d46a00?}, 0x0?, {0xc00049bd50?, 0xc0008d7a28?, 0x0?})
       /root/project/hugo/commands/commandeer.go:596 +0x3c
github.com/bep/simplecobra.(*Commandeer).compile.func1(0xc0009acb00?, {0xc00049bd50?, 0x4?, 0x320c1bf?})
       /root/project/gomodcache/github.com/bep/simplecobra@v0.4.0/simplecobra.go:113 +0x4c
github.com/spf13/cobra.(*Command).execute(0xc0006dc608, {0xc00049bd10, 0x1, 0x1})
       /root/project/gomodcache/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc0009b4908)
       /root/project/gomodcache/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
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(0xc0004b6820, {0x4a010d8?, 0x5d46a00?}, {0xc0000ac090?, 0x101?, 0xc000099e88?})
       /root/project/gomodcache/github.com/bep/simplecobra@v0.4.0/simplecobra.go:155 +0xd4
github.com/gohugoio/hugo/commands.Execute({0xc0000ac090, 0x3, 0x3})
       /root/project/hugo/commands/commandeer.go:66 +0x2f9
main.main()
       /root/project/hugo/main.go:25 +0x56
jmooring commented 6 months ago

Summary...

hugo new site foo
cd foo
hugo new _index.md
hugo new index.md

This was not a problem with v0.122.0. Fails with v0.123.0 and later.

ca5ua1 commented 4 months ago

I have something that might be related to this issue on hugo v0.125.4+extended linux/amd64 BuildDate=unknown VendorInfo=nixpkgs.

In my issue - when there is index.md - hugo doesn't generate content for any subfolders. E.g. if there is content/myFolder/post.md it will not generate in public

jmooring commented 4 months ago

@ca5ua1 If you have a directory with descendant pages it is a branch bundle, and you must use an _index.md file instead of an index.md file. See documentation.

ca5ua1 commented 4 months ago

@jmooring ah, I see. That's confusing. Thanks for pointing that out