A comprehensive utility to organize Jekyll markdown posts based on frontmatter metadata. This tool automatically sorts posts into subdirectories based on their section
field and renames them using their slug values.
section
frontmatterpermalink
, slug
, title
, or filenamescripts/development/content/
βββ organize-posts.py # Main Python script
βββ organize-posts.sh # Bash wrapper script
βββ requirements.txt # Python dependencies
βββ README.md # This documentation
# Navigate to the IT-Journey root directory
cd /path/to/it-journey
# Run with dry-run to preview changes
./scripts/development/content/organize-posts.sh --dry-run
# Run the actual organization
./scripts/development/content/organize-posts.sh
# Install dependencies
pip install -r scripts/development/content/requirements.txt
# Run the script
python3 scripts/development/content/organize-posts.py --dry-run
pip install pyyaml
)pages/_posts/
directory_data/navigation/posts.yml
./organize-posts.sh [OPTIONS]
OPTIONS:
-d, --posts-dir PATH Path to posts directory
-c, --config-file PATH Path to posts.yml config file
-n, --dry-run Preview changes without moving files
-i, --install-deps Install Python dependencies only
-h, --help Show help message
python3 organize-posts.py [OPTIONS]
OPTIONS:
--posts-dir PATH Path to posts directory (default: pages/_posts)
--config-file PATH Path to posts.yml configuration file
--dry-run Show what would be done without moving files
The script analyzes each markdown fileβs YAML frontmatter:
---
title: "My Blog Post"
section: technology
permalink: /posts/my-blog-post/
---
Validates the section
field against your posts.yml
configuration:
- title: Technology
icon: tech
url: /posts/tech/
- title: Business
icon: cash
url: /posts/business/
Extracts slug in this priority order:
permalink
field (last segment)slug
fieldtitle
fieldMoves files to structure like:
pages/_posts/
βββ technology/
β βββ my-tech-post.md
β βββ another-tech-post.md
βββ business/
β βββ business-strategy.md
β βββ market-analysis.md
βββ world/
βββ global-trends.md
section
field with a value matching posts.ymlsection
fieldpost-organization.log
2024-08-24 10:30:15 - INFO - Starting post organization in: /path/to/pages/_posts
2024-08-24 10:30:15 - INFO - Found 45 markdown files to process
2024-08-24 10:30:15 - INFO - Processing: 2021-10-27-build-die-repeat.md
2024-08-24 10:30:15 - INFO - Created/verified directory: /path/to/pages/_posts/technology
2024-08-24 10:30:15 - INFO - Moved: 2021-10-27-build-die-repeat.md -> /path/to/pages/_posts/technology/build-destroy-repeat-mastery.md
============================================================
POST ORGANIZATION SUMMARY
============================================================
Successfully processed: 38 files
β 2021-10-27-build-die-repeat.md -> technology/build-destroy-repeat-mastery.md
β 2023-03-17-penrose-triangle.md -> technology/penrose-triangle-impossible-geometry.md
Skipped: 7 files
β 2024-05-09-bootstrap-your-theme-and-character.md: No valid section found in frontmatter
Section value: 'None'
Valid sections: ['business', 'home', 'tech', 'technology', 'world']
============================================================
The script reads valid sections from your _data/navigation/posts.yml
:
- title: Home
icon: home
url: /posts/
- title: Technology
icon: tech
url: /posts/tech/
- title: Business
icon: cash
url: /posts/business/
- title: World
icon: world
url: /posts/world/
You can specify a custom config file:
./organize-posts.sh --config-file /path/to/custom-posts.yml
Always test with --dry-run
first:
./organize-posts.sh --dry-run
Consider backing up your posts before running:
cp -r pages/_posts pages/_posts.backup
All operations are logged to post-organization.log
for audit trails.
PyYAML Not Found
# Install the required dependency
pip install pyyaml
Permission Denied
# Make the script executable
chmod +x scripts/development/content/organize-posts.sh
Invalid Section Values
--dry-run
to see which sections are detectedFiles Not Moving
--dry-run
to see what would happenpost-organization.log
This utility is designed to work with the IT-Journey workflow:
pages/_posts/
To improve this utility:
This utility is part of the IT-Journey project and follows the same license terms.