Jekyll-ID adds ID support for jekyll markdown documents. These IDs do not change alongside document filenames, which make using the ID in a document's permalink
attribute more reliable.
Nanoid is used to validate ID format and generate IDs.
This gem is part of the jekyll-bonsai project. 🎋
Add this line to your application's Gemfile:
gem 'jekyll-id'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install jekyll-id
Defaults look like this:
ids:
enabled: true
exclude: []
enabled
: Set to false
to disable the plugin. (Toggle this off if you only want to use id
s in permalinks )
exclude
: jekyll document types to exclude from ids processing.
format
: set format parameters, available fields are alpha
and size
, see nanoid docs for details.
ids:
format:
alpha: '_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
size: 21
This plugin assumes all target markdown files contain frontmatter.
The plugin will check each markdown document's data attributes for an id
. If none exists, it will prompt the user to generate an ID for them:
// ID Generation
> Generate frontmatter ID for:
> <doc_info>
> with new ID: <new_id>
> Is that ok?
> (yes, no, yesall, or noall)
If yes
or yesall
is the response, the plugin will generate an ID and write it to the document's frontmatter in the markdown document.
If the format
fields have been filled out in the plugin's configuration, the plugin will not only scan for the existence of an id
, but it will check that the id
is of the correct format. The above logic still applies, but the plugin will also ask about ID replacement when it's of an incorrect format:
// ID Replacement
> Replace frontmatter for:
> <document_info>
> with ID: <current_id>
> with new ID: <new_id>
> Is that ok?
> (yes, no, yesall, or noall)
This plugin adds the ability to insert :id
into the configuration for frontmatter defaults:
# _config.yml
defaults:
-
scope:
type: "posts"
values:
permalink: "/post/:id/"
-
scope:
type: "entries"
values:
permalink: "/entry/:id/"
The jekyll core will not make (post) ids permanent: jekyll/jekyll#3725
Add support for GUIDs from ruby's built-in SecureRandom