Enhancement: Date format in preview path #465

Closed
opened 2026-10-05 02:48:40 +02:00 by adam · 7 comments
Owner

Is your feature request related to a problem? Please describe.
I migrated from Jekyll to Hugo and wanted to keep the old url format /{year}/{month}/{day}/{slug} this is perfectly doable in Hugo. But now I cannot get the preview path to load, since it would require having the day.

Describe the solution you'd like
I would like support for either {{fm.day}} / {{fm.month}} / {{fm.year}} in the preview path or have some sort of formatting option on the provided date value like {{fm.date.format('yy')}} or {{fm.date:yy}} depending on language features.

Describe alternatives you've considered
I've considered using the {{pathToken.x}} placeholders, but that does not work because I don't have the day folder, since my posts are stored in content/posts/{year}/{month}/{slug}.md format.

**Is your feature request related to a problem? Please describe.** I migrated from Jekyll to Hugo and wanted to keep the old url format `/{year}/{month}/{day}/{slug}` this is perfectly doable in Hugo. But now I cannot get the preview path to load, since it would require having the day. **Describe the solution you'd like** I would like support for either `{{fm.day}}` / `{{fm.month}}` / `{{fm.year}}` in the preview path or have some sort of formatting option on the provided date value like `{{fm.date.format('yy')}}` or `{{fm.date:yy}}` depending on language features. **Describe alternatives you've considered** I've considered using the `{{pathToken.x}}` placeholders, but that does not work because I don't have the day folder, since my posts are stored in `content/posts/{year}/{month}/{slug}.md` format. <!-- github-sync-id:1776488481 -->
adam closed this issue 2026-10-05 02:48:40 +02:00
Author
Owner

@svrooij, do you have a date field in your front matter section?

The {{fm.<field-name>}} placeholder is what can be used here, only need to find the best approach to apply the date formatting.

@svrooij, do you have a date field in your front matter section? The `{{fm.<field-name>}}` placeholder is what can be used here, only need to find the best approach to apply the date formatting. <!-- github-comment-id:1611136319 -->
Author
Owner

@estruyf yes I do have the date field in the front matter. I think it's even a default field if you setup front matter CMS.

I was not sure if formatting would be an option, or if it would be easier to make 3 addition special placeholders day / month / year that are filled if the frontmatter has a date property.

@estruyf yes I do have the date field in the front matter. I think it's even a default field if you setup front matter CMS. I was not sure if formatting would be an option, or if it would be easier to make 3 addition special placeholders `day / month / year` that are filled if the frontmatter has a `date` property. <!-- github-comment-id:1611143592 -->
Author
Owner

Indeed, OOTB Front Matter has a date field, but you can adapt it by referring to your older articles.

This {{fm.date:yy}} is my preferred format right now, but more thinking towards something like this: {{fm.date | dateFormat 'yyyy'}}

Indeed, OOTB Front Matter has a date field, but you can adapt it by referring to your older articles. This `{{fm.date:yy}}` is my preferred format right now, but more thinking towards something like this: `{{fm.date | dateFormat 'yyyy'}}` <!-- github-comment-id:1611302037 -->
Author
Owner

Having the | dateFormat 'yy' would allow using it on other fields as well. That sound like a perfect plan.

Having the `| dateFormat 'yy'` would allow using it on other fields as well. That sound like a perfect plan. <!-- github-comment-id:1611334718 -->
Author
Owner

@svrooij I have added it. The format changed a bit. I've asked ChatGPT what would be the ideal field definition. It was pretty close to what we already came up with.

The format for this will be: {{fm.<field name>|format:<your format>}}. Example: {{fm.pubDate|format:dd/MM/yy}}.

Xnapper-2023-06-29-11 41 06

PS: Feel free to try it out in the 8.5.5410787 beta.

@svrooij I have added it. The format changed a bit. I've asked ChatGPT what would be the ideal field definition. It was pretty close to what we already came up with. The format for this will be: `{{fm.<field name>|format:<your format>}}`. Example: `{{fm.pubDate|format:dd/MM/yy}}`. ![Xnapper-2023-06-29-11 41 06](https://github.com/estruyf/vscode-front-matter/assets/2900833/7281590c-f120-441d-b6df-e78f23c444dc) PS: Feel free to try it out in the `8.5.5410787` beta. <!-- github-comment-id:1612729041 -->
Author
Owner

It works perfectly, shall I close the issue? Or does that happen automatically if you release the new version

It works perfectly, shall I close the issue? Or does that happen automatically if you release the new version <!-- github-comment-id:1615896358 -->
Author
Owner

@svrooij I will close it when I document and release it in the main version.

@svrooij I will close it when I document and release it in the main version. <!-- github-comment-id:1616445781 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#465