Visitar URL original
GitHub - carl-alberto/wp-to-contentful: Script to Migrate WordPress Posts to Contentful · GitHub
Skip to content

About

Script to Migrate WordPress Posts to Contentful

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

A script to migrate posts from WordPress to Contentful.

This is a script that will export all posts from WordPress using the Rest API and import them into Contentful using the Content Management API.

I've used this script for my own personal site and decided to share it and document my process used to develop it so people can learn from it. The basis of the script is intended to be expanded on for your own specifc purpose, but you can use the script as-is by modifying a few things.

Full write-up can be found here: https://ashcroft.dev/blog/script-migrate-wordpress-posts-contentful/

How to use the script

This script will run in the terminal via Node. You need to have npm installed.

Quick Setup

  1. Clone the repository

    git clone git@github.com:jonashcroft/wp-to-contentful.git
    cd wp-to-contentful
  2. Install dependencies

    npm install
  3. Set up configuration

    npm run setup
  4. Edit your configuration in relation to WP & Contentful

    In your Contentful admin panel:

    1. Go to Settings → API keys
    2. Create or select a Content Management API key
    3. Copy the Space ID and Content Management Token``
    4. Open config.js and update with: a. WordPress:
    • endpoint - Rest API endpoint of your WP site
    • importPostCount - Number of posts to be processed when running your migrat script

    b. Contentful:

  5. Customize field mapping (if needed)

 let fieldData = {
    id: postData.id,
    type: postData.type,
    postTitle: postData.title.rendered,
    slug: postData.slug,
    content: postData.content.rendered,
    publishDate: postData.date_gmt + '+00:00',
    featuredImage: postData.featured_media,
    tags: getPostLabels(postData.tags, 'tags'),
    categories: getPostLabels(postData.categories, 'categories'),
    contentImages: getPostBodyImages(postData)
 }
  1. Run the migration
    npm run migrate

Security Notes

  • Never commit sensitive credentials to version control
  • The config.js file is automatically excluded from git via .gitignore
  • Your Contentful access tokens provide full access to your space - keep them secure
  • Consider using environment variables in production environments

Configuration Files

This project uses config.js to store sensitive configuration data. The following files are included:

  • config.template.js - Template with example values (safe to commit)
  • config.js - Your actual configuration (excluded from git)
  • .env.example - Alternative environment variable setup (if you prefer .env files)

IMPORTANT: There is no sandbox or test environment with this script. If you run this script, it will immediately attempt to publish your new posts and assets - I am not responsible for anything that goes wrong.

About

Script to Migrate WordPress Posts to Contentful

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages