Note: The book edition is still an early release and a work-in-progess.
This is the (official) documentation for the Jekyll static site builder / generator reformatted in a single-page book edition.
See the source repo for how the book gets auto-built with "plain" Jekyll - of course - and hosted on GitHub Pages.
Questions? Comments? Send them to the Jekyll Talk forum post titled Jekyll Docu Reformatted as a Single-Page in Black 'n' White (Book Version) - Why? Why Not?.
Onwards.
Thanks to all Jekyll contributors for making it all possible.
In general, plugins you make will fall into one of four categories:
You can create a generator when you need Jekyll to create additional content based on your own rules.
A generator is a subclass of Jekyll::Generator
that defines a generate
method, which receives an instance of
Jekyll::Site
. The
return value of generate
is ignored.
Generators run after Jekyll has made an inventory of the existing content, and
before the site is generated. Pages with YAML Front Matters are stored as
instances of
Jekyll::Page
and are available via site.pages
. Static files become instances of
Jekyll::StaticFile
and are available via site.static_files
. See
the Variables documentation page and
Jekyll::Site
for more details.
For instance, a generator can inject values computed at build time for template
variables. In the following example the template reading.html
has two
variables ongoing
and done
that we fill in the generator:
This is a more complex generator that generates new pages:
In this example, our generator will create a series of files under the
categories
directory for each category, listing the posts in each category
using the category_index.html
layout.
Generators are only required to implement one method:
Method | Description |
---|---|
|
Generates content as a side-effect. |
If you have a new markup language you’d like to use with your site, you can include it by implementing your own converter. Both the Markdown and Textile markup languages are implemented using this method.
Jekyll will only convert files that have a YAML header at the top, even for converters you add using a plugin.
Below is a converter that will take all posts ending in .upcase
and process
them using the UpcaseConverter
:
Converters should implement at a minimum 3 methods:
Method | Description |
---|---|
|
Does the given extension match this converter’s list of acceptable
extensions? Takes one argument: the file’s extension (including the
dot). Must return |
|
The extension to be given to the output file (including the dot).
Usually this will be |
|
Logic to do the content conversion. Takes one argument: the raw content of the file (without YAML Front Matter). Must return a String. |
In our example, UpcaseConverter#matches
checks if our filename extension is
.upcase
, and will render using the converter if it is. It will call
UpcaseConverter#convert
to process the content. In our simple converter we’re
simply uppercasing the entire content string. Finally, when it saves the page,
it will do so with a .html
extension.
As of version 2.5.0, Jekyll can be extended with plugins which provide
subcommands for the jekyll
executable. This is possible by including the
relevant plugins in a Gemfile
group called :jekyll_plugins
:
Each Command
must be a subclass of the Jekyll::Command
class and must
contain one class method: init_with_program
. An example:
Commands should implement this single class method:
Method | Description |
---|---|
|
This method accepts one parameter, the
|
If you’d like to include custom liquid tags in your site, you can do so by
hooking into the tagging system. Built-in examples added by Jekyll include the
highlight
and include
tags. Below is an example of a custom liquid tag that
will output the time the page was rendered:
At a minimum, liquid tags must implement:
Method | Description |
---|---|
|
Outputs the content of the tag. |
You must also register the custom tag with the Liquid template engine as follows:
In the example above, we can place the following tag anywhere in one of our pages:
And we would get something like this on the page:
You can add your own filters to the Liquid template system much like you can add tags above. Filters are simply modules that export their methods to liquid. All methods will have to take at least one parameter which represents the input of the filter. The return value will be the output of the filter.
Jekyll lets you access the site
object through the
context.registers
feature of Liquid at context.registers[:site]
. For example, you can
access the global configuration file _config.yml
using
context.registers[:site].config
.
Using hooks, your plugin can exercise fine-grained control over various aspects of the build process. If your plugin defines any hooks, Jekyll will call them at pre-defined points.
Hooks are registered to a container and an event name. To register one, you call Jekyll::Hooks.register, and pass the container, event name, and code to call whenever the hook is triggered. For example, if you want to execute some custom functionality every time Jekyll renders a post, you could register a hook like this:
Jekyll provides hooks for :site
, :pages
,
:posts
, and :documents
. In all cases, Jekyll calls your
hooks with the container object as the first callback parameter. But in the
case of :pre_render
, your hook will also receive a payload hash as
a second parameter which allows you full control over the variables that are
available while rendering.
The complete list of available hooks is below:
Container | Event | Called |
---|---|---|
|
|
Just after site reset |
|
|
After site data has been read and loaded from disk |
|
|
Just before rendering the whole site |
|
|
After rendering the whole site, but before writing any files |
|
|
After writing the whole site to disk |
|
|
Whenever a page is initialized |
|
|
Just before rendering a page |
|
|
After rendering a page, but before writing it to disk |
|
|
After writing a page to disk |
|
|
Whenever a post is initialized |
|
|
Just before rendering a post |
|
|
After rendering a post, but before writing it to disk |
|
|
After writing a post to disk |
|
|
Whenever a document is initialized |
|
|
Just before rendering a document |
|
|
After rendering a document, but before writing it to disk |
|
|
After writing a document to disk |
If you’re interested in creating a custom markdown processor, you’re in luck! Create a new class in the Jekyll::Converters::Markdown
namespace:
Once you’ve created your class and have it properly set up either as a plugin
in the _plugins
folder or as a gem, specify it in your _config.yml
:
There are two flags to be aware of when writing a plugin:
Flag | Description |
---|---|
|
A boolean flag that informs Jekyll whether this plugin may be safely
executed in an environment where arbitrary code execution is not
allowed. This is used by GitHub Pages to determine which core plugins
may be used, and which are unsafe to run. If your plugin does not
allow for arbitrary code execution, set this to |
|
This flag determines what order the plugin is loaded in. Valid values
are: |
To use one of the example plugins above as an illustration, here is how you’d specify these two flags: