Наиболее чосто используемые фильтры и команды Jekyll. Их описание установки, настройки и использования.
$ gem install jekyll
Структура
./
├── _config.yml
│
├── _data/
│ └── ...
│
├── _drafts/
│ └── ...
│
├── _posts/
│ └── 2014-01-01-hello.md
│
├── _layouts/
│ ├── default.html
│ └── post.html
│
├── _includes/ - partials
│ ├── header.html
│ └── footer.html
│
└── _site/
└── ...
Разметка
---
layout: post
title: Hello
---
Дополнительная разметка
permalink: '/hello'
published: false
category: apple
categories: ['html', 'css']
tags: ['html', 'css']
Конфигурация
source: .
destination: _site
exclude: [dir, file, ...]
include: ['.htaccess']
Variables
{{ site }} - from config.yml
{{ page }} - from frontmatter, and page-specific info
{{ content }} - html content (use in layouts)
{{ paginator }} - ...
Сайт
{{ 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.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.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 %}
Добавить в _config.yml:
paginate: 5
paginate_path: "blog/:num"
Код
def show
...
end
For
{% for post in site.posts %}
<a href="{{ post.url }}">
<h2>
{{ post.title }} — {{ post.date | date_to_string }}
</h2>
</a>
{{ post.content }}
{% endfor %}
Дата
{{ page.date | date: "%b %d, %Y" }}
If
{% if page.image.feature %}
{% else if xyz %}
{% else %}
{% endif %}
Includes (partials)
{% include header.html %}
Блог
_posts/YEAR-MONTH-DAY-title.md
Всавка изображения

Черновики
vi _drafts/a-draft-post.md
jekyll build --drafts
Превью
{{ post.excerpt | remove: '<p>' | remove: '</p>' }}
{{ post.excerpt | strip_html }}
Превью вставка
---
excerpt_separator: <!--more-->
---
Excerpt
<!--more-->
Out-of-excerpt
Пермалинк
# _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/members.yml
{% for member in site.data.members %}
Коллекции
# _config.yml
collections:
+ authors
# _/authors/a-n-roquelaire.md
---
name: A. N. Roquelaire
real_name: Anne Rice
---
{% for author in site.authors %}
Подсказки и фильтры Даты
{{ 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
| date: "%Y %m %d"
Процессы
| textilize
| markdownify
| jsonify
| sassify
| scssify
Массивы
site.posts | where:"year","2014"
site.posts | group_by:"genre" #=> { name, items }
site.posts | sort
| first
| last
| join: ","
| array_to_sentence_string #=> CSS, JavaScript and HTML
| map: "post" # works like 'pluck'
| size
Строки
| default: "xxx"
| upcase
| downcase
| remove: "<p>"
| replace: "super", "mega"
| remove_first: "<p>"
| replace_first: "super", "mega"
| truncate: 5
| truncatewords: 20
| prepend: "Mr. "
| append: " Sr."
| camelize
| capitalize
| pluralize
| strip_html
| strip_newlines
| newline_to_br
| split: ','
| escape
| escape_once
| slice: -3, 3
Строковые фильтры только для Jekkyl
| number_of_words
| slugify
| xml_escape #=> CDATA
| cgi_escape #=> foo%2Cbar
| uri_escape #=> foo,%20bar
Числа
| minus: 2
| plus: 1
| time: 4
| divided_by: 3
| modulo: 2
Комментарии
{% comment %}
{% endcomment %}
Встроить Bundler
# _plugins/bundler.rb
require "bunder/setup"
Bundler.require :default
Compass
Compass
Asset pipeline
Ссылки на рессурсы