This is a script that imports WordPress posts and their images to Markdown files.
It will also export authors, categories and tags to JSON files. These will be linked to the exported posts.
This is a fork of Alex Seifert's export-wordpress-to-markdown with added frontmatter support.
- Adds YAML frontmatter to each exported post with:
- id: post slug
- title: post title
- status: publish status
- author: author name
- authorSlug: author's URL slug
- titleImage: featured image filename
- categorySlug: primary category URL slug
- category: primary category name
- publishedDate: original publish date
- updatedAt: last modified date
- wordpressId: original WordPress post ID
The script requires Node.js 18+ (lower versions might work, but aren't tested).
- Clone this repository
- Run
npm install
- Create a
config.mjs
file with your settings:
export const config = {
apiUrl: "https://your-wordpress-site.com/wp-json/wp/v2/",
dataDirectory: "data",
postsLimit: 0, // 0 for all posts, or number for testing
showTags: false, // true to include tags in frontmatter
turndownOptions: {
bulletListMarker: "-",
codeBlockStyle: "fenced",
emDelimiter: "*"
}
};
- Run
npm start
The script creates a data
folder with:
data/
βββ authors/
β βββ authors.json # Author information
βββ categories.json # Category information
βββ posts/
βββ post-slug/
βββ index.md # Post content with frontmatter
βββ images/ # Downloaded images
- Downloads all posts with pagination support
- Preserves images and updates their paths
- Converts HTML to Markdown
- Maintains author and category relationships
- Handles special content (polls, embedded content)
- Retries failed downloads automatically
apiUrl
: Your WordPress site's REST API URLdataDirectory
: Where to save exported contentpostsLimit
: Number of posts to export (0 for all)showTags
: Include tags in post frontmatterturndownOptions
: HTML to Markdown conversion settings
See the original author's blog post about this script: A Script for Exporting WordPress to Markdown
Original script by Alex Seifert
Frontmatter additions by Michael Allen Smith