According to the documentation it should be possible to override the URL with slug or url in frontmatter but it doesn’t seem to work for me. I would like post permalinks like 2017-09 by default, but want to be able to override this on specific posts. Instead I get two posts with the same permalink: 2017-09.
I have observed this happening on at least Hugo v0.27.1 and v0.29. This simple setup can reproduce it:
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "hyde"
post = "/:year-:month/"
title: "Test Post 1"
Testing a post.
title: "Test Post 2"
Testing another post.
Thanks, @Leo_Merkel. Is the frontmatter snippet above a top-level page or a post? I’m guessing the difference here is you’re creating top-level pages, not posts. In my example all my content are posts, and no permalink setting makes any difference.
Eye-balling it, it looks like you are specifically telling Hugo to skip the slug parameter. A “slug” is the portion of the URL that refers to a specific piece of content. The defaults make it so it works as expected for most folks, playing with title and working in common permalink patterns.
But yours says to just make a year and a month. If you have :title or :slug somewhere in the permalink, it should generate as expected.
Hmm, that’s not how I understand the documentation regarding URL management. We should be able to override the slug in frontmatter, regardless of whether the site’s configuration uses :slug in the [permalinks] setting.
I may misunderstand your issue. Do you have a use for the slug, aside from the permalink, and it isn’t working properly?
I think you may be thinking of url after all. The slug changes how the :slug shows up in a permalink. It overrides the :title. url in front matter, however, changes the complete URL, relative to the baseurl.
Have you tried adding something like this to a post’s front matter?
url = "test/out/url"
It should make whichever post render at example.com/test/out/url/.
You’re right, @maiki. I was misunderstanding the use of slug in frontmatter and using url does indeed achieve what I want. I was just coming here to say that the Content Organization page of the docs explains this a little better—although the ASCII flowcharts aren’t very readable if you don’t realize the code blocks expand on hover.