Skip to content

Enhancement: Date format in preview path #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
svrooij opened this issue Jun 27, 2023 · 7 comments
Closed

Enhancement: Date format in preview path #593

svrooij opened this issue Jun 27, 2023 · 7 comments

Comments

@svrooij
Copy link

svrooij commented Jun 27, 2023

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.

@svrooij svrooij added the enhancement New feature or request label Jun 27, 2023
@estruyf
Copy link
Owner

estruyf commented Jun 28, 2023

@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
Copy link
Author

svrooij commented Jun 28, 2023

@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
Copy link
Owner

estruyf commented Jun 28, 2023

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'}}

@svrooij
Copy link
Author

svrooij commented Jun 28, 2023

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

@estruyf
Copy link
Owner

estruyf commented Jun 29, 2023

@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
Copy link
Author

svrooij commented Jul 1, 2023

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

@estruyf
Copy link
Owner

estruyf commented Jul 2, 2023

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

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

No branches or pull requests

2 participants