cheatsheets/jekyll.md

4.7 KiB

title layout jekyll_escape
Jekyll default true

{% raw %}

Installation

$ gem install jekyll

Directories

_config.yml

_drafts/

_includes/
  header.html
  footer.html

_layouts/
  default.html

_posts/
  2013-09-02-hello.md

_site/
  ...

Front-matter

---
layout: post
title: Hello
---

Other frontmatter stuff

permalink: '/hello'
published: false
category: apple
categories: ['html', 'css']
tags: ['html', 'css']

Configuration

source: .
destination: _site
exclude: [dir, file, ...]
include: ['.htaccess']

Reference

Variables

{{ site }}       - from config.yml
{{ page }}       - from frontmatter, and page-specific info
{{ content }}    - html content (use in layouts)
{{ paginator }}  - ...

Site

{{ site.time }}                 - current time
{{ site.pages }}                - list of pages
{{ site.posts }}                - list of posts
{{ site.related_posts }}        - list
{{ site.categories.CATEGORY }}  - list
{{ site.tags.TAG }}             - list

{{ site.static_files }}

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 }}
{{ post.excerpt | remove: '<p>' | remove: '</p>' }}
{{ post.excerpt | strip_html }}

<!-- blog pagination: -->
{{ page.next }}
{{ page.previous }}

Paginator

{{ paginator.page }}         - page number
{{ paginator.total_posts}}
{{ paginator.total_pages}}
{{ paginator.per_page }}

{% for post in paginator.posts %} ... {% endfor %}

{% if paginator.previous_page %}
  <a href="{{ paginator.previous_page_path }}">Previous</a>
{% else %}
{% endif %}

{{ paginator.next_page }}     - page number
{{ paginator.next_page_path }}
...

{% if paginator.total_pages > 1 %}
{% endif %}

Add this to _config.yml:

paginate: 5
paginate_path: "blog/:num"

Code

{% highlight ruby linenos %}
def show
  ...
end
{% endhighlight %}

Markup

Loops

{% for post in site.posts %}
  <a href="{{ post.url }}">
    <h2>{{ post.title }} &mdash; {{ post.date | date_to_string }}</h2>
  </a>
  {{ post.content }}
{% endfor %}

Dates

{{ page.date | date: "%b %d, %Y" }}

If

{% if page.image.feature %}
{% else %}
{% endif %}

Includes (partials)

{% include header.html %}

Blogging

_posts/YEAR-MONTH-DAY-title.md

Image paths

![My helpful screenshot]({{ site.url }}/assets/screenshot.jpg)

Drafts

vi _drafts/a-draft-post.md
jekyll build --drafts
# _config.yml
permalink: date   # /:categories/:year/:month/:day/:title.html
permalink: pretty # /:categories/:year/:month/:day/:title/
permalink: none   # /:categories/:title.html
permalink: "/:title"

Data

_data/members.yml

{% for member in site.data.members %}

Helpers and Filters

 {{ site.time | date_to_xmlschema }}   #=> 2008-11-07T13:07:54-08:00
 {{ site.time | date_to_rfc822 }}      #=> Mon, 07 Nov 2008 13:07:54 -0800
 {{ site.time | date_to_string }}      #=> 07 Nov 2008
 {{ site.time | date_to_long_string }} #=> 07 November 2008

 | where:"year","2014"
 | group_by:"genre"
 | sort

 | xml_escape
 | cgi_escape
 | uri_escape

 | array_to_sentence_string
 | number_of_words

 | textilize
 | markdownify
 | jsonify

 | camelize
 | capitalize
 | pluralize

 | date: "%Y %m %d"
 | default: "xxx"

 | replace: "super", "mega"
 | replace_first: "super", "mega"

Comments

{% comment %}
{% endcomment %}

Integration

Bundler

# _plugins/bundler.rb
require "bunder/setup"
Bundler.require :default

Compass

References