diff options
author | Luke Francl <look@recursion.org> | 2019-11-09 21:58:38 -0800 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-11-10 11:00:02 +0100 |
commit | 70a1aa345b95bcf325f19c6e7184bcd6f885e454 (patch) | |
tree | fee67032d577cabd8eaf2da981e444be2de7fa4e /docs/content | |
parent | cafecca440e495ec915cc6290fe09d2a343e9c95 (diff) |
Support Go time format strings in permalinks
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:
https://github.com/gohugoio/hugo/commit/07978e4a4922bc21c230fee65052232b829bd1ab#diff-0688a3b65c7f5d01aa216f8d9b57fd00R111-R112
https://discourse.gohugo.io/t/implementing-additional-date-formats-for-permalinks/17860
https://github.com/gohugoio/hugo/pull/6488
Diffstat (limited to 'docs/content')
-rw-r--r-- | docs/content/en/content-management/urls.md | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/content/en/content-management/urls.md b/docs/content/en/content-management/urls.md index 9cb16f52d..14971af43 100644 --- a/docs/content/en/content-management/urls.md +++ b/docs/content/en/content-management/urls.md @@ -38,6 +38,13 @@ permalinks: Only the content under `posts/` will have the new URL structure. For example, the file `content/posts/sample-entry.md` with `date: 2017-02-27T19:20:00-05:00` in its front matter will render to `public/2017/02/sample-entry/index.html` at build time and therefore be reachable at `https://example.com/2017/02/sample-entry/`. +If the standard date-based permalink configuration does not meet your needs, you can also format URL segments using [Go time formatting directives](https://golang.org/pkg/time/#Time.Format). For example, a URL structure with two digit years and month and day digits without zero padding can be accomplished with: + +{{< code-toggle file="config" copy="false" >}} +permalinks: + posts: /:06/:1/:2/:title/ +{{< /code-toggle >}} + You can also configure permalinks of taxonomies with the same syntax, by using the plural form of the taxonomy instead of the section. You will probably only want to use the configuration values `:slug` or `:title`. ### Permalink Configuration Values @@ -80,6 +87,8 @@ The following is a list of values that can be used in a `permalink` definition i `:filename` : the content's filename (without extension) +Additionally, a Go time format string prefixed with `:` may be used. + ## Aliases Aliases can be used to create redirects to your page from other URLs. |