Force 3-digit yearday

I need to create permalinks for my pages in this format: /2020/123/0.
In my config I created this permalink setup:

  note = "/:year/:yearday/:filename"

For posts which are made before the 100th day of the year Hugo creates 1 or 2 digit yeardays as per documentation. To not break a bunch of old links I need padding for those links that are created before the 100th day of the year so that a post created on January 10th would result in this link: 2022/010/0

Is there any facility I can leverage to pad yeardays with zeros when < 100? I do not know anything about Go but I was thinking that maybe the last phrase in that section could help?

Additionally, a Go time format string prefixed with : may be used.

Searching for “padding yearday” and “format padding date” etc. did not yield any results.

You should be able to use :__2 (it’s in the Go Doc for time.Format). The underscores represents the padding.

note = "/:year/:__2/:filename"
.Date Resulting URL
2021-04-10 2021/100/test/index.html
2021-04-09 2021/-99/test/index.html
2021-01-09 2021/-9/test/index.html

OK, I read the spec wrong. Using 002 seem to do the trick:

1 Like

Thank you, that did the trick. However I had to write :002 for it to work.

1 Like

Yeah, the spec didn’t make sense to me:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.