Skip to content
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

Merged
merged 1 commit into from Nov 10, 2019

Conversation

@look
Copy link
Contributor

look commented Nov 10, 2019

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:

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
@@ -173,8 +192,8 @@ func (l PermalinkExpander) validate(pp string) bool {
}

for _, match := range matches {
k := strings.ToLower(match[0][1:])

This comment has been minimized.

Copy link
@look

look Nov 10, 2019

Author Contributor

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 {

This comment has been minimized.

Copy link
@bep

bep Nov 10, 2019

Member

Smart!

@bep bep mentioned this pull request Nov 10, 2019
@bep bep merged commit 70a1aa3 into gohugoio:master Nov 10, 2019
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details
@look

This comment has been minimized.

Copy link
Contributor Author

look commented Nov 10, 2019

🙇 Thanks for your help with this! Appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.