This Ruby script is specifically designed for users working with WordPress markdown exports in a Windows Subsystem for Linux 2 (WSL2) environment. It converts exported WordPress markdown files (via Gatsby exporter) into Jekyll-ready blog post files while handling Windows and WSL2 path conversions seamlessly.
- Extracts YAML front matter
- Filters to specific allowed keys
- Adds 'layout: post'
- Cleans HTML content
- Renames files with date prefix
- Converts paths for WSL2 compatibility
- Automatically converts Windows paths (e.g.,
C:\path\to\files
) to WSL2 paths (e.g.,/mnt/c/path/to/files
) - Handles path separators (
\
to/
) - Supports mixed Windows and WSL2 path inputs
- Windows Subsystem for Linux 2 (WSL2)
- Ruby (version 3.0 or later recommended)
- Required gems:
- nokogiri
- fileutils
- cgi
- yaml
- date
- Ensure WSL2 is set up on your Windows machine
- Clone the repository in your WSL2 environment
- Install required gems:
gem install nokogiri fileutils
- Set your input and output directories in the script
- Works with both Windows-style paths (e.g.,
C:\path\to\input
) - Works with WSL2 paths (e.g.,
/mnt/c/path/to/input
)
- Works with both Windows-style paths (e.g.,
- Run the script:
ruby wpMdCleaner.rb
Modify these variables in the script:
input_directory
: Path to directory containing exported WordPress markdown filesoutput_directory
: Path where cleaned Jekyll-compatible files will be saved
The script automatically converts:
C:\Users\YourName\Documents\files
→/mnt/c/Users/YourName/Documents/files
D:\Blog\WordPress\exports
→/mnt/d/Blog/WordPress/exports
- title
- date
- status
- permalink
- author
- excerpt
- type
- id
- category
- tag
- layout
- Tested with WordPress exports via Gatsby exporter
- Works with Jekyll static site generator
- Fully compatible with WSL2 environments
Contributions are welcome! Please see CONTRIBUTING.md for details.
This software is licensed under the Standard MIT License.
- Ensure you're using absolute paths
- Double-check drive letter mapping in WSL2
- Verify file permissions in your WSL2 environment