Using Jekyll Compose Plugin
Info
The Jekyll Compose plugin makes it easy to create new drafts and posts using the CLI. The correct filename is automatically generated in the format YEAR-MONTH-DAY-POST-NAME.md
and the date is added to the front matter header. Drafts can also be created and then published as a post.
The following Jekyll Compose commands are available:
- draft # Creates a new draft post with the given NAME
- post # Creates a new post with the given NAME
- publish # Moves a draft into the _posts directory and sets the date
- unpublish # Moves a post back into the _drafts directory
- page # Creates a new page with the given NAME
- rename # Moves a draft to a given NAME and sets the title
- compose # Creates a new file with the given NAME
A complete Jekyll Compose command usually looks like this: bundle exec jekyll draft "New Draft"
Install and Configuration
Add jekyll-compose
to your Gemfile and then execute bundle
.
group :jekyll_plugins do
gem 'jekyll-compose'
end
And these entries are created in _config.yml
if you want to use a default front matter:
# Jekyll Compose default front matter example
jekyll_compose:
auto_open: true
default_front_matter:
posts:
author_name: m0x2A
modified:
tags: []
category: [linux, jekyll]
description:
published: false
sitemap: false
drafts:
author_name: m0x2A
modified:
category: []
tags: [linux, jekyll]
description:
When a draft is created, an option can also be added to the Jekyll config to have a default editor open the file immediately:
#auto-open new drafts or posts in your editor
jekyll_compose:
auto_open: true
To define the editor, just set an environment variable for EDITOR
, VISUAL
or JEKYLL_EDITOR
. As an example for VSCodium: export JEKYLL_EDITOR=codium
To set the variable permanently, it only needs to be set in the user’s shell config, in my case ~/.zshrc
, or globally in /etc/environment
. Then you have to restart the terminal session or run source ~/.zshrc
or source /etc/environemnt
.
I also created these command aliases in my .zshrc
:
#Jekyll Compose commands
alias jekyll-draft="bundle exec jekyll draft"
alias jekyll-publish="bundle exec jekyll publish"
alias jekyll-unpublish="bundle exec jekyll unpublish"
alias jekyll-post="bundle exec jekyll post"
alias jekyll-page="bundle exec jekyll page"
alias jekyll-rename="bundle exec jekyll rename"
Usage with my aliases
- Create your draft
jekyll-draft "My new draft"
- Rename your draft
jkyll-rename _drafts/my-new-draft.md "My Renamed Draft"
- Publish your draft
jekyll-publish _drafts/my-new-draft.md
- Create your post
jekyll-post "My New Post"
- Rename your post
jekyll-rename _posts/2024-07-01-my-new-draft.md "My New Post"
- Rename and specify a specific date
jekyll-rename _posts/2024-07-01-my-new-post.md "My Old Post" --date "2024-06-20"
- Rename and specify the current date
jekyll-rename _posts/2024-06-20-my-old-post.md "My New Post" --now
- Unpublish your post
jekyll-unpublish _posts/2024-07-01-my-new-draft.md
- Create new page
jekyll-page "My New Page"
With bundle exec jekyll help
you can review all the commands and options.