Can not generate a folder from archetypes when using Hugo Modules

When I was developing a Hugo theme Hugo Eureka, I used hugo new -k homepage homepage for users to create a folder homepage under content with a basic file.

And I found that hugo new -k homepage homepage only works when I import theme by using git submodules. But this can not work when imported by Hugo Modules though the output shows:

<my-path>\content\homepage created

Maybe it is a bug right now? I tested it with Hugo 0.82.0

hugo new does not create a page bundle. You have to manually say hugo new homepage/ to create a page bundle. It would be nice to somehow set a parameter in the archetype that tells Hugo to always create a page bundle, but that is not available (yet?).

Thanks! But according to Hugo’s Docs, I think this is possible. And this can also be done when importing theme using git submodules or directly. This does not work only in Hugo Modules as far as what I tested

I totally forgot about that. In that case maybe the archetype is not found. I would suspect mounting to be the issue. Try mounting the archetypes/homepage module directory directly to archetype/homepage. I don’t see a config.toml in your theme. So maybe Hugo does not treat it as a module yet.

I use config folder to organize config params better and the config folder behaves as the config.toml :wink:

I think I am not understanding or misunderstanding completely. The repo you linked: Is it a Hugo module? If so, I don’t think you can use the subfolder configuration. It is also not marked as a module. For that it needs a go.mod and (optional) a go.sum. So maybe the whole terminology of a module is where your expectations crash with the realities?

is not a hugo module. For that it needs to be initiated.

Yes, that is a module. And when I tested this, I inited Hugo Modules. Everything works well except this.

Acutally I also build my own site uses Hugo Modules, it works well also. So I don’t think it is because of the misuse of Hugo Module. I think Hugo already treated as a module.

Adding wangchucheng/hugo-eureka as module and theme to my repo leads to:

ERROR 2021/04/04 11:44:35 Module "hugo-eureka" not found; either add it as a Hugo Module or store it in "/home/.../themes".: module does not exist

That repo is not a Hugo Module. As I wrote before, it needs a go.mod to be a module. It has none.

Maybe someone else has an idea what’s going on here.

I do not know how you configure it. But at least I am sure if you set theme = "" it will work well.

It will. But it won’t be a module. It will be a theme. Either that or THAT is the issue, somewhere it is thought to be a “module”. It’s definitely not a Go module. You create one by running hugo mod init in the theme, then adding the go.mod to the theme. Then adding the theme via modules.toml in your config directory, then adding a config.toml to your theme defining mounts. Only THEN it’s a module (in sense of Go modules) and only then archetypes get folded or mounted into the local archetypes folder. If you use it as a theme, then Hugo ignores the archetypes folder in your theme and assumes it was copied over with sampleSite.

I guess that differentiation of adding it via theme="github path" or [[module]] is the reason for the behaviour. As far as I understand your way of adding it is not an “official” go module way and Hugo probably doesn’t even think about checking for anything to merge.

Let’s wait for some of the developers to have a look at this.