Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize Jekyll's url?

Tags:

html

ruby

jekyll

I would like to use Jekyll to create a site. not a blog. Is there a way to avoid to have the creation date specified in the url and in the page's file name?

I think that the idea behind Jekyll is brilliant, but it seems too tied to blog generation content while it could be useful also in a more general use case.

like image 565
alessmar Avatar asked Dec 29 '11 06:12

alessmar


People also ask

What is the url of Jekyll?

They all start with http://localhost:4000 or http://127.0.0.1:4000 . This happens because in older versions of Jekyll (v3. 3 through 4.1) it would reset site. url to localhost:4000 when JEKYLL_ENV=development (the default environment value), overriding whatever is set in the _config.


2 Answers

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: example date: you can pick what ever date you want 
like image 191
joshuahornby10 Avatar answered Sep 29 '22 20:09

joshuahornby10


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.

like image 32
JoostS Avatar answered Sep 29 '22 19:09

JoostS