Updated to correct content
I previously had pasted in the wrong page here. Now it's fixed.
This commit is contained in:
parent
11b4ae05e5
commit
a6d357050a
|
@ -1,580 +1,176 @@
|
|||
---
|
||||
layout: docs
|
||||
title: Templates
|
||||
permalink: /docs/templates/
|
||||
title: Themes
|
||||
permalink: /docs/themes/
|
||||
---
|
||||
|
||||
Jekyll uses the [Liquid](https://shopify.github.io/liquid/) templating language to
|
||||
process templates. All of the standard Liquid [tags](https://shopify.github.io/liquid/tags/) and
|
||||
[filters](https://shopify.github.io/liquid/filters/) are
|
||||
supported. Jekyll even adds a few handy filters and tags of its own to make
|
||||
common tasks easier.
|
||||
Jekyll has an extensive theme system that allows you to leverage community-maintained templates and styles to customize your site's presentation. Jekyll themes package up layouts, includes, and stylesheets in a way that can be overridden by your site's content.
|
||||
|
||||
## Filters
|
||||
## Understanding gem-based themes
|
||||
|
||||
<div class="mobile-side-scroller">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Description</th>
|
||||
<th><span class="filter">Filter</span> and <span class="output">Output</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Relative URL</strong></p>
|
||||
<p>Prepend the <code>baseurl</code> value to the input. Useful if your site is hosted at a subpath rather than the root of the domain.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "/assets/style.css" | relative_url }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">/my-baseurl/assets/style.css</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Absolute URL</strong></p>
|
||||
<p>Prepend the <code>url</code> and <code>baseurl</code> value to the input.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "/assets/style.css" | absolute_url }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">http://example.com/my-baseurl/assets/style.css</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Date to XML Schema</strong></p>
|
||||
<p>Convert a Date into XML Schema (ISO 8601) format.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.time | date_to_xmlschema }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">2008-11-07T13:07:54-08:00</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Date to RFC-822 Format</strong></p>
|
||||
<p>Convert a Date into the RFC-822 format used for RSS feeds.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.time | date_to_rfc822 }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">Mon, 07 Nov 2008 13:07:54 -0800</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Date to String</strong></p>
|
||||
<p>Convert a date to short format.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.time | date_to_string }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">07 Nov 2008</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Date to Long String</strong></p>
|
||||
<p>Format a date to long format.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.time | date_to_long_string }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">07 November 2008</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Where</strong></p>
|
||||
<p>Select all the objects in an array where the key has the given value.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.members | where:"graduation_year","2014" }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Where Expression</strong></p>
|
||||
<p>Select all the objects in an array where the expression is true. Jekyll v3.2.0 & later.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.members | where_exp:"item",
|
||||
"item.graduation_year == 2014" }}{% endraw %}</code>
|
||||
<code class="filter">{% raw %}{{ site.members | where_exp:"item",
|
||||
"item.graduation_year < 2014" }}{% endraw %}</code>
|
||||
<code class="filter">{% raw %}{{ site.members | where_exp:"item",
|
||||
"item.projects contains 'foo'" }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Group By</strong></p>
|
||||
<p>Group an array's items by a given property.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.members | group_by:"graduation_year" }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">[{"name"=>"2013", "items"=>[...]},
|
||||
{"name"=>"2014", "items"=>[...]}]</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Group By Expression</strong></p>
|
||||
<p>Group an array's items using a Liquid expression.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.members | group_by_exp:"item",
|
||||
"item.graduation_year | truncate: 3, \"\"" }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">[{"name"=>"201...", "items"=>[...]},
|
||||
{"name"=>"200...", "items"=>[...]}]</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>XML Escape</strong></p>
|
||||
<p>Escape some text for use in XML.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.content | xml_escape }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>CGI Escape</strong></p>
|
||||
<p>
|
||||
CGI escape a string for use in a URL. Replaces any special characters
|
||||
with appropriate %XX replacements.
|
||||
</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "foo,bar;baz?" | cgi_escape }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">foo%2Cbar%3Bbaz%3F</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>URI Escape</strong></p>
|
||||
<p>
|
||||
URI escape a string.
|
||||
</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "foo, bar \baz?" | uri_escape }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">foo,%20bar%20%5Cbaz?</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Number of Words</strong></p>
|
||||
<p>Count the number of words in some text.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.content | number_of_words }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">1337</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Array to Sentence</strong></p>
|
||||
<p>Convert an array into a sentence. Useful for listing tags. Optional argument for connector.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | array_to_sentence_string }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">foo, bar, and baz</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | array_to_sentence_string: 'or' }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">foo, bar, or baz</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Markdownify</strong></p>
|
||||
<p>Convert a Markdown-formatted string into HTML.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.excerpt | markdownify }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Smartify</strong></p>
|
||||
<p>Convert "quotes" into “smart quotes.”</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.title | smartify }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Converting Sass/SCSS</strong></p>
|
||||
<p>Convert a Sass- or SCSS-formatted string into CSS.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ some_scss | scssify }}{% endraw %}</code>
|
||||
<code class="filter">{% raw %}{{ some_sass | sassify }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Slugify</strong></p>
|
||||
<p>Convert a string into a lowercase URL "slug". See below for options.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "The _config.yml file" | slugify }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">the-config-yml-file</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "The _config.yml file" | slugify: 'pretty' }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">the-_config.yml-file</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Data To JSON</strong></p>
|
||||
<p>Convert Hash or Array to JSON.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.data.projects | jsonify }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Normalize Whitespace</strong></p>
|
||||
<p>Replace any occurrence of whitespace with a single space.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ "a \n b" | normalize_whitespace }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Sort</strong></p>
|
||||
<p>Sort an array. Optional arguments for hashes: 1. property name 2. nils order (<em>first</em> or <em>last</em>).</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | sort }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.posts | sort: 'author' }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.pages | sort: 'title', 'last' }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Sample</strong></p>
|
||||
<p>Pick a random value from an array. Optional: pick multiple values.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.pages | sample }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ site.pages | sample:2 }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>To Integer</strong></p>
|
||||
<p>Convert a string or boolean to integer.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ some_var | to_integer }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Array Filters</strong></p>
|
||||
<p>Push, pop, shift, and unshift elements from an Array.</p>
|
||||
<p>These are <strong>NON-DESTRUCTIVE</strong>, i.e. they do not mutate the array, but rather make a copy and mutate that.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | push: 'Spokane' }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">['Seattle', 'Tacoma', 'Spokane']</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | pop }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">['Seattle']</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | shift }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">['Tacoma']</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ page.tags | unshift: "Olympia" }}{% endraw %}</code>
|
||||
</p>
|
||||
<p>
|
||||
<code class="output">['Olympia', 'Seattle', 'Tacoma']</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p class="name"><strong>Inspect</strong></p>
|
||||
<p>Convert an object into its String representation for debugging.</p>
|
||||
</td>
|
||||
<td class="align-center">
|
||||
<p>
|
||||
<code class="filter">{% raw %}{{ some_var | inspect }}{% endraw %}</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
When you [create a new Jekyll site](/docs/quickstart) (by running the `jekyll new <PATH>` command), Jekyll installs a gem-based theme called [Minima](https://github.com/jekyll/minima).
|
||||
|
||||
### Options for the `slugify` filter
|
||||
With gem-based themes, some of the theme directories and files are stored in the gem, hidden from view in your Jekyll project. As a result, the files and directories shown for your site are only part of all the theme's files. In the case of Minima, you see only the following:
|
||||
|
||||
The `slugify` filter accepts an option, each specifying what to filter.
|
||||
The default is `default`. They are as follows (with what they filter):
|
||||
|
||||
- `none`: no characters
|
||||
- `raw`: spaces
|
||||
- `default`: spaces and non-alphanumeric characters
|
||||
- `pretty`: spaces and non-alphanumeric characters except for `._~!$&'()+,;=@`
|
||||
|
||||
## Tags
|
||||
|
||||
### Includes
|
||||
|
||||
If you have small page fragments that you want to include in multiple places on your site, you can use the `include` tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}{% include footer.html %}{% endraw %}
|
||||
```
|
||||
├── Gemfile
|
||||
├── Gemfile.lock
|
||||
├── _config.yml
|
||||
├── _posts
|
||||
│ └── 2016-12-04-welcome-to-jekyll.markdown
|
||||
├── about.md
|
||||
└── index.md
|
||||
```
|
||||
|
||||
Jekyll expects all include files to be placed in an `_includes` directory at the root of your source directory. In the above example, this will embed the contents of `_includes/footer.html` into the calling file.
|
||||
The `Gemfile` and `Gemfile.lock` files are used by Bundler to keep track of the required gems and gem versions you need to build your Jekyll site.
|
||||
|
||||
For more advanced information on using includes, see [Includes](../includes).
|
||||
Gem-based themes make it easy for theme developers to make updates available to anyone who has the theme gem. When there's an update, theme developers push the update to RubyGems.
|
||||
|
||||
### Code snippet highlighting
|
||||
If you have the theme gem, you can (if you desire) run `bundle update` to update all gems in your project. Or you can run `bundle update <theme>`, replacing `<theme>` with the theme name, such as `minima`, to just update the theme gem. Any new files or updates the theme developer has made (such as to stylesheets or includes) will be pulled into your project automatically.
|
||||
|
||||
Jekyll has built in support for syntax highlighting of over 60 languages
|
||||
thanks to [Rouge](http://rouge.jneen.net). Rouge is the default highlighter
|
||||
in Jekyll 3 and above. To use it in Jekyll 2, set `highlighter` to `rouge`
|
||||
and ensure the `rouge` gem is installed properly.
|
||||
The goal of gem-based themes is to allow you to get all the benefits of a robust, continually updated theme without having all the theme's files getting in your way and over-complicating what might be your primary focus: creating content.
|
||||
|
||||
Alternatively, you can use [Pygments](http://pygments.org) to highlight
|
||||
your code snippets. To use Pygments, you must have Python installed on your
|
||||
system, have the `pygments.rb` gem installed and set `highlighter` to
|
||||
`pygments` in your site's configuration file. Pygments supports [over 100
|
||||
languages](http://pygments.org/languages/)
|
||||
## Overriding theme defaults
|
||||
|
||||
To render a code block with syntax highlighting, surround your code as follows:
|
||||
Jekyll themes set default layouts, includes, and stylesheets. However, you can override any of the theme defaults with your own site content. For example, if your selected theme has a `page` layout, you can override the theme's layout by creating your own `page` layout in the `_layouts` directory (for example, `_layouts/page.html`).
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% highlight ruby %}
|
||||
def foo
|
||||
puts 'foo'
|
||||
end
|
||||
{% endhighlight %}
|
||||
{% endraw %}
|
||||
Jekyll will look first to your site's content before looking to the theme's defaults for any requested file in the following folders:
|
||||
|
||||
* `/assets`
|
||||
* `/_layouts`
|
||||
* `/_includes`
|
||||
* `/_sass`
|
||||
|
||||
Refer to your selected theme's documentation and source repository for more information on what files you can override.
|
||||
{: .note .info}
|
||||
|
||||
To locate theme's files on your computer:
|
||||
|
||||
1. Run `bundle show` followed by the name of the theme's gem, e.g., `bundle show minima` for default Jekyll's theme.
|
||||
|
||||
The location of the theme gem is returned. For example, minima is located in `/usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0` on a Mac.
|
||||
|
||||
2. Change to the directory's location and open the directory in Finder or Explorer:
|
||||
|
||||
```
|
||||
cd /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0
|
||||
open .
|
||||
# for Windows, use "explorer ."
|
||||
```
|
||||
|
||||
A Finder or Explorer window opens showing the theme's files and directories.
|
||||
|
||||
With a clear understanding of the theme's files, you can now override any theme file by creating a similarly named file in your Jekyll site directory.
|
||||
|
||||
If you want to get rid of the theme gem altogether, copy the files from the theme gem's directory into your Jekyll site directory (for example, copy them to `/myblog` if you created your Jekyll site at `/myblog`).
|
||||
|
||||
Then modify the Gemfile and configuration to remove references to the theme gem. For example, to remove Minima:
|
||||
* Open `Gemfile` and remove `gem "minima", "~> 2.0"`.
|
||||
* Open `_config.yml` and remove `theme: minima`.
|
||||
|
||||
Now `bundle update` will no longer get updates for the theme gem.
|
||||
|
||||
## Using themes other than the default {#installing-a-theme}
|
||||
|
||||
The `jekyll new <PATH>` command isn't the only way to create a new Jekyll site with a gem-based theme. You can also find gem-based themes online and incorporate them into your Jekyll project. To install a gem-based theme:
|
||||
|
||||
1. Add the theme to your site's `Gemfile`:
|
||||
|
||||
```
|
||||
gem 'my-awesome-jekyll-theme'
|
||||
```
|
||||
|
||||
3. Install the theme:
|
||||
|
||||
```
|
||||
bundle install
|
||||
```
|
||||
|
||||
3. Add the following to your site's `_config.yml` to activate the theme:
|
||||
|
||||
```
|
||||
theme: my-awesome-jekyll-theme
|
||||
```
|
||||
|
||||
5. Build your site:
|
||||
|
||||
```
|
||||
bundle exec jekyll serve
|
||||
```
|
||||
|
||||
You can have multiple themes listed in your site's `Gemfile`, but only one theme can be selected in your site's `_config.yml`.
|
||||
{: .note .info }
|
||||
|
||||
If you're publishing your Jekyll site on [Github Pages](https://pages.github.com/), note that Github Pages supports only some gem-based themes. See [Supported Themes](https://pages.github.com/themes/) in Github's documentation to see which themes are supported.
|
||||
|
||||
## Creating your own gem-based theme
|
||||
|
||||
If you're a Jekyll theme developer (rather than just a consumer of themes), you can package up your theme in RubyGems and allow users to install it through Bundler.
|
||||
|
||||
If you're unfamiliar with distributing ruby gems, don't worry. Jekyll will help you scaffold a new theme with the `new-theme` command. Just run `jekyll new-theme` with the theme name as an argument:
|
||||
|
||||
```sh
|
||||
jekyll new-theme my-awesome-theme
|
||||
create /path/to/my-awesome-theme/_layouts
|
||||
create /path/to/my-awesome-theme/_includes
|
||||
create /path/to/my-awesome-theme/_sass
|
||||
create /path/to/my-awesome-theme/_layouts/page.html
|
||||
create /path/to/my-awesome-theme/_layouts/post.html
|
||||
create /path/to/my-awesome-theme/_layouts/default.html
|
||||
create /path/to/my-awesome-theme/Gemfile
|
||||
create /path/to/my-awesome-theme/my-awesome-theme.gemspec
|
||||
create /path/to/my-awesome-theme/README.md
|
||||
create /path/to/my-awesome-theme/LICENSE.txt
|
||||
initialize /path/to/my-awesome-theme/.git
|
||||
create /path/to/my-awesome-theme/.gitignore
|
||||
Your new Jekyll theme, my-awesome-theme, is ready for you in /path/to/my-awesome-theme!
|
||||
For help getting started, read /path/to/my-awesome-theme/README.md.
|
||||
```
|
||||
|
||||
The argument to the `highlight` tag (`ruby` in the example above) is the
|
||||
language identifier. To find the appropriate identifier to use for the language
|
||||
you want to highlight, look for the “short name” on the [Rouge
|
||||
wiki](https://github.com/jayferd/rouge/wiki/List-of-supported-languages-and-lexers)
|
||||
or the [Pygments' Lexers page](http://pygments.org/docs/lexers/).
|
||||
Add your template files in the corresponding folders. Then complete the `.gemspec` and the README files according to your needs.
|
||||
|
||||
#### Line numbers
|
||||
### Layouts and includes
|
||||
|
||||
There is a second argument to `highlight` called `linenos` that is optional.
|
||||
Including the `linenos` argument will force the highlighted code to include line
|
||||
numbers. For instance, the following code block would include line numbers next
|
||||
to each line:
|
||||
Theme layouts and includes work just like they work in any Jekyll site. Place layouts in your theme's `/_layouts` folder, and place includes in your themes `/_includes` folder.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% highlight ruby linenos %}
|
||||
def foo
|
||||
puts 'foo'
|
||||
end
|
||||
{% endhighlight %}
|
||||
{% endraw %}
|
||||
```
|
||||
For example, if your theme has a `/_layouts/page.html` file, and a page has `layout: page` in its YAML front matter, Jekyll will first look to the site's `_layouts` folder for a the `page` layout, and if none exists, will use your theme's `page` layout.
|
||||
|
||||
#### Stylesheets for syntax highlighting
|
||||
### Assets
|
||||
|
||||
In order for the highlighting to show up, you’ll need to include a highlighting
|
||||
stylesheet. For an example stylesheet you can look at
|
||||
[syntax.css](https://github.com/mojombo/tpw/tree/master/css/syntax.css). These
|
||||
are the same styles as used by GitHub and you are free to use them for your own
|
||||
site. If you use `linenos`, you might want to include an additional CSS class
|
||||
definition for the `.lineno` class in `syntax.css` to distinguish the line
|
||||
numbers from the highlighted code.
|
||||
Any file in `/assets` will be copied over to the user's site upon build unless they have a file with the same relative path. You can ship any kind of asset here: SCSS, an image, a webfont, etc. These files behave just like pages and static files in Jekyll: if the file has [YAML front matter](../docs/frontmatter/) at the top, then it will be rendered. If it does not have YAML front matter, it will simply be copied over into the resulting site. This allows theme creators to ship a default `/assets/styles.scss` file which their layouts can depend on as `/assets/styles.css`.
|
||||
|
||||
### Gist
|
||||
All files in `/assets` will be output into the compiled site in the `/assets` folder just as you'd expect from using Jekyll on your sites.
|
||||
|
||||
Use the `gist` tag to easily embed a GitHub Gist onto your site. This works
|
||||
with public or secret gists:
|
||||
### Stylesheets
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% gist parkr/931c1c8d465a04042403 %}
|
||||
{% endraw %}
|
||||
```
|
||||
Your theme's stylesheets should be placed in your theme's `/_sass` folder, again, just as you would when authoring a Jekyll site. Your theme's styles can be included in the user's stylesheet using the `@import` directive.
|
||||
|
||||
You may also optionally specify the filename in the gist to display:
|
||||
### Documenting your theme
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% gist parkr/931c1c8d465a04042403 jekyll-private-gist.markdown %}
|
||||
{% endraw %}
|
||||
```
|
||||
Your theme should include a `/README.md` file, which explains how site authors can install and use your theme. What layouts are included? What includes? Do they need to add anything special to their site's configuration file?
|
||||
|
||||
To use the `gist` tag, you'll need to add the
|
||||
[jekyll-gist](https://github.com/jekyll/jekyll-gist) gem to your project.
|
||||
### Adding a screenshot
|
||||
|
||||
## Links
|
||||
Themes are visual. Show users what your theme looks like by including a screenshot as `/screenshot.png` within your theme's repository where it can be retrieved programatically. You can also include this screenshot within your theme's documentation.
|
||||
|
||||
### Linking to pages {#link}
|
||||
### Previewing your theme
|
||||
|
||||
To link to a post, a page, collection item, or file, the `link` tag will generate the correct permalink URL for the path you specify. For example, if you use the `link` tag to link to `mypage.html`, even if you change your permalink style to include the file extension or omit it, the URL formed by the `link` tag will always be valid.
|
||||
To preview your theme as you're authoring it, it may be helpful to add dummy content in, for example, `/index.html` and `/page.html` files. This will allow you to use the `jekyll build` and `jekyll serve` commands to preview your theme, just as you'd preview a Jekyll site.
|
||||
|
||||
You must include the file's original extension when using the `link` tag. Here are some examples:
|
||||
If you do preview your theme locally, be sure to add `/_site` to your theme's `.gitignore` file to prevent the compiled site from also being included when you distribute your theme.
|
||||
{: .info .note}
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ site.baseurl }}{% link _collection/name-of-document.md %}
|
||||
{{ site.baseurl }}{% link _posts/2016-07-26-name-of-post.md %}
|
||||
{{ site.baseurl }}{% link news/index.html %}
|
||||
{{ site.baseurl }}{% link /assets/files/doc.pdf %}
|
||||
{% endraw %}
|
||||
```
|
||||
### Publishing your theme
|
||||
|
||||
You can also use the `link` tag to create a link in Markdown as follows:
|
||||
Themes are published via [RubyGems.org](https://rubygems.org). You'll need a RubyGems account, which you can [create for free](https://rubygems.org/sign_up).
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
[Link to a document]({{ site.baseurl }}{% link _collection/name-of-document.md %})
|
||||
[Link to a post]({{ site.baseurl }}{% link _posts/2016-07-26-name-of-post.md %})
|
||||
[Link to a page]({{ site.baseurl }}{% link news/index.html %})
|
||||
[Link to a file]({{ site.baseurl }}{% link /assets/files/doc.pdf %})
|
||||
{% endraw %}
|
||||
```
|
||||
1. First, package your theme, by running the following command, replacing `my-awesome-jekyll-theme` with the name of your theme:
|
||||
|
||||
Including `{% raw %}{{site.baseurl}}{% endraw %}` is optional — it depends on whether you want the link to be absolute or root-relative.
|
||||
gem build my-awesome-jekyll-theme.gemspec
|
||||
|
||||
The path to the post, page, or collection is defined as the path relative to the root directory (where your config file is) to the file, not the path from your existing page to the other page.
|
||||
2. Next, push your packaged theme up to the RubyGems service, by running the following command, again replacing `my-awesome-jekyll-theme` with the name of your theme:
|
||||
|
||||
For example, suppose you're creating a link `page_a.md` (stored in `pages/folder1/folder2`) to `page_b.md` (stored in `pages/folder1`). Your path in the link would not be `../page_b.html`. Instead, it would be `/pages/folder1/page_b.md`.
|
||||
gem push my-awesome-jekyll-theme-*.gem
|
||||
|
||||
If you're unsure of the path, add `{% raw %}{{page.path}}{% endraw %}` to the page and it will display the path.
|
||||
|
||||
One major benefit of using the `link` tag is link validation. If the link doesn't exist, Jekyll won't build your site. This is a good thing, as it will alert you to a broken link so you can fix it (rather than allowing you to build and deploy a site with broken links).
|
||||
|
||||
Note you cannot add filters to `link` tags. For example, you cannot append a string using Liquid filters, such as `{% raw %}{% link mypage.html | append: "#section1" %} {% endraw %}`. To link to sections on a page, you will need to use regular HTML or Markdown linking techniques.
|
||||
|
||||
### Linking to posts
|
||||
|
||||
If you want like to include a link to a post on your site, the `post_url` tag will generate the correct permalink URL for the post you specify.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ site.baseurl }}{% post_url 2010-07-21-name-of-post %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
If you organize your posts in subdirectories, you need to include subdirectory path to the post:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ site.baseurl }}{% post_url /subdir/2010-07-21-name-of-post %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
There is no need to include the file extension when using the `post_url` tag.
|
||||
|
||||
You can also use this tag to create a link to a post in Markdown as follows:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
[Name of Link]({{ site.baseurl }}{% post_url 2010-07-21-name-of-post %})
|
||||
{% endraw %}
|
||||
```
|
||||
3. To release a new version of your theme, simply update the version number in the gemspec file, ( `my-awesome-jekyll-theme.gemspec` in this example ), and then repeat Steps 1 & 2 above.
|
||||
We recommend that you follow [Semantic Versioning](http://semver.org/) while bumping your theme-version.
|
||||
|
|
Loading…
Reference in New Issue