This repository contains a collection of tools to assist with managing Jekyll projects. These tools are designed to automate one-off tasks when working with Jekyll sites; generally when migrating or making changes to site layout.
- Python 3.6 or higher
-
Clone or download this repository to your local machine.
-
Ensure you have Python installed on your system.
-
Run the provided
setup.shscript to set up a virtual environment and install dependencies:./setup.sh
This script will:
- Create a virtual environment in the
venvdirectory. - Install the required dependencies inside the virtual environment.
- Create a virtual environment in the
-
Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate - On Windows:
venv\Scripts\activate
Once activated, you can run the scripts with all dependencies properly configured.
- On macOS/Linux:
This script is designed to add redirect_from entries to the front matter of Jekyll posts based on the current permalink format defined in the site's _config.yml.
-
Navigate to the directory containing the script:
cd jekyll-tools -
Backup your
_postsdirectory: Before running the script, create a backup of your_postsdirectory to avoid accidental data loss, as the script modifies files in place. -
Run the script with the path to your Jekyll site directory:
python add_redirects.py /path/to/your/jekyll/site
Replace
/path/to/your/jekyll/sitewith the actual path to your Jekyll site directory. -
When finished, deactivate the virtual environment:
deactivate
- The script reads the
_config.ymlfile in your Jekyll site directory to determine the permalink format. - It scans all Markdown files in the
_postsdirectory. - For each post, it generates the current permalink based on the format and adds it to the
redirect_fromfield in the front matter if it is not already present.
Given a _config.yml file with the following permalink format:
permalink: /:year/:month/:title/And a post file named 2023-10-01-example-post.md with the following front matter:
---
title: Example Post
categories: blog
---The script will add the following redirect_from entry:
---
title: Example Post
categories: blog
redirect_from:
- /2023/10/example-post/
---- The script assumes that post filenames follow the
YYYY-MM-DD-title.mdformat. - Existing
redirect_fromentries will not be duplicated. - Backup your
_postsdirectory before running the script, as it modifies files in place.
This script adds a link_category front matter entry to all posts in the _posts directory of a Jekyll site. The value is set to the first category in the categories list if it exists and link_category is not already set.
The link_category can then be used to include a single category in a post's permalink, rather than including all categories as jekyll does when using categories.
-
Navigate to the directory containing the script:
cd jekyll-tools -
Backup your
_postsdirectory: Before running the script, create a backup of your_postsdirectory to avoid accidental data loss, as the script modifies files in place. -
Run the script with the path to your Jekyll site directory:
python set_link_category.py /path/to/your/jekyll/site
Replace
/path/to/your/jekyll/sitewith the actual path to your Jekyll site directory. -
When finished, deactivate the virtual environment:
deactivate
- The script scans all Markdown files in the
_postsdirectory. - For each post, it checks if the front matter contains a
categorieslist. - If a
categorieslist exists, it sets thelink_categoryfield to the first category in the list, providedlink_categoryis not already set.
Given a post file named 2023-10-01-example-post.md with the following front matter:
---
title: Example Post
categories:
- blog
- tutorials
---The script will add the following link_category entry:
---
title: Example Post
categories:
- blog
- tutorials
link_category: blog
---- Posts without a
categorieslist or with an emptycategorieslist will be skipped. - Existing
link_categoryentries will not be overwritten. - Backup your
_postsdirectory before running the script, as it modifies files in place.
This project is licensed under the MIT License. See the LICENSE file for details.