Creating a static site with Jekyll
This article explains how I created this site using Jekyll.
1. Installing Jekyll
My development environment is Linux Mint which is based on Ubuntu, so following commands will work for both. For other OS check the official Jekyll website.
Jekyll is based in ruby and uses gem to control its installation process, requiring the packages:
Once the ruby packages have been installed we can proceed to install Jekyll
2. Creating a new Jekyll Project
A Jekyll project is based in several preconfigured folders and files. For this example we will go with the basics, for further information check Jekyll Structure. To create a new site use the sintax jekyll new {project directory name}
that will create the following structure:
.
├── _config.yml
├── css
│ ├── main.css
│ └── syntax.css
├── index.html
├── _layouts
│ ├── default.html
│ └── post.html
└── _posts
└── 2014-01-23-welcome-to-jekyll.markdown
To modify this default folder structure check Jekyll Configuration
3. Configuration
This is not strictly necessary because the Jekyll has a basic configuration by default. We will only add some global properties and configure the markdown editor to use ‘redcarpet2’
_config.yml
DEPLOYS what is deployed and how
4. Page
Jekyll allow serveral ways to create a page, in this post I will focus on markdown.
page.md
In the YAML (after the first ---
) declaration we usually declare parameter for the page that will be generated (title, author,…). In the markdown declaration (after the second ---
) we will place the content. For further information check the official markdown documentation.
5. Layout
The layout will allow us to place the content generated in the markdown file in a good looking HTML.
markdown generates concrete HTML for each of its elements so the idea is to style this specific format using CSS based on the wrapper of the content, besides this, markdown allows to use plain HTML. From the layout side Jekyll allows the use on is templates of liquid.
In every layout there are three global vars that are always defined:
- site: that refers to the information declared in _config.yml
- page: information related the the page itself
- content: refering to the content generated by markdown
6. Includes
To keep it simple we will go for a simple header and footer that we will place in
_includes/header.html
_includes/footer.html
to use import this files in a layout we will use the following codes
Where the first part of the example shows how to pass parameters to an include. The parameter will be read as follows:
7. Paginated index
Once you have reached a certain numbers of posts, pagination is a must. Jekyll allow you to paginate the post in to basic steps:
- First will require to configure the pagination extension in the file config.yml:
where paginate
defines the number of post per page, and paginate_path
will define how the page is shown in the URL.
- The second one will be define the Liquid/HTML code to navigate through the index pages, that contain the links to the different post, this must be defined in the file index.html:
Apart of this, Jekyll also allow to navigate from a post to the next and the previous posts, this should be defined in the template for the posts: