I’m looking to find the parameter to get the parent’s folder name.
Example: docs/folder/subpage.md is generated as docs/folder/subpage no issue there. But it’s not nested in the toc. For that to work I need to figure out how to get the /folder/ part from the subpage.md. ChatGPT suggested a complex string splitter setup after I couldn’t find something suitable in the docs. Which is something I’d rather avoid if there’s a direct solution.
It goes here btw:
menu:
docs:
parent: "foldername"
identifier:
It’d be great if the pieces were properly nested in the toc without manual intervention. I just couldn’t figure out how.
A table of contents is a list of heading elements on a given page.
A menu is a list of links to pages, generated by (a) Hugo’s built-in menu system, or (b) recursively walking the directory structure (often referred to as a section menu).
If you want to use Hugo’s built-in menu system, the parent property of the menu entry needs to point to the identifer or name property of its parent menu entry.
I’m looking for something that gets me the parent value (in the example Products) upon creation of the page via hugo new folder/filename.md as at that point Hugo knows both the parent and the child.
So, if I understand you correctly, you do not want to create a menu entry in site configuration for each page that you add to content. Instead, you want your navigation to be updated whenever you create a new page.
Yup that would be an apt assessment. I create a new sub-page and the sub-page has the correct value put in the parent: automatically based on its parent section/folder.
git clone --single-branch -b hugo-forum-topic-42835 https://github.com/jmooring/hugo-testing hugo-forum-topic-42835
cd hugo-forum-topic-42835
hugo server
Thanks for that. The archetypes there are basic, there’s nothing there to indicate any sort of nesting. I can probably do it with a Bash script though since I batch generate the documentation section, I have the top category of each in the script as a variable anyway. Would’ve been nice to have it native though.
Yes. Look in the archetypes folder. There is no parent information there. Each post is created in a void without any relation to where it belongs.
The in-page list has nothing to do with what I’m looking for. What I was after is a way to get the foldername part into the parent frontmatter when hugo new foldername/filename.md as I have many filename.md in fewer foldername. Hence the archetypes/docs.md should have something in the parent: that tells the page where it belongs to in terms of nesting.
Structural result example:
foldername
_index.md
filename1.md
filename2.md
filename3.md
filename4.md
filename5.md
By default, Hugo doesn’t know the filename parts belong to foldername therefore the need for setting the parent: in frontmatter. I need to do this a good couple of times, so automating it is fairly necessary.