Excluding the date from the :filename

Hello everyone,

I’m new to Hugo. I have a Jekyll website and articles that have the following format:

/articles/2020-01-01-hello.md

That creates the URL /hello/.

Is this possible in Hugo?

The only solution I’ve seen is to either specify the URL or slug as front matter or to use the title. Both don’t feel like very good solutions.

Thanks in advance.

Dave.

I think using title is fairly standard, like, everywhere (after modifying it, ie lowercase and hyphenating).

You called them above, those are the ways I’m aware of.

It occurs to me that when we build the feature to generate content pages from data sources (rather than content text files) we’ll need a way to standardize the titles and URLs, so something (a new config or a new method of building content) may be baking that addresses your concern. :slight_smile:

Thanks for your help, Maiki.

I think using title is fairly standard, like, everywhere (after modifying it, ie lowercase and hyphenating).

I’m not sure about that. I agree most systems choose the title as the default but I think most platforms store that information elsewhere. WordPress sets it in a permalink field and Jekyll uses the file name.

Using the title sounds dangerous and prone unknowingly breaking pages—especially for editors who don’t fully understand the concepts of the CMS.

Also, I’d be surprised if the norm is for the URL to match the title on most websites with a large number of articles. You often see abbreviated versions of the titles in the URL, here’s an example: https://www.smashingmagazine.com/2020/04/particle-trail-animation-javascript/

Using the title makes the filename redundant which feels odd and confusing. I imagine most peoples mental model of how the contents folder works is to create folders and files and for them to directly correspond in the URL structure.

You called them above, those are the ways I’m aware of.

I think I’ve found another way. I’ve removed the date from the file name and moved it into front matter. This means I can now use the :filename as the permalink. This actually feels better than Jekyll because although it doesn’t order the files chronologically in the folder, it is an accurate representation of the URL structure for the website.

It occurs to me that when we build the feature to generate content pages from data sources (rather than content text files) we’ll need a way to standardize the titles and URLs, so something (a new config or a new method of building content) may be baking that addresses your concern. :slight_smile:

It would be great to see some more options around this. If for nothing else, to make the transition from Jekyll to Hugo easier for lots of people.

Thanks again for your help, Maiki.

The urlize function can make any string suitable for usage as a URL.

Thanks, @onedrawingperday.

I was referring more to if someone changes the title the URL will also change so all the SEO value might be lost—especially without a redirect.