Gasim
Gasim

Reputation: 7961

How to change paths and URLs in Jekyll?

I am very new to Jekyll and I am failing to find configuration to change the following:

  1. I built a basic Jekyll site using jekyll new . and ran jekyll serve to learn and built a layout using Jekyll. The basic test site gives me the following URL for posts: /jekyll/update/2016/01/30/welcome-to-jekyll.html. Is the URL like that because I am running jekyll serve and not jekyll build? I want to remove the the jekyll/update from the URL path, so my final URLs for posts look like the following: /2016/01/30/welcome-to-jekyll.html.

  2. I want my pages to be stored in a separate directory _pages instead of the root directory. How can I do that?

  3. Is there way to prepend a path to files loaded from a specific directory? For example, I want to make a /_projects directory. Then add files with the following permalinks: /prj-test1, /prj-test2, /prj-test3. When compiled, I want to get the following URLs: /projects/prj-test1, /projects/prj-test2, /projects/prj-test3, respectively. Is this possible?

Upvotes: 5

Views: 3898

Answers (1)

Virtua Creative
Virtua Creative

Reputation: 2113

Yes, everything you asked is possible.

  1. Take a look at these examples, you might want to choose one of them. But to do as you asked, you'll need to change the permalink to /:year/:month/:day/:title.html. To do that, add this line to your _config.yml file:

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

  2. It depends on the structure you want to achieve. You can use collections or simply create pages inside a folder called pages (without the underscore).

  3. Yes. You can do that via collections, for example.

I recommend you to take a look at some templates, so you can see how the code works in different ways:

  • Try some Jekyll Themes here and here. Download them and study their structures.

  • If you want to go deep, take a look how Jekyll build its own website.

Hope to have helped!

Upvotes: 14

Related Questions