-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Add permalink configuration for non-zero padded dates #6488
Conversation
This adds new permalink configuration to allow non-zero padded months (:monthnopad) and days (:daynopad) to be used in URLs. For example, `2018-01-06` can be rendered as `/2018/1/6`. See: https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860
That comment is very old, and I'm not sure how sensible it was. What would probably make more sense was to use the date format built into Go, e.g. Adding the |
Thanks for the quick feedback. I'm in favor of providing a way for users to specify their own date format for permalinks, that feels the best to me. And given that the Go community really does not use strftime much, using the standard library's date formatting seems reasonable. 👍 I'd be happy to work on that. However, I'm not sure how to configure that in the This looks a little weird, but would match the
Or perhaps the config could optionally become a map (not sure how hard that would be to implement) to make the format string unambiguous.
Thoughts? |
I was more thinking in the line of making "numbers" the special case, e.g.
|
Ah yes, that makes sense. I will try that and see how it works out. Do you think it will impact anyone who might be using a literal number in their permalinks? It would only be those that are for Go's special case date, I suppose. |
I didn't think about those ... We could do:
The |
I like that. Giving it a try now. |
In the vein of an ancient TODO about supporting custom date formatting with strftime, this allows `:`-prefixed Go time format strings in permalink segments. This allows users to customize date-based permalinks any way they need to. For example, with a date of 2019-11-09, the permalink `/:06/:1/:2` will render as `/19/11/9`. See: gohugoio@07978e4#diff-0688a3b65c7f5d01aa216f8d9b57fd00R111-R112 https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860 gohugoio#6488
Closed in favor of #6489. |
In the vein of an ancient TODO about supporting custom date formatting with strftime, this allows `:`-prefixed Go time format strings in permalink segments. This allows users to customize date-based permalinks any way they need to. For example, with a date of 2019-11-09, the permalink `/:06/:1/:2` will render as `/19/11/9`. See: 07978e4#diff-0688a3b65c7f5d01aa216f8d9b57fd00R111-R112 https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860 #6488
In the vein of an ancient TODO about supporting custom date formatting with strftime, this allows `:`-prefixed Go time format strings in permalink segments. This allows users to customize date-based permalinks any way they need to. For example, with a date of 2019-11-09, the permalink `/:06/:1/:2` will render as `/19/11/9`. See: gohugoio/hugo@07978e4#diff-0688a3b65c7f5d01aa216f8d9b57fd00R111-R112 https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860 gohugoio/hugo#6488
In the vein of an ancient TODO about supporting custom date formatting with strftime, this allows `:`-prefixed Go time format strings in permalink segments. This allows users to customize date-based permalinks any way they need to. For example, with a date of 2019-11-09, the permalink `/:06/:1/:2` will render as `/19/11/9`. See: gohugoio/hugo@07978e4#diff-0688a3b65c7f5d01aa216f8d9b57fd00R111-R112 https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860 gohugoio/hugo#6488
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This adds new permalink configuration to allow non-zero padded months (
:monthnopad
) and days (:daynopad
) to be used in URLs. For example,2018-01-06
can be rendered as/2018/1/6
.See: https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860
I also looked into implementing this using
strftime
escapes, as hinted at by this TODO comment introduced way back in 07978e4:hugo/resources/page/permalinks.go
Lines 217 to 218 in cafecca
I did find a very nice pure Go strftime library. However, it wasn't clear to me how to fit stftime escapes into the permalink configuration that exists today, so I went with the straightforward solution of adding new configuration.