How to customize Jekyll's url? How to customize Jekyll's url? ruby ruby

How to customize Jekyll's url?


In the _config file you can change the permalink to anything you like, for example mine is

permalink: /blog/:title

As for the date you can choose your own date using the YAML front matter, again in mine i have

title: exampledate: you can pick what ever date you want


If you aren't producing blog pages, you can create files in the directory structure mapping to certain URLs. Running on localhost, if your directory has the structure

- _layouts/- config.yml- index.html- some_other_page.html- some_directory/    - index.html    - some_sub_page.html

You'll have content at the following locations after jekyll has processed the files:

  • 0.0.0.0:4000 (index.html)
  • 0.0.0.0:4000/some_other_page.html (some_other_page.html)
  • 0.0.0.0:4000/some_directory (some_directory/index.html)
  • 0.0.0.0:4000/some_directory/some_sub_page.html (some_directory/some_sub_page.html)

You can also use the permalink attribute on each post to set one manually, or set a different default in config.yml Permalinks only have a small subset of variables available to use and need to be defined in every single file you want to put in a non-standard location.

This directory structure will automatically categorize your posts too. So you can have:

- some_category (defined in the yaml front matter or the _config.yml    - index.html    - _posts/        - some_post.md        - some_other_post.md

And posts will automatically have the category 'some category', and index.html will appear at 0.0.0.0:4000/some-category, with the default permalink format. The category variable is available as :category in the permalink format string.


What the docs say:

You configure permalinks in your _config.yml file like this:

permalink: /:categories/:year/:month/:day/:title.html

If you don’t specify any permalink setting, Jekyll uses the above pattern as the default. The permalink can also be set using a built-in permalink style:

permalink: date

Although you can specify a custom permalink pattern using template variables, Jekyll also provides the following built-in styles for convenience.

  • date = /:categories/:year/:month/:day/:title.html
  • pretty = /:categories/:year/:month/:day/:title/
  • ordinal = /:categories/:year/:y_day/:title.html
  • none = /:categories/:title.html

Source: https://jekyllrb.com/docs/permalinks/


This is the basic setting I use:

permalink: pretty

This sets pages to the pretty permalink style. Thus '/contact.md' will become '/contact/'.

How I use it for blog posts:

permalink: /blog/:title/

This makes sure the path contains the (sluggified) title.

How I use it for collections:

permalink: /desiredpath/:name/

This makes sure the path contains the filename.