Harshil Shah
Harshil Shah

Reputation: 33

Jekyll permalinks based on layout

I'm working on my first Jekyll website, and I'm expecting to have a bunch of different things there such as blog posts, a linked list, photo albums, and so on, and have thus prepared a whole bunch of layouts to suit each of them.

So I was wondering if there was a way I could get Jekyll to set permalinks based on the layout, so that posts have their permalink automatically set to /layout_name/yy/mm/post_name.

I've been digging around Jekyll's permalink documentation and various Jekyll tutorials, but to no avail, and now I'm wondering if it's even possible to automate this.

Any help will be greatly appreciated, thanks!

Upvotes: 2

Views: 738

Answers (2)

Nikl
Nikl

Reputation: 221

I tried to do something similar and ended up writing a small plugin that allows you to use any Front Matter variable in the permalink setting. You can find the plugin with a usage example on GitHub.

This way you don't have to use the folder structure and can build the paths to each page in a collection using any Front Matter (including layout) from the files.

Upvotes: 0

David Jacquel
David Jacquel

Reputation: 52809

Following the principle that each type of page/post can be in a specific folder (eg: /albums for you photo albums), you can have a look at default configuration.

This can help you to set default permalink for a folder in _config.yml :

defaults:
  -
    scope:
      path: "albums" 
      type: "posts"
    values:
      permalink: "my/albums/"

Upvotes: 1

Related Questions