:point_right: Live demo: https://erikw.github.io/jekyll-glossary_tooltip/
This plugin simplifies for your readers and you by making it easy to define terms or abbreviations that needs an explanation. Define a common dictionary of terms and their definition in a YAML file. Then inside markdown files you can use the provided glossary liquid tag to insert a tooltip for a defined word from the dictionary. The tooltip will show the term definition on mouse hover.
It's also possible to provide an optional URL to for example a term definition source reference. To also support mobile devices, this URL link is placed inside the tooltip pop-up itself, rather than making the term itself clickable. This is so that on mobile device, you will first tap the word to get the hover tooltip, then click the link in the tooltip if desired.
:jekyll_plugins
group:bundle add --group jekyll_plugins jekyll-glossary_tooltip
group :jekyll_plugins do
[...]
gem 'jekyll-glossary_tooltip'
end
$ bundle install
._config.yml
, enable the plugin:plugins:
- jekyll-glossary_tooltip
_data/glossary.yml
file, according to the 'Glossary Term Definition File' section below, with your terms.{% glossary term_name %}
assets/css/
directory 2) editing your theme's template for blog posts (or what pages you desire) to include this CSS in the header like <link rel="stylesheet" href="/assets/css/jekyll-glossary_tooltip.css">
. However you could also copy this file's content in to your main.css
or main.scss
or however you build your site's CSS.bundle exec jekyll build
Create a file _data/glossary.yml
to host your shared term definition entries. This file should contain a list of term entries in the format of:
- term: a_term_name # Can contain spaces
definition: A description of the term
url: https://jekyllrb.com/ # Is optional
- term: another term
definition: Some other term definition text
This could look something like:
- term: Jekyll
definition: A Static Site Generator (SSG) built with ruby. Widely adopted as of GitHub Pages inclusion.
url: https://jekyllrb.com/
- term: SSG
definition: A Static Site Generator compiles the website before deployment. Then the generated web content is simply retrieved as-is by the client without any code running at retrieve time.
- term: Jamstack
definition: JavaScript + API + Markup - a way of buildin and hosting websites.
url: https://jamstack.org/
- term: EmbeddedLiquidURL
definition: This definition has an URL with embedded liquid tags to make it dynamic at build time. Note special YAML syntax for being able to use liquid (1.)
url: >
{{ site.baseurl }}{% link page2.md %}
On any page where you've made sure include the needed CSS styling, you can use the glossary tag simply like
Here I'm talking about {% glossary term_name %} in a blog post.
The term name can contain spaces like {% glossary operating system %}.
Even if the term is defined in _data/glossary.yml as 'term_name', the matching is case-insensitive meaning that I can look it up using {% glossary TeRM_NaME %}. Note that the term is displayed as defined in the tag rather than the definition, here meaing 'TeRM_NaME'.
The case-styling above works as there's still a case-insensitive match. But what about when you actually want to dispaly the term differently? Maybe the term is defined as "cat" but you want to use the plural "cats"? Then you can supply an optional `display` argument. The syntax is:
{% glossary <term>, display: <diplay name> %}
This could be e.g.
{% glossary cat, display: cats %}
{% glossary some term, display: some other display text %}
Note that a term name can not contain a ,
, as this is the argument separator character.
Simply modify the rules jekyll-glossary_tooltip.css that you copied to your project. The tooltip is based on this tutorial. View the generated HTML output to see the HTML tags that are styled, or check the tag.rb implementation in the method render()
.
The structure of this plugin was inspired by https://ayastreb.me/writing-a-jekyll-plugin/, the plugin jekyll-sitemap and the Bundler Gem tutorial.
After checking out the repo;
script/setup
to install dependenciesscript/test
to run the testsscript/console
for an interactive prompt that will allow you to experiment.To install this gem onto your local machine, run bundle exec rake install
.
Following the setup at how-to-specify-local-ruby-gems-in-your-gemfile, these are the steps needed to build a jekyll site with a local clone of this plugin for local testing.
~/src/jekyll-glossary_tooltip
Gemfile
:gem 'jekyll-glossary_tooltip'
partgem 'jekyll-glossary_tooltip', github: 'erikw/jekyll-glossary_tooltip', branch: 'main'
$ bundle config --local local.jekyll-glossary_tooltip ~/src/jekyll-glossary_tooltip
$ bundle install
bundle exec jekyll build
$ bundle config --delete local.jekyll-glossary_tooltip
Gemfile
or keep building from a branch in the github repo.Instructions for releasing on rubygems.org below. Optionally make a GitHub release after this for the pushed git tag.
Following instructions from bundler.io:
vi -p lib/jekyll-glossary_tooltip/version.rb CHANGELOG.md
bundle exec rake build
ver=$(ruby -r ./lib/jekyll-glossary_tooltip/version.rb -e 'puts Jekyll::GlossaryTooltip::VERSION')
# Optional: test locally by including in another project
gem install pkg/jekyll-glossary_tooltip-$ver.gem
bundle exec rake release
Using gem-release:
vi CHANGELOG.md && git add CHANGELOG.md && git commit -m "Update CHANGELOG.md" && git push
gem bump --version minor --tag --push --release --sign
For --version
, use major|minor|patch
as needed.
.gemspec
.Appraisals
to generate different gemfiles/
BUNDLE_GEMFILE=gemfiles/jekyll_4.x.x.gemfile bundle exec rake spec
bundle exec appraisal jekyll-4.x.x rake spec
rake spec
for all gemfiles:bundle exec appraisal rake spec
Appraisals
bundle exec appraisal install
bundle exec appraisal generate --travis
To use the travis cli client (installed from Gemfile
):
travis-cli
repo
, read:org
, user:email
according to the docs.--pro
to most commandsbundle exec travis endpoint --set-default --api-endpoint https://api.travis-ci.com/
bundle exec travis login --github-token $GITHUB_TOKEN
--pro
to use travis.com)bundle exec travis lint
bundle exec travis accounts
bundle exec travis status
bundle exec travis branches
bundle exec travis monitor
The live demo source is in the branch gh-pages-source
. Check its README.md
!
Bug reports and pull requests are welcome on GitHub at https://github.com/erikw/jekyll-glossary_tooltip.
The gem is available as open source under the terms of the MIT License.
Thanks to ayastreb/jekyll-maps for inspiration on project structure and options parsing!
Check out my other Jekyll repositories here.