GithubHelp home page GithubHelp logo

juliencrn / wordpress-to-ndjson Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 197 KB

CLI tool that fetch WordPress data to produce ndjson files for sanity.io importation

JavaScript 14.13% TypeScript 85.87%
minimist cli nodejs typescript wordpress sanity-io ndjson

wordpress-to-ndjson's Introduction

WordPress to NDJSON formatter

Simple NodeJS CLI-Application that fetch and format data from WordPress, and create NDJSON output to import it in Sanity.io CMS.

Getting started

Download and install the repository locally

git clone wordpress-to-ndjson https://github.com/Junscuzzy/wordpress-to-ndjson
cd wordpress-to-ndjson
npm install

Then run

npm run dev --url https://your-wordpress-site.com

Output format

This script makes a *.ndjson files for the following schema:

// studio/schemas/documents/post.js

export default {
    name: 'post',
    type: 'document',
    title: 'Blog posts',
    fields: [
        {
            name: 'title',
            type: 'string',
            title: 'Title',
        },
        {
            name: 'slug',
            type: 'slug',
            title: 'Slug',
            options: {
            source: 'title',
                maxLength: 96
            }
        },
        {
            name: 'mainImage',
            type: 'mainImage',
            title: 'Main image'
        },
        {
            name: 'excerpt',
            type: 'text',
            rows: 4,
            title: 'Excerpt',
        },
        {
            name: 'categories',
            type: 'array',
            title: 'Categories',
            of: [
                {
                    type: 'reference',
                    to: {
                        type: 'category'
                    }
                }
            ]
        },
        {
            name: 'body',
            type: 'bodyPortableText',
            title: 'Body text'
        }
    ]
}

// studio/schemas/documents/category.js

export default {
    name: 'category',
    type: 'document',
    title: 'Categories',
    fields: [
        {
            name: 'title',
            type: 'string',
            title: 'Title'
        },
        {
            name: 'slug',
            type: 'slug',
            title: 'Slug',
            options: {
                source: 'title',
                maxLength: 96
            }
        },
        {
            name: 'description',
            type: 'text',
            title: 'Description'
        }
    ]
}

Evolution

Actually, your can only fetch posts and post categories. If you want edit the formatting schema or add entities:

  1. Update the Typescript interface model in src/interfaces/{post-type}.ts
  2. Update the formatter following typescript support in src/models/{post-type}.ts
  3. If necessary, edit the index file named src/bin/cli.ts.

You can copy this repository and adapt this following your business logic or submit a PR ;).

To-do

  • CPT support
  • ACF support
  • Custom sanity.io output format
  • Use wp-api instead REST API
  • Authenticated connection to wordPress
  • Add unit tests

License

Un-licensed, you can use, copy, edit, share (...) as you want without credit or permission.

wordpress-to-ndjson's People

Contributors

juliencrn avatar

Watchers

 avatar

Forkers

thewinger

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.