Post Organizer Utility

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.

🎯 Features

πŸ“ File Structure

scripts/development/content/
β”œβ”€β”€ organize-posts.py       # Main Python script
β”œβ”€β”€ organize-posts.sh       # Bash wrapper script
β”œβ”€β”€ requirements.txt        # Python dependencies
└── README.md              # This documentation

πŸš€ Quick Start

# 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

Using Python Directly

# Install dependencies
pip install -r scripts/development/content/requirements.txt

# Run the script
python3 scripts/development/content/organize-posts.py --dry-run

πŸ“‹ Requirements

πŸ› οΈ Usage Options

Bash Script Options

./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

Python Script Options

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

πŸ“Š How It Works

1. Frontmatter Analysis

The script analyzes each markdown file’s YAML frontmatter:

---
title: "My Blog Post"
section: technology
permalink: /posts/my-blog-post/
---

2. Section Validation

Validates the section field against your posts.yml configuration:

- title: Technology
  icon: tech
  url: /posts/tech/
- title: Business
  icon: cash
  url: /posts/business/

3. Slug Extraction

Extracts slug in this priority order:

  1. From permalink field (last segment)
  2. From explicit slug field
  3. Generated from title field
  4. Generated from filename (without date prefix)

4. File Organization

Moves 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

⚠️ File Processing Rules

Files are PROCESSED when they have:

Files are SKIPPED when they:

Error Handling:

πŸ“ Example Output

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']
============================================================

πŸ”§ Configuration

Posts Configuration File

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/

Custom Configuration

You can specify a custom config file:

./organize-posts.sh --config-file /path/to/custom-posts.yml

🚨 Safety Features

Dry Run Mode

Always test with --dry-run first:

./organize-posts.sh --dry-run

Backup Recommendation

Consider backing up your posts before running:

cp -r pages/_posts pages/_posts.backup

Logging

All operations are logged to post-organization.log for audit trails.

πŸ› Troubleshooting

Common Issues

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

Files Not Moving

Debug Steps

  1. Run with --dry-run to see what would happen
  2. Check the log file post-organization.log
  3. Verify your posts.yml configuration
  4. Test with a single file first

πŸ”„ Integration with IT-Journey Workflow

This utility is designed to work with the IT-Journey workflow:

  1. Content Creation: Authors create posts in pages/_posts/
  2. Organization: This script organizes them by section
  3. Publication: Jekyll builds the organized structure
  4. Maintenance: Regular organization keeps content structured

🀝 Contributing

To improve this utility:

  1. Test with various frontmatter configurations
  2. Add support for additional slug sources
  3. Enhance error handling and validation
  4. Add more configuration options

πŸ“„ License

This utility is part of the IT-Journey project and follows the same license terms.