I think I need to use "directory-based archetypes" but don't understand the sparce docs

Wondering what I’m misunderstanding here, OR how to accomplish getting the frontmatter to:

I created an archetype called machine.md with a lot of extra front matter and thought that it would apply to any hugo new machine/machine-name/index.html that I created – but all I get is the default.md archetype in those index.html files.

Thanks for any help!

EDIT: Would I be correct in assuming that if I put that “machine.md” archetype in archetype/machine/default.md that it would then work for content/machine/machine-name/index.md ?
NOPE that does not work.

Found a discussion on a feature added to Hugo 0.49
called Directory-Based Archetypes that sounds like what I need to grok. Is it referring to this? If so, I still don’t understand them:

Have a look at the Hugo site’s archetypes folder (plural):

~/d/g/g/hugoDocs ❯❯❯ tree archetypes                                                        master
├── functions.md
├── news
│   └── index.md
└── showcase
    ├── bio.md
    ├── featured.png
    └── index.md

Look at the showcase directory, witch matches your expectation.

Appreciate the response, but I found the answer on page 149 of the “Hugo in Action” book.
I will outline the steps here, for anyone finding thread this via search.

First, create a subfolder & file:
archetypes/machine/index.md (I believe that this must be named index.md)
Fill out the index.md with all of the front matter and page matter that you want generated for each “machine” page you will be creating.

Now, to create a page bundle (folder) named “machine-name1” (resulting in a file: content/machine/machine-name/index.md ) you enter this command:

hugo new machine/machine-name1 --kind machine

NOTE that there is NO .md in the command above. The magic of calling the specified archetype file is accomplished with the --kind machine flag at the end of the hugo new command.

The page bundle folder of /machine-name1/ and associated /machine-name1/index.md are created with the front matter you specified in archetypes/machine/index.md

Now I can store the images associated with machine-name1 in that folder for Hugo processing, etc.

Note that in the static files generated, this will result in the following static site structure:

PS… I believe Examples, like this would be very helpful in the documentation pages. I believe that my example could go under the Directory-Based Archetypes section of: Archetypes | Hugo

See the button “IMPROVE THIS PAGE” at the end of of all doc pages.

1 Like

I don’t have a lot of archetypes. Therefore, it is easier to do hugo new -k machine section/nested-section/file-name.md with -k being kind and machine.md being the file in archetypes folder. I just swap out the archetype name depending on the structure I need. I also stumbled upon the same problem with archetype based folders and gave up on using them.

1 Like

Thank you for sharing that! It seems that Hugo usually gives us more than One Way to do things, so it is good to learn alternative methods.

Indeed! I have come to like its versatility so far compared to other SSGs.

I don’t understand this line of your response.
Googling for “tree archetypes” brings up nothing and searching for “tree archetypes” shows no uses of that phrase, but does link to the archetypes page, which I already referenced.

I believe now that I have my example working, I can go back and make sense out of the “Directory-Based Archetypes”. However it does not use the term “page bundle” anywhere. It does use “post-bundle” which may mean the same thing, but not sure.

One annoyance with Hugo is that it uses words in it’s terminology that may mean something specific or may not when used in a sentence: type, kind, page (for example). As I like to say, “words mean things” and if a word can be taken in more than one way it introduces the likelihood for confusion (at least until one learns to recognize the context in which it is used). Programming projects might do well to include a non-programmer linguist to assist in the words used to describe things like this. :wink:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.