Create catalog-based archetypes templates
It is possible to use full catalogs as archetypes templates in Hugo.
Preface
If you don’t want to clutter your articles with images in the same directory as your articles, you can create an images folder and put the images in it. But it’s too much of a hassle to create it manually every time, which can be simplified by setting up a directory-based template with archetypes.
This article is based on the Stack theme.
Creating a directory structure
Create a default_structure folder in the archetypes directory with an arbitrary filename and the following directory structure:
|
|
The index.md
in the default_structure
directory can also have template content added to it, for example:
|
|
New article
Once the template is created, it’s time to create a new article to see how it looks, using the command:
|
|
This command will create a new folder /content/posts/demo
and it will contain the same folder structure as in the default_structure prototype folder.
Note: The argument after --kind
needs to be the same as the folder name of the directory structure created earlier, i.e. the default_structure
directory name.
At this point the article is created and you can see that the structure of the demo
directory is as expected.
|
|
At the same time, the template content of demo/index.md
was successfully added
|
|
Summary
The archetypes prototype template allows you to create a directory structure that meets your needs.
Of course, if you don’t like the idea of having the images folder in the same directory as the article, you can also consider creating the images folder in the static directory, so that it will show up when referenced in the md file (e.g. ! [](images/one.jpg)
).