Files
wordpress-export-to-markdown/README.md
T

151 lines
5.3 KiB
Markdown
Raw Normal View History

2018-10-25 17:09:16 -04:00
# wordpress-export-to-markdown
2018-10-14 18:46:24 -04:00
2024-02-28 09:36:40 -05:00
Converts a WordPress export file into Markdown files that are compatible with static site generators ([Eleventy](https://www.11ty.dev/), [Gatsby](https://www.gatsbyjs.org/), [Hugo](https://gohugo.io/), etc.).
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
Each post is saved as a separate Markdown file with frontmatter. Images are downloaded and saved.
2018-10-26 16:07:22 -04:00
2020-01-19 13:24:13 -05:00
![wordpress-export-to-markdown running in a terminal](https://user-images.githubusercontent.com/1245573/72686026-3aa04280-3abe-11ea-92c1-d756a24657dd.gif)
2018-10-25 17:09:16 -04:00
## Quick Start
2018-12-12 16:28:15 -05:00
You'll need:
2024-02-28 09:36:40 -05:00
- [Node.js](https://nodejs.org/) installed
- Your [WordPress export file](https://wordpress.org/support/article/tools-export-screen/) (be sure to export "All content").
2020-01-18 16:18:48 -05:00
2024-02-28 09:36:40 -05:00
To make things easier, you can rename your WordPress export file to `export.xml` and drop it into the same directory that you run this script from.
2018-10-25 17:09:16 -04:00
2020-01-18 14:57:18 -05:00
You can run this script immediately in your terminal with `npx`:
2018-10-25 17:09:16 -04:00
2020-01-18 14:57:18 -05:00
```
npx wordpress-export-to-markdown
```
2018-10-25 17:09:16 -04:00
2024-02-28 09:36:40 -05:00
Or you can clone this repo, then from within the repo's directory, install and run:
2018-10-25 17:09:16 -04:00
```
2020-01-18 16:18:48 -05:00
npm install && node index.js
2018-10-25 17:09:16 -04:00
```
2024-02-28 09:36:40 -05:00
Either way, the script will start a wizard to configure your options. Answer the questions and off you go!
2020-01-18 14:57:18 -05:00
## Command Line
2024-02-28 09:36:40 -05:00
Options can also be configured via the command line. The wizard will skip asking about any such options. For example, the following will give you [Jekyll](https://jekyllrb.com/)-style output in terms of folder structure and filenames.
2020-01-18 14:57:18 -05:00
Using `npx`:
2020-01-14 13:56:28 -05:00
```
2020-01-18 14:57:18 -05:00
npx wordpress-export-to-markdown --post-folders=false --prefix-date=true
2020-01-14 13:56:28 -05:00
```
2020-01-18 14:57:18 -05:00
Using a locally cloned repo:
2020-01-14 13:56:28 -05:00
```
2020-01-18 14:57:18 -05:00
node index.js --post-folders=false --prefix-date=true
2020-01-14 13:56:28 -05:00
```
2024-02-28 09:36:40 -05:00
The wizard will still ask you about any options not specified on the command line. To skip the wizard entirely and use default values for unspecified options, add `--wizard=false`.
2020-01-18 14:57:18 -05:00
2020-01-14 13:56:28 -05:00
## Options
2020-01-18 16:18:48 -05:00
### Path to WordPress export file?
2020-01-14 13:56:28 -05:00
2024-02-28 13:20:32 -05:00
**Command line:** `--input=export.xml`
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
The path to your WordPress export file. To make things easier, you can rename your WordPress export file to `export.xml` and drop it into the same directory that you run this script from.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Path to output folder?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--output=output`
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
The path to the output directory where Markdown and image files will be saved. If it does not exist, it will be created.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Create year folders?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--year-folders=false`
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
Whether or not to organize output files into folders by year.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Create month folders?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--month-folders=false`
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
Whether or not to organize output files into folders by month. You'll probably want to combine this with `--year-folders` to organize files by year then month.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Create a folder for each post?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--post-folders=true`
2018-10-25 17:09:16 -04:00
Whether or not to save files and images into post folders.
If `true`, the post slug is used for the folder name and the post's Markdown file is named `index.md`. Each post folder will have its own `/images` folder.
2020-01-14 13:56:28 -05:00
/first-post
/images
potato.png
index.md
/second-post
/images
carrot.jpg
celery.jpg
index.md
2018-10-25 17:09:16 -04:00
If `false`, the post slug is used to name the post's Markdown file. These files will be side-by-side and images will go into a shared `/images` folder.
2020-01-14 13:56:28 -05:00
/images
carrot.jpg
celery.jpg
potato.png
first-post.md
second-post.md
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
Either way, this can be combined with with `--year-folders` and `--month-folders`, in which case the above output will be organized under the appropriate year and month folders.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Prefix post folders/files with date?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--prefix-date=false`
2018-10-25 17:09:16 -04:00
Whether or not to prepend the post date to the post slug when naming a post's folder or file.
2020-01-14 13:56:28 -05:00
If `--post-folders` is `true`, this affects the folder.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
/2019-10-14-first-post
index.md
/2019-10-23-second-post
index.md
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
If `--post-folders` is `false`, this affects the file.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
2019-10-14-first-post.md
2019-10-23-second-post.md
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Save images attached to posts?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--save-attached-images=true`
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
Whether or not to download and save images attached to posts. Generally speaking, these are images that were uploaded by using **Add Media** or **Set Featured Image** in WordPress. Images are saved into `/images`.
2018-10-25 17:09:16 -04:00
2020-01-14 13:56:28 -05:00
### Save images scraped from post body content?
2018-10-25 17:09:16 -04:00
2024-02-28 13:20:32 -05:00
**Command line:** `--save-scraped-images=true`
2018-10-25 17:09:16 -04:00
Whether or not to download and save images scraped from `<img>` tags in post body content. Images are saved into `/images`. The `<img>` tags are updated to point to where the images are saved.
### Include custom post types and pages?
2024-02-28 13:20:32 -05:00
**Command line:** `--include-other-types=false`
2024-02-28 13:20:32 -05:00
Some WordPress sites make use of a `"page"` post type and/or custom post types. Set this to `true` to include these post types in the output. Posts will be organized into post type folders.
### Use wizard?
**Command line:** `--wizard=true`
Enable to have the script prompt you for each option. Disable to skip the wizard and use default values for any options not specified via the command line.
2020-12-22 10:43:14 -05:00
## Advanced Settings
2024-02-23 17:44:03 -05:00
You can edit [settings.js](https://github.com/lonekorean/wordpress-export-to-markdown/blob/master/src/settings.js) to tweak advanced settings. This includes things like customizing frontmatter fields and throttling image downloads.
2020-12-22 10:43:14 -05:00
You'll need to run the script locally (not using `npx`) to make use of advanced settings.