A Jekyll plugin to make sure your post is really ready for publishing.
Add this line to your
group :jekyll_plugins do gem 'jekyll-pre-commit' end
Then execute the
bundle command to install the gem.
bundle exec jekyll pre-commit init in the root of your Jekyll site.
This will symlink this plugin's
pre-commit file to the
.git/hooks/ directory of your project.
If you provide the
--force flag when running
bundle exec jekyll pre-commit init any existing
pre-commit file will be deleted.
Once installed you may choose the pre-commit checks you would like to use by listing them in your site's
pre-commit: - check: FrontMatterVariableExists variables: ['description', 'image'] - check: FrontMatterVariableIsNotDuplicate variables: ['description'] - check: FrontMatterVariableMeetsLengthRequirements variables: ['description', 'title'] - check: NoDuplicateTags
This check ensures that any listed variables exist in the front matter of any post that is staged to be committed.
This check ensures that any listed variables are unique amongst all the posts on your site in the front matter of any post that is staged to be committed.
This check ensures that any listed variables meet the length requirements (in number of characters) in the front matter of any post that is staged to be committed.
This check includes the following defaults:
- max: 59
- min: 145
- max: 165
These can be overridden, or requirements can be specified for other variables in the following format...
- check: FrontMatterVariableMeetsLengthRequirements variables: ['title||50']
In the above, there would be a maximum length of 50 characters for the title (rather than the default of 59)
Checks that you have not accidentally introduced a duplicate tag. For example, if you have posts that are already using "MySQL" as a tag and you attempt to commit a post with the tag "mysql" (notice the difference in case-sensitivity) you will not be allowed to commit.
Roll Your Own
You can also add your own checks. To do so, create a class in the
Jekyll::PreCommit::Checks module and and define a
check method. Your class should extend the
Jekyll::PreCommit::Checks::Check class and return the
@result instance variable.
module Jekyll module PreCommit module Checks class DoesNothing < Check def check(staged, not_staged, site, args) @result end end end end end
Put this file in your plugins_path (which is _plugins by default) and
jekyll-pre-commit will load it automatically. Then just specify that you'd like to run this check in your front matter.
pre-commit: - check: DoesNothing
As you can probably tell by the name, this check doesn't actually do anything. Review the checks in
lib/jekyll-pre-commit/checks for some more useful examples.
Bug reports and pull requests are welcome on GitHub at https://github.com/mpchadwick/jekyll-pre-commit.
Please ensure tests pass (using rspec) before submitting a pull request and provide test coverage for any new features.
The gem is available as open source under the terms of the MIT License.