I have a
_pages directory containing pages. I can set a permalink in a page’s frontmatter with:
However, specifying variables doesn’t work:
slug: test permalink /page/:slug/
slug is one of the documented template variables)
The permalink is processed but the variable is not expanded. The above example produces literally
Ultimately I want to specify the permalink as a default in
_config.yml. I have also tried that but it yields the same result - the permalink is produced but the variables are not expanded.
I am using Jekyll 3.7.0 so I should be bang up to date. I have seen other posts about this behaviour both here, GitHub and StackOverflow. They suggest this was a known issue that was resolved in earlier versions so I expect I am just doing it wrong ?
These things do work for posts. I am trying to do it for pages. How do I specify variables in a pages’ permalinks, in both frontmatter and defaults, but especially in defaults?
Having played around with this for a while, I think that variables are expanded but a limited set of variables are available. I think this set is defined by the
url_placeholders function in
page.rb and acceptable values are
I have been able to test permalinks specifed in both frontmatter and the defaults config section and the one that give me the effect that I’m after is
defaults: - scope: path: "" type: pages values: permalink: /page/:basename/
However… the behaviour differs between a permalink in frontmatter and one in the defaults config section. The latter causes many files to be generated, like
basename iterates over
sitemap as well as
test which is the one that was expected.
I fixed this by expressing the defaults like this:
defaults: - scope: path: "_pages" values: permalink: /page/:basename/
This works for me but I am not sure whether it is the right thing to do.