Permalinks
A permalink is the determination of what the output URL of your resource will be. Every resource uses a permalink processer to figure out where to save your transformed resource in the output folder tree.
Resources in the pages collection are the most straightforward. The filenames and folder structure of your pages will result in matching output URLs. For example, a file saved at src/_pages/this/is/great.md
would be output to /this/is/great/
.
For resources in the posts collection, Bridgetown ships with few permalink “styles”. The posts permalink style is configured by using the permalink
key in the config file. If the key isn’t present, the default is pretty
.
The available styles are:
pretty
:/[locale]/:categories/:year/:month/:day/:slug/
pretty_ext
:/[locale]/:categories/:year/:month/:day/:slug.*
simple
:/[locale]/:categories/:slug/
simple_ext
:[locale]/:categories/:slug.*
(Including .*
at the end means it will output the resource with its own slug and extension. Alternatively, /
at the end will put the resource in a folder of that slug with index.html
inside.)
To set a permalink style or template for a custom collection, add it to your collection metadata in bridgetown.config.yml
. For example:
collections:
articles:
permalink: pretty
would make your articles collection behave the same as posts. Or you can create your own template:
collections:
articles:
permalink: /lots-of/:collection/:year/:title/
This would result in URLs such as /lots-of/articles/2021/super-neato/
.
Placeholders #
All of the segments you see above starting with a colon, such as :year
or :slug
, are called placeholders. Bridgetown ships with a number of placeholders, but you can also create your own! See the placeholders plugin page for details.
Here’s the full list of built-in placeholders available:
Variable | Description |
---|---|
|
Four-digit year based on the resource's date. |
|
Two-digit year based on the resource's date within its century (00..99). |
|
Month based on the resource's date (01..12). |
|
Month based on the resource's date without leading zeros (1..12). |
|
Day of the month based on the resource's date (01..31). |
|
Day of the month based on the resource's date without leading zeros (1..31). |
|
The specified categories for the resource. If a resource has multiple
categories, Bridgetown will create a hierarchy (e.g. |
|
Adds the locale key of the current rendering context, if its not the default site locale. |
|
Title from the resource's front matter (aka |
|
Extracted from the resources’s filename. May be overridden via the resources’s |
|
Extracted from the resources’s filename and cannot be overridden. |
|
Constructs URL segments out of the relative path of the resource within its collection folder. Used by the pages collection as well as custom collections if no specific permalink config is provided. |
|
Outputs the label of the resource's custom collection (will be blank for the built-in pages and posts collections). |