Installation
# Install the gems
gem install jekyll bundler
# Create a new site at `./myblog`
jekyll new myblog
cd myblog
# Optional: if you're targeting github-pages,
# use this Gemfile instead.
cat > Gemfile <<-END
source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins
END
bundle exec jekyll serve
See: Jekyll quickstart
See: github/pages-gem
Directories
./
βββ _config.yml
β
βββ _data/
β βββ ...
β
βββ _drafts/
β βββ ...
β
βββ _posts/
β βββ 2014-01-01-hello.md
β
βββ _layouts/
β βββ default.html
β βββ post.html
β
βββ _includes/ - partials
β βββ header.html
β βββ footer.html
β
βββ _site/
βββ ...
Front-matter
Basic frontmatter
---
layout: post
title: Hello
---
Hello! this is my post.
Attach metadata to a page by adding them on top of the page, delimited by ---
.
See: Front-matter
Other frontmatter stuff
permalink: '/hello'
published: false
category: apple
categories: ['html', 'css']
tags: ['html', 'css']
Configuration
In _config.yml
:
source: .
destination: _site
exclude:
- Gemfile
- Gemfile.lock
include: ['.htaccess']
All config keys are optional. See: Configuration
Markup
Page variables
<title>
{{ page.title }}
</title>
Filters
<p>
{{ page.description | truncate_words: 20 }}
</p>
Loops
{% for post in site.posts %}
<a href="{{ post.url }}">
<h2>{{ post.title }}</h2>
<p>{{ post.date | date_to_string }}</p>
</a>
{% endfor %}
Dates
{{ page.date | date: "%b %d, %Y" }}
Conditionals
{% if page.image.feature %}
...
{% elsif xyz %}
...
{% else %}
...
{% endif %}
{% if page.category == 'React' %}
{% if page.category == 'React' or page.featured %}
{% if page.tags contains 'Featured' %}
Case
{% case shipping.title %}
{% when 'international' %}
Arriving in 2-3 weeks
{% when 'Domestic' %}
Arriving in 2-3 days
{% else %}
Thank you for your order!
{% endcase %}
Includes (partials)
{% include header.html %}
<!-- Including local vars -->
{% include header.html page=page %}
Comments
{% comment %}
This is a comment!
{% endcomment %}
Variables
Top-level variables
{{ site }} |
Data from config.yml |
{{ page }} |
From frontmatter, and page-specific info |
{{ content }} |
HTML content (use in layouts) |
{{ paginator }} |
Paginator |
See: Variables
Site
{{ site.time }}
site.time |
Current time |
site.pages |
List of pages |
site.posts |
List of blog posts |
site.related_posts |
List of posts related to current |
site.categories.CATEGORY |
List |
site.tags.TAG |
List |
site.static_files |
List |
Page
{{ page.content }} - un-rendered content
{{ page.title }}
{{ page.excerpt }} - un-rendered excerpt
{{ page.url }}
{{ page.date }}
{{ page.id }} - unique id for RSS feeds
{{ page.categories }}
{{ page.tags }}
{{ page.path }}
{{ page.dir }}
{{ page.excerpt | remove: '<p>' | remove: '</p>' }}
{{ page.excerpt | strip_html }}
<!-- blog pagination: -->
{{ page.next }}
{{ page.previous }}
Filters
Dates
{{ site.time | date: "%Y %m %d" }}
date_to_xmlschema |
β 2008-11-07T13:07:54-08:00 |
date_to_rfc822 |
β Mon, 07 Nov 2008 13:07:54 -0800 |
date_to_string |
β 07 Nov 2008 |
date_to_long_string |
β 07 November 2008 |
date: β%Y %m %dβ |
β 2017 Nov 7 |
Preprocessors
{{ page.description | markdownify }}
Filter | Description |
---|---|
textilize |
Textile |
markdownify |
Markdown |
jsonify |
JSON |
sassify |
Sass |
scssify |
SCSS |
smartify |
Smartypants |
Array filters
{{ site.pages | where: "year", "2014" }}
Filter | Description |
---|---|
where: βyearβ, β2014β |
Β |
where_exp: βitemβ, βitem.year >= 2014β |
Β |
group_by: βgenreβ |
β {name, items} |
group_by_exp: βitemβ, βitem.genreβ |
β {name, items} |
sort |
Β |
sort: βauthorβ |
Β |
uniq |
Β |
first |
Β |
last |
Β |
join: β,β |
Β |
array_to_sentence_string |
β "X, Y and Z" |
map: βpostβ |
Works like βpluckβ |
size |
Β |
push: βxxxβ |
Adds an item |
String filters
{{ page.title | default: "xxx" }}
Filter | Description |
---|---|
default: βxxxβ |
Β |
upcase |
Β |
downcase |
Β |
remove: βpβ |
Β |
replace: βsuperβ, βmegaβ |
Β |
remove_first: βpβ |
Β |
replace_first: βsuperβ, βmegaβ |
Β |
truncate: 5 |
Β |
truncatewords: 20 |
Β |
prepend: βMr. β |
Β |
append: βJr.β |
Β |
camelize |
Β |
capitalize |
Β |
strip_html |
Β |
strip_newlines |
Β |
newlines_to_br |
Β |
split: β,β |
Β |
escape |
Β |
escape_once |
Β |
slice: -3, 3 |
Β |
See: String filters
String filters (Jekyll-only)
{{ page.excerpt | number_of_words }}
Filter | Description |
---|---|
number_of_words |
Β |
slugify |
Β |
xml_escape |
β CDATA |
cgi_escape |
β foo%2Cbar |
uri_escape |
β foo,%20bar |
Numbers
{{ site.posts.size | minus: 2 }}
Filter | Description |
---|---|
minus: 2 |
Β |
plus: 2 |
Β |
times: 2 |
Β |
divided_by: 2 |
Β |
modulo: 2 |
Β |
ceil |
Β |
floor |
Β |
round |
Β |
Paginator
Paginator setup
Add this to _config.yml
:
paginate: 5
paginate_path: "blog/:num"
See: Paginator
Numbers
{{ paginator.page }} - page number
{{ paginator.total_posts }}
{{ paginator.total_pages }}
{{ paginator.per_page }}
Iterating through posts
{% for post in paginator.posts %} ... {% endfor %}
Previous button
{% if paginator.total_pages > 1 %}
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path }}">Previous</a>
{% else %}
{% endif %}
{% endif %}
{{ paginator.next_page }} - page number
{{ paginator.next_page_path }}
Blogging
Paths
_posts/YEAR-MONTH-DAY-title.md
See: Blogging
Image paths
![My helpful screenshot]({{ site.url }}/assets/screenshot.jpg)
See: Image paths
Drafts
vi _drafts/a-draft-post.md
jekyll build --drafts
Posts in _drafts
only show up in development, but not production.
See: Drafts
Defining excerpts
---
title: My blog post
excerpt: This post is about cats
---
Hello, let's talk about cats. (Β·Β·Β·)
Put a key excerpt
in the frontmatter.
See: Excerpts
Displaying excerpts
{{ post.excerpt }}
{{ post.excerpt | remove: '<p>' | remove: '</p>' }}
{{ post.excerpt | strip_html }}
Excerpt separator
---
excerpt_separator: <!--more-->
---
Excerpt here
<!--more-->
More post body here
Alternatively, you can put excerpts inline in your post by defining excerpt_separator
.
Permalinks
# _config.yml
permalink: date # /:categories/:year/:month/:day/:title.html
permalink: pretty # /:categories/:year/:month/:day/:title/
permalink: none # /:categories/:title.html
permalink: "/:title"
See: Permalinks
More features
Data
_data/members.yml
{% for member in site.data.members %}
...
{% endfor %}
See: Data
Collections
# _config.yml
collections:
- authors
# _/authors/a-n-roquelaire.md
---
name: A. N. Roquelaire
real_name: Anne Rice
---
{% for author in site.authors %}
See: Collections
Code highlighter
{% highlight ruby linenos %}
def show
...
end
{% endhighlight %}
Integration
Bundler
In _plugins/bundler.rb
:
require "bunder/setup"
Bundler.require :default
Compass
Also see
- Jekyll docs jekyllrb.com
- CloudCannon Jekyll cheatsheet cloudcannon.com
- Jekyll: templates jekyllrb.com
- Liquid: output shopify.com
- Liquid: logic shopify.com
- Liquid: filters shopify.com
- Liquid for designers github.com/Shopify