I have some posts with
permalink: /example/ in the frontmatter. I was confused they were causing an error until I read this and had to bulk change from permalink to slug both in the front matter and the config file. What is the logic behind not supporting
I have some posts with
A permalink is a full identifier. The slug is just the last part. You could regulate your content by putting stuff into arbitrary folders and build your resulting URLs via:
In the latter case the containing folder might have an
_index.md with a
the-page. The full URL would be
This gives you more power over the resulting URL structure of your website.
For instance useful for putting different sections into the same URL-section, but using different layout files.
But I am referring to frontmatter specifically, not necessarily the folder structure.
me too. frontmatter configures your content.
OOh. I get your point. So you mean
slug bypasses the directory structure?
yes, frontmatter parameters
slug both bypass the directory structure.
I’m not sure if I understood correctly but in any case …
slug setting is only for the last part of a
- A permalink is:
- The slug in the permalink is:
slug frontmatter is optional. In the absence of it, Hugo will use the
title frontmatter as the
slug. (Also, if I remember correctly, the default is if
title is also not present, it will use the filename of the
filename.md file next, to form the
This is good because you can structure your permalinks independent of your folder structure.
For example, in my
[permalinks] section in
config.toml I have:
blog = "/:slug-:year:yearday/" c = "/:sections[1:]/:slug-:year:yearday/"
c above are actual folders, as shown below, is my folder structure:
When Hugo generates the site, the
In both examples, the folder
2020 are not in the resulting permalink. You will also notice in the second example, the
poems folder remains intact but not the
My case was why Hugo sends a 404 error if I have
permalink: /abc-def/ in the posts frontmatter, but doesn’t if I use
url: and I am still confused about this.
You cannot set
permalink in front matter.
Why not? Any reason in the docs?
permalinks is for site configuration.
url is for front matter.
Sorry, I don’t know how to make this any clearer.
The decisions regarding url management (globally and per content file) were made by Hugo’s original creator and other contributors a very long time ago.
We cannot provide you with the reasons why these features were designed in a specific way -as we are not the ones who created the software-.
Also the documentation site is not meant to provide the reasons behind the software’s architecture.
This is an important question since I was moving my second site from Jekyll to Hugo and it has permalinks defined in front matter using
permalink: /example/. So, brushing this away does not answer my question in the first place! Anyways, it is not a big deal, but I wasted time figuring out I needed to use slug or URL instead.
I think I will stick with this explanation. Having hundreds of posts with permalink: /example/ in the front matter throw an error does make me apprehensive of why this is the case, since other I could not find any explanation online.
I do not think that I brushed anything away. Rather I gave you an informed reply.
The doc is crystal clear.
You really have to read the documentation there is no way around it.
Also before opening further topics please do read the:
These forum guidelines were put in place years ago to save time.
Both your time -as you found out the hard way- but also our time.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.