Developing plugin for Jekyll
Abstract
Operational notes on developing/refactoring plugin for Jekyll blog. Given example is based on jekyll-seo-tag plugins refactoring.
Methodology:
Download locally forked version of plugin repository or create a new one:
https://github.com/jekyll/jekyll-seo-tag
Apply locally changes/develop:
Here, we want Abstract
keyword to be removed from page description when generating the SEO metadata, cause every post/article has standard structure and is started with Abstract section. But in SEO metadata we want only generic description to be present.
1
2
3
4
5
6
7
def description
@description ||= begin
data = format_string(page["description"] || page["excerpt"]) || site_description
data = data.delete_prefix("Abstract ")
data
end
end
One more example is changing the priority of different images for generating meta head tags.
1
2
3
4
5
def raw_path
@raw_path ||= begin
image_hash["twitter"] || image_hash["facebook"] || image_hash["path"]
end
end
If twitter property of image will be present in blog post declaration than twitter image path will have higher priority when generating Open Graph meta tag:
1
2
3
image:
path: /images/banners/1200/xray-banner.jpg
twitter: /images/banners/twitter/banner-xray-1.png
1
2
<meta property="twitter:image" content="https://tsypuk.github.io/images/banners/twitter/banner-xray-2.png">
<meta property="og:image" content="https://tsypuk.github.io/images/banners/twitter/banner-xray-2.png">
Build plugin:
In plugin repo run build command.
1
bundle exec gem build jekyll-seo-tag.gemspec
Update Jekyll Blog repo to use updated local plugin
1
gem 'jekyll-seo-tag', ">= 2.8.1"
Install plugin from local path:
Run gem install
by providing path to plugin repository folder.
1
gem install --local ~/jekyll-seo-tag/jekyll-seo-tag-2.8.1.gem