My content structure is as follows: /content/posts/folder-name
. I have six folders inside /posts/
. I would like to create two archetype templates that populate the same frontmatter for the first 5 folders, and a different one for the 6th folder. Is there a way to do that? I tried using the command hugo new posts/6th-folder-name
but it creates a folder instead of a file. I have the main template inside archetypes/posts
and the other inside archetypes/posts/6th-folder-name
. (The current one creates the post inside the posts folder and I copy-paste it to the folder it belongs. But if there is a way to target each individual folder, I would appreciate too).
There is a concept called βsectionsβ in Hugo. Sections are basically the first level folders. You could create two sections and use in that one section with one subfolder with frontmatter slug
and/or url
parameters so you can define the resulting URL.
It appears your want posts/
being the first part of any url in those 6 folders. You would put the five identical subfolders into the content/posts/foldername
folders and for the sixth section you oput them into content/specialposts/
and use the following frontmatter:
url: /posts/special-section/linkname
and then you can have an archetype for posts
and one for specialposts
.
Hope that makes sense somehow
It does, but that would disrupt my URLs and taxonomy. I was thinking there was a simpler way to achieve this without disrupting the current order. Alternatively, I can retain the same file in archetypes for all folders, but how would I use the hugo new
command so that each post appears in the folder I want it to appear in? (Since using hugo new /posts/folder-name
generates the folder name instead of the post?)
slug
and url
regulate your URLs, so it actually does NOT disrupt whatever you have going on there. Archetypes are possible per section only.
Doing this makes my taxonomy page for this folder disappear. It seems the category works only when the posts are inside the posts folder.
archetypes/
βββ default.md
βββ foo.md
For the first 5 directories:
hugo new posts/dir/xxx.md
For the sixth (different) directory:
hugo new -k foo posts/dir-6/xxx.md
@jmooring that does the trick. Thanks
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.