-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Support Go time format strings in permalinks #6489
Conversation
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
@@ -173,8 +192,8 @@ func (l PermalinkExpander) validate(pp string) bool { | |||
} | |||
|
|||
for _, match := range matches { | |||
k := strings.ToLower(match[0][1:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lower casing the key turns out to be a bug: If you use :TITLE
as the key in the permalink configuration, it will pass this check, but then when trying to expand the permalink, it will fail because TITLE
isn't in the map and the code would panic.
I decided to remove this to lower because it makes date formats like Friday
not work because friday
is not a valid Go time format.
I added a test for the behavior that non-normalized permalink configuration keys aren't valid. It would pass on master as well, due to the bug noted above.
return callback, true | ||
} | ||
|
||
if referenceTime.Format(attr) != attr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smart!
🙇 Thanks for your help with this! Appreciate it. |
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. |
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: