Skip to content

Decouple slug inference from date resolution when using :filename in front matter config #14971

Description

@maxkapur

Hugo bug report

Summary

When a post has a date given in both its filename and frontmatter, hugo fails to parse the slug from the filename.

Steps to reproduce

I created a repo here that reproduces the issue: https://github.com/maxkapur/hugo-date-slug-repro

To summarize, consider a hugo.toml configured to extract dates from filename, but allow explicit override in frontmatter:

[frontmatter]
date = ["date", ":filename"]

Create content/posts/2026-05-24-bar.md with empty frontmatter. As expected, the .Date is set to 2025-05-24T00:00:00 and .Slug is set to just bar.

Now add a second post content/posts/2026-05-24-foo.md, but this time also set the date in frontmatter to 2025-05-24T11:59:59 (providing an explicit time, e.g. to force a certain sort order).

In this case, the .Date field is correctly populated with the 11:59:59 version, but .Slug is nil.

Here's the CSV output of hugo list all which may clarify what's going on:

https://github.com/maxkapur/hugo-date-slug-repro/blob/main/hugo_list_all.csv

Why I believe this is a bug

From the source code, it's obvious why this happens—if given an explicit date, then dateAndSlugFromBaseFilename() never gets called and thus no slug is ever inferred.

In my opinion, this is a bug, or at least surprising behavior. The frontmatter.date = [":filename"] date config silently triggers slug inference behavior that users (or at least users like me 😅) could come to rely on. In particular, this behavior generates surprising permalinks—in the example above:

And a markdown link like [whatever](/posts/2026-05-24-bar/) (which makes perfect sense looking at the file tree) from another post will 404.

This date/slug interaction is not discussed in the documentation on frontmatter dates, slugs, or URLs. It just happens.

Possible fixes

  • New config option frontmatter.slug that allows users to control interaction with frontmatter.date (maximally preserves backwards compat)
  • If a filename begins with a date, strip it before inferring the slug if frontmatter.date = [":filename"] is set (even if frontmatter also has an explicit date)

What version of Hugo are you using (hugo version)?

I reproduced with the latest snap version:

$ hugo version
hugo v0.162.0-076dfe13d0f789e3d9586b192f8f7f3329c26990+extended linux/amd64 BuildDate=2026-05-26T13:53:44Z VendorInfo=snap:0.162.0

As well as the latest Docker hugomods/hugo:nightly image:

$ docker run --rm -it -v (pwd):/repro hugomods/hugo:nightly version
hugo v0.163.0-DEV-28d882ab704e5060687a61210ae20b0027595705+extended+withdeploy linux/amd64 BuildDate=2026-05-29T09:28:27Z VendorInfo=hugomods

Does this issue reproduce with the latest release?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions