Markdown Converter
Agent skill for markdown-converter
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Sign in to like and favorite skills
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Microblog-to-Hugo is a collection of Python 3 scripts for migrating and refactoring content from Micro.blog exports to Hugo static sites. The scripts handle frontmatter standardization, filename cleanup, slug generation, and image migration.
The repository implements a pipeline architecture where each script performs one specific transformation:
standardize_frontmatter.py) - Cleans TOML frontmattersimplify_filenames.py) - Removes date prefixes from filenamesadd_slugs.py or fix_slugs.py) - Generates URL-friendly slugsThe
migrate.py wrapper orchestrates these steps with safety checks and error handling.
migrate.py (wrapper) ├── standardize_frontmatter.py (always runs) ├── simplify_filenames.py (optional, --skip-filenames) └── add_slugs.py (optional, --skip-slugs) fix_slugs.py (standalone - regenerates all slugs) migrate_images.py (standalone - moves images to assets/)
File Processing Pattern: All scripts follow this structure:
+++ TOML delimiters (frontmatter vs body)Slug Generation Logic:
slugify(title)slugify(first_6_words_of_content)-2, -3, etc.Collision Detection: Scripts track used slugs/filenames in sets/dicts to prevent overwrites.
content/post/ for posts (configurable via post_dir variable)+++ delimiters.md)Note:
simplify_filenames.py has a discrepancy - it looks for content/posts/ and content/notes/ instead of content/post/. This may need adjustment based on actual site structure.
# One-command migration (recommended) python3 migrate.py # Full migration python3 migrate.py --dry-run # Preview only python3 migrate.py --skip-filenames # Skip filename cleanup python3 migrate.py --skip-slugs # Skip slug generation # Individual scripts (for granular control) python3 standardize_frontmatter.py python3 simplify_filenames.py python3 add_slugs.py python3 fix_slugs.py # Image migration python3 migrate_images.py # Migrate all images python3 migrate_images.py --dry-run # Preview changes python3 migrate_images.py --year 2024 # Migrate specific year
All scripts have shebang (
#!/usr/bin/env python3) and can be run directly:
chmod +x *.py ./migrate.py --dry-run
To use with different content directories, update the
post_dir variable in each script:
# Example from standardize_frontmatter.py post_dir = Path('content/post') # Change this path as needed
Key regex patterns used across scripts:
r'^\d{4}-\d{2}-\d{2}-(.+)$' (YYYY-MM-DD prefix)r'^field_name\s*=\s*"([^"]+)"' (MULTILINE)r'^title\s*=\s*""?\s*$'standardize_frontmatter.py performs these operations:
title, slug, summary fieldsdate = 2024-01-15... → date = "2024-01-15..."[ "foo" ] → ["foo"]
(incremental):add_slugs.py
(complete regeneration):fix_slugs.py
After running migration scripts:
# Review changes git diff # Test Hugo site builds successfully cd /path/to/hugo/site hugo server # Verify permalink structure works # Ensure hugo.toml has: [permalinks] post = "/:slug/"
migrate_images.py moves images from static/images/ to assets/images/ to enable Hugo's image processing (WebP conversion, responsive srcsets, lazy loading).
Important:
assets/images/ at /images/ URL path/images/2024/photo.jpgstatic/ (not processed)migrate.py --dry-run