Skip to content

Conversation

fionaRowan
Copy link

@fionaRowan fionaRowan commented Oct 14, 2025

related to issue #6801 , though takes a different approach than that requested in the issue description. this PR tentatively implements solution 1 outlined in this issue comment, though could pivot to another solution if preferred!

Summary

currently, when configuring the slug, the template tags {{year}}, {{month}}, etc are always pulled from the hardcoded "now".

in this PR, if the entry contains an inferred 'date' field, we use that value when generating the slug.

thus, the following slug config would pull the template tags {{year}}, {{month}}, etc from the entry's front matter inferred 'date' field if it exists (or otherwise, "now"):

slug: "{{year}}-{{month}}-{{day}}-{{slug}}" 

notes for evaluating slugFormatter's expected behavior w.r.t. date template tags:

| slug | Template for filenames. {{year}}, {{month}}, and {{day}} pulls from the post's date field or save date. {{slug}} is a URL-safe version of the post's title. Default is simply {{slug}}. |

  • however, this PR makes the slugFormatter's behavior more nuanced than this piece of documented behavior implies

{{year}}: 4-digit year of the file creation date

Test plan

  • wrote a unit test which I verified passes
  • (still working on this) built the library + pointed my own static generator site to that library locally to verify that the slug template variables {{year}}, {{month}}, etc are pulled from the entry's front matter "date" field if it exists

Checklist

Please add a x inside each checkbox:

A picture of a cute animal (not mandatory but encouraged)
signal-2025-06-15-204636_002

@fionaRowan fionaRowan requested a review from a team as a code owner October 14, 2025 21:23
@martinjagodic
Copy link
Member

@fionaRowan this is a very well-written PR!

I like the idea of your second point: allow the user to configure which date to use. For instance, Hugo also uses publishDate, and it would be helpful to have that choice.

But, how should the user pass that field?

option 1:

slug: "{{fields.date.year}}-{{fields.date.month}}-{{fields.date.day}}-{{slug}}"

The original proposal from #6801. It feels too verbose, and .year sounds like a field, not a modifier.

option 2:

slug: "{{fields.date | date("YYYY-MM-DD)}}-{{slug}}"

This matches your option 3, I like it better. If I understand correctly, this is possible if we merge #6690?

In any case, I would first merge what you did here, because it's a well-rounded PR. Just let me know once you complete the testing, and please share your thoughts on how to continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants