Reputation: 12019
I would like all posts and pages on my Jekyll site to have the same link structure: example.com/my-title
, regardless of the directory structure I use to store my files.
Looking at the documentation it seems like I should be able to implement this by putting the following line in my _config.yml
:
permalink: /:title
.
This almost works. All posts (in the _posts/
directory) get the correct URL. And all pages in my site's home directory also get the correct url. However, pages that are in subdirectories still have the directory path prefixed to the url. For example, if I have a page pages/cats/my-cat.md
the URL is example.com/pages/cats/my-cat
, instead of what I want (example.com/my-cat
). If I set the permalink for that page directly in the front matter as /my-cat
I get the desired outcome, but I'd rather not do this on every page.
Is it possible to remove the path from all page URLs?
I see a number of other questions about Jekyll permalinks but nothing that addresses this exactly. This answer from 2013 says that pages will "always remain relative path" but that's fairly old, and also seemed like a throwaway assertion rather than an evidence-backed claim.
Upvotes: 3
Views: 1020
Reputation: 2861
You can use Jekyll defaults to apply fallback front matter for files based on a type and/or path. It has the same effect as setting the front matter inside each file. Here's how you could apply that permalink to all pages:
_config.yml
:
defaults:
- scope:
path: ''
type: pages
values:
permalink: /:title
It's also a great way to set other common fields, e.g. layout
.
Official documentation for further details: https://jekyllrb.com/docs/configuration/front-matter-defaults/
Upvotes: 2