I have a file under ‘cars’ in a subfolder ‘mercedes’, called ‘300-sl.md’. The path to the file is ‘/content/cars/mercedes/300-sl.md’. I would like the permalink to be: ‘/autos/mercedes/300-sl/’.
I want the following configuration:
permalinks:
cars: autos/:filename
but this gives me the permalink ‘/autos/300-sl/’. Is it possible to have the dir (‘mercedes’) in the permalink by setting a custom permalink structure in the config? I would expect there to be a ‘:dir’ or ‘:filepath’ variable. Does this exist?
Your solution works, but it means I have to add the url to each file. I would rather automatically read the path the file is already on. Is that also possible?
However, I am after a solution that works for more than just one level, as I have created an auto-collapsing menu that works for infinite levels of content (within a section).
If there is no way to reflect the directory structure in the permalink (and mimic the default behaviour), adding a variable like ‘:dir’ or ‘:filepath’ might be a nice feature request? What do you think?
the content’s sections hierarchy. New in v0.83.0 Since Hugo 0.83 you can use a selection of the sections using slice syntax : :sections[1:] includes all but the first, :sections[:last] includes all but the last, :sections[last] includes only the last, :sections[1:2] includes section 2 and 3. Note that this slice access will not throw any out-of-bounds errors, so you don’t have to be exact.
there is no way to reflect the directory structure in the permalink
In my opinion using subsections IS a workaround for this problem, as a subsection is not the same as a directory structure (from what I have understood). I have understood it to be like this:
a folder with an _index.md file is a section or subsection
a folder with a index.md file is a page bundle
a folder without those files is a directory structure (unless it is in the root of the content dir)
I was looking for a way to reflect the third option in the permalink, not the first or the second.
Did you read the documentation?
Words matter.
Please know that I am not trying to offend or attack you. I think this functionality is genuinly flawed in Hugo. I want to ask you (or the community) if this is indeed a missing feature/strange behaviour (the default behaviour being different from the one you can configure). I love to hear your opinion on this, because I know you know everything about Hugo. Having people think along is why I asked the question.