Rewrite documentation on installing plugins (#8921)
Merge pull request 8921
This commit is contained in:
parent
1008f1b4e3
commit
b0a68d56fc
|
|
@ -3,77 +3,123 @@ title: Plugins
|
||||||
permalink: /docs/plugins/installation/
|
permalink: /docs/plugins/installation/
|
||||||
---
|
---
|
||||||
|
|
||||||
You have 3 options for installing plugins:
|
Jekyll has built-in support for using plugins to extend the core functionality.
|
||||||
|
|
||||||
1. In your site source root, make a `_plugins` directory. Place your plugins
|
Primarily, any file with extension `.rb` placed within a `_plugins` directory at the root of the site's `source`, will be automatically loaded
|
||||||
here. Any file ending in `*.rb` inside this directory will be loaded before
|
during a build session.
|
||||||
Jekyll generates your site.
|
|
||||||
|
|
||||||
2. In your `_config.yml` file, add a new array with the key `plugins` (or `gems` for Jekyll < `3.5.0`) and the
|
This behavior can be configured as follows:
|
||||||
values of the gem names of the plugins you'd like to use. An example:
|
|
||||||
|
- The `_plugins` directory may be changed either directly via the command-line or via the configuration file(s).
|
||||||
|
- Plugins in the `_plugins` directory (or its equivalent(s)) will not be loaded when Jekyll is running in `safe` mode.
|
||||||
|
- This route cannot be used to extend the Jekyll CLI.
|
||||||
|
|
||||||
|
To work with plugins packaged as gems, one has to list the desired gems in the configuration file under a top-level key named `plugins`.
|
||||||
|
Additionally, if you're building in `safe` mode, the gem needs to be listed under a top-level key named `whitelist`. For example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# This will require each of these plugins automatically.
|
|
||||||
plugins:
|
plugins:
|
||||||
- jekyll-gist
|
- jekyll-gist
|
||||||
- jekyll-coffeescript
|
- jekyll-coffeescript
|
||||||
- jekyll-assets
|
- jekyll-seo-tag
|
||||||
- another-jekyll-plugin
|
- some-other-jekyll-plugin
|
||||||
|
|
||||||
|
# Enable safe mode
|
||||||
|
safe: true
|
||||||
|
|
||||||
|
# Whitelist plugins under safe mode.
|
||||||
|
# Note that `some-other-jekyll-plugin` is not listed here. Therefore,
|
||||||
|
# it will not be loaded under safe mode.
|
||||||
|
whitelist:
|
||||||
|
- jekyll-gist
|
||||||
|
- jekyll-coffeescript
|
||||||
|
- jekyll-seo-tag
|
||||||
```
|
```
|
||||||
|
|
||||||
Then install your plugins using `gem install jekyll-gist jekyll-coffeescript jekyll-assets another-jekyll-plugin`
|
In the absence of a Gemfile, one must manually ensure that listed plugins have been installed prior to invoking Jekyll. For example, the
|
||||||
|
latest versions of gems in the above list may be installed to a system-wide location by running:
|
||||||
|
|
||||||
3. Add the relevant plugins to a Bundler group in your `Gemfile`. An
|
```sh
|
||||||
example:
|
gem install jekyll-gist jekyll-coffeescript jekyll-remote-theme some-other-jekyll-plugin
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using a Gemfile
|
||||||
|
|
||||||
|
The maintenance of various gem dependencies may be greatly simplified by using a Gemfile (usually at the root of the site's source) in
|
||||||
|
conjunction with a Rubygem named `bundler`. The Gemfile however **should** list all the primary dependencies of your site, including Jekyll
|
||||||
|
itself, not just gem-based plugins of the site because Bundler narrows the scope of installed gems to just *runtime dependencies* resolved by
|
||||||
|
evaluating the Gemfile. For example:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
group :jekyll_plugins do
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
# Use the latest version.
|
||||||
|
gem "jekyll"
|
||||||
|
|
||||||
|
# The theme of current site, locked to a certain version.
|
||||||
|
gem "minima", "2.4.1"
|
||||||
|
|
||||||
|
# Plugins of this site loaded during a build with proper
|
||||||
|
# site configuration.
|
||||||
gem "jekyll-gist"
|
gem "jekyll-gist"
|
||||||
gem "jekyll-coffeescript"
|
gem "jekyll-coffeescript"
|
||||||
gem "jekyll-assets"
|
gem "jekyll-seo-tag", "~> 1.5"
|
||||||
gem "another-jekyll-plugin"
|
gem "some-other-jekyll-plugin"
|
||||||
end
|
|
||||||
|
# A dependency of a custom-plugin inside `_plugins` directory.
|
||||||
|
gem "nokogiri", "~> 1.11"
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you need to install all plugins from your Bundler group by running single command `bundle install`.
|
The gems listed in the Gemfile can be collectively installed by simply running `bundle install`.
|
||||||
|
|
||||||
|
### The `:jekyll_plugins` Gemfile group
|
||||||
|
{: #the-jekyll_plugins-group}
|
||||||
|
|
||||||
|
Jekyll gives a special treatment to gems listed as part of the `:jekyll_plugins` group in a Gemfile. Any gem under this group is loaded at
|
||||||
|
the very beginning of any Jekyll process, irrespective of the `--safe` CLI flag or entries in the configuration file(s).
|
||||||
|
|
||||||
|
While this route allows one to enhance Jekyll's CLI with additional subcommands and options, or avoid having to list gems in the configuration
|
||||||
|
file, the downside is the necessity to be mindful of what gems are included in the group. For example:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
# Use the latest version.
|
||||||
|
gem "jekyll"
|
||||||
|
|
||||||
|
# The theme of current site, locked to a certain version.
|
||||||
|
gem "minima", "2.4.1"
|
||||||
|
|
||||||
|
# Plugins of this site loaded only if configured correctly.
|
||||||
|
gem "jekyll-gist"
|
||||||
|
gem "jekyll-coffeescript"
|
||||||
|
|
||||||
|
# Gems loaded irrespective of site configuration.
|
||||||
|
group :jekyll_plugins do
|
||||||
|
gem "jekyll-cli-plus"
|
||||||
|
gem "jekyll-seo-tag", "~> 1.5"
|
||||||
|
gem "some-other-jekyll-plugin"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
<div class="note info">
|
<div class="note info">
|
||||||
<h5>Plugins on GitHub Pages</h5>
|
<h5>Plugins on GitHub Pages</h5>
|
||||||
<p>
|
<p>
|
||||||
<a href="https://pages.github.com/">GitHub Pages</a> is powered by Jekyll.
|
<a href="https://pages.github.com/">GitHub Pages</a> is powered by Jekyll. All GitHub Pages sites are generated using the
|
||||||
All Pages sites are generated using the <code>--safe</code> option
|
<code>--safe</code> option to disable plugins (with the exception of some
|
||||||
to disable plugins (with the exception of some
|
<a href="https://pages.github.com/versions">whitelisted plugins</a>) for security reasons. Unfortunately, this means your plugins won't
|
||||||
<a href="https://pages.github.com/versions">whitelisted plugins</a>) for
|
work if you’re deploying via GitHub Pages.<br><br>
|
||||||
security reasons. Unfortunately, this means
|
You can still use GitHub Pages to publish your site, but you’ll need to build the site locally and push the generated files to your
|
||||||
your plugins won’t work if you’re deploying to GitHub Pages.<br><br>
|
GitHub repository instead of the Jekyll source files.
|
||||||
You can still use GitHub Pages to publish your site, but you’ll need to
|
|
||||||
convert the site locally and push the generated static files to your GitHub
|
|
||||||
repository instead of the Jekyll source files.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<h5>
|
<h5>
|
||||||
<code>_plugins</code>, <code>_config.yml</code> and <code>Gemfile</code>
|
<code>_plugins</code>, <code>_config.yml</code> and <code>Gemfile</code> can be used simultaneously
|
||||||
can be used simultaneously
|
|
||||||
</h5>
|
</h5>
|
||||||
<p>
|
<p>
|
||||||
You may use any of the aforementioned plugin options simultaneously in the
|
You may use any of the aforementioned plugin routes simultaneously in the same site if you so choose.
|
||||||
same site if you so choose. Use of one does not restrict the use of the
|
Use of one does not restrict the use of the others.
|
||||||
others.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### The jekyll_plugins group
|
|
||||||
|
|
||||||
Jekyll gives this particular group of gems in your `Gemfile` a different
|
|
||||||
treatment. Any gem included in this group is loaded before Jekyll starts
|
|
||||||
processing the rest of your source directory.
|
|
||||||
|
|
||||||
A gem included here will be activated even if its not explicitly listed under
|
|
||||||
the `plugins:` key in your site's config file.
|
|
||||||
|
|
||||||
{: .note .warning}
|
|
||||||
Gems included in the <code>:jekyll-plugins</code> group are activated
|
|
||||||
regardless of the <code>--safe</code> mode setting. Be aware of which
|
|
||||||
gems are included under this group!
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue