0.11.4 • Published 9 months ago

@tryghost/mg-wp-api v0.11.4

Weekly downloads
7
License
MIT
Repository
-
Last release
9 months ago

Migrate WP Api

Export content using the WordPress JSON API, and generate a zip file you can import into a Ghost installation.

Install

To install the CLI, which is required for the Usage commands below:

npm install --global @tryghost/migrate

To use this package in your own project:

npm install @tryghost/mg-wp-api --save

or

yarn add @tryghost/mg-wp-api

Usage

To run an absolute basic WordPress migration, the required command is this:

migrate wp-api --url https://example.com

It's possible to pass more options, in order to achieve a better migration file for Ghost:

  • --url (required)
    • Path to a WordPress site
    • string - default: false
  • -V --verbose
    • Show verbose output
    • bool - default: false
  • --zip
    • Create a zip file
    • bool - default: true
  • --onlyURLs
    • Path to a CSV file of post URLs that will be the only migrated posts
    • string - default: null
  • -s --scrape
    • Configure scraping tasks
    • string - default: all
    • Choices: all, img, web, media, files, none
  • --sizeLimit
    • number - default: false
    • Media files larger than this size (defined in MB i.e. 5) will be flagged as oversize
  • -I --info
    • bool - default: false
    • Show initalisation info only
  • -b --batch
    • number - default: 0
    • Batch number to run (defaults to running all)
  • -l --limit
    • number - default: 15
    • Number of items fetched in a batch i.e. batch size
  • -a --auth
    • string - default: null
    • Provide a user and password to authenticate the WordPress API (:)
  • -u --users
    • string - default: null
    • Provide a JSON file with users. Contents should be a JSON array of objects that match the format returned by the Wordpress API, including the following keys: "id", "slug", "name", "description", "email" and "url".
  • `--posts`**
    • boolean - default: true
    • Import posts
  • `--pages`**
    • boolean - default: true
    • Import pages
  • --tags
    • boolean - default: true
    • Set to false if you don't want to import WordPress tags, only categories
  • --addTag
    • string - default: null
    • Provide a tag slug which should be added to every post in this migration
  • --featureImage
    • Change which value is used as the feature image
    • string - default: featuredmedia
    • Choices: featuredmedia, og:image, none
  • --excerpt
    • bool - default: true
    • Use the excerpt value from WordPress API
  • --excerptSelector
    • string - default: null
    • Pass in a valid selector to grab a custom excerpt from the post content, e. g. h2.excerpt
  • --datedPermalinks
    • Set the dated permalink structure. /*/ matches any prefix, such as /articles/2018/05/ or /blog-posts/2018/05/
    • string - default: none
    • Choices: none, '/yyyy/mm/', '/yyyy/mm/dd/', '/*/yyyy/mm/', '/*/yyyy/mm/dd/'
    • NOTE: When using /*/, this is only to match existing links. Fixed links will not contain this.
  • --postsBefore
    • Only migrate posts before and including a given date e.g. 'March 20 2018'
    • string - default: null
  • --postsAfter
    • Only migrate posts after and including a given date e.g. 'August 16 2023'
    • string - default: null
  • --cpt
    • A comma-separated list of custom post type slugs e.g. resources,newsletters
    • array - default: null
  • --fallBackHTMLCard
    • Fall back to convert to HTMLCard, if standard Mobiledoc convert fails
    • bool - default: true
  • --removeSelectors
    • Pass in a string of CSS selectors for elements that will be removed, e.g. '.ads, script[src*="adnetwork.com"]'
    • string - default: null
  • --trustSelfSignedCert
    • Trust self-signed certificates (such as for local installs)
    • bool - default: false
  • --cache
    • Persist local cache after migration is complete (Only if --zip is true)
    • bool - default: true

A more realistic command for a WordPress migration looks like this:

migrate wp-api --url https://example.com --auth person:pa55w0rd --addTag 'From old site' --limit 10 --batch 5

This will fetch the newest 50 posts, in 5 batches of 10, collect real author data including email addresses), and add the tag 'From old site'.

migrate wp-api --url https://example.com --scrape img web

This will fetch all posts, and only scrape image & web meta data

Only get a specific set of posts:

migrate wp-api --url https://example.com --onlyURLs /path/to/urls.csv

The CSV should look like this:

url
https://example.com/2023/03/02/my-article
https://example.com/2023/03/01/another-article

Develop

This is a mono repository, managed with lerna.

Follow the instructions for the top-level repo. 1. git clone this repo & cd into it as usual 2. Run yarn to install top-level dependencies.

Run

To run a local development copy, cd into this directory, and use yarn dev instead of migrate like so:

yarn dev wp-api <url>

Test

  • yarn lint run just eslint
  • yarn test run lint and tests

Copyright & License

Copyright (c) 2013-2023 Ghost Foundation - Released under the MIT license.

0.11.3

9 months ago

0.11.4

9 months ago

0.11.1

9 months ago

0.11.2

9 months ago

0.11.0

10 months ago

0.10.38

10 months ago

0.10.37

10 months ago

0.10.36

10 months ago

0.10.35

11 months ago

0.10.33

11 months ago

0.10.34

11 months ago

0.10.32

1 year ago

0.10.30

1 year ago

0.10.31

1 year ago

0.10.29

1 year ago

0.10.28

2 years ago

0.10.27

2 years ago

0.10.26

2 years ago

0.10.25

2 years ago

0.10.23

2 years ago

0.10.24

2 years ago

0.10.22

2 years ago

0.10.21

2 years ago

0.10.18

2 years ago

0.10.19

2 years ago

0.10.15

2 years ago

0.10.16

2 years ago

0.10.17

2 years ago

0.10.20

2 years ago

0.10.14

2 years ago

0.10.11

3 years ago

0.10.12

3 years ago

0.10.13

3 years ago

0.10.10

3 years ago

0.10.9

3 years ago

0.10.2

3 years ago

0.10.3

3 years ago

0.10.4

3 years ago

0.10.5

3 years ago

0.10.6

3 years ago

0.10.7

3 years ago

0.10.8

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.8.8

3 years ago

0.8.7

3 years ago

0.8.6

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.7.11

3 years ago

0.7.10

3 years ago

0.7.9

3 years ago

0.7.12

3 years ago

0.7.8

3 years ago

0.7.7

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

5 years ago

0.4.15

5 years ago

0.4.14

5 years ago

0.4.13

5 years ago

0.4.12

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago