npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wordprismic

v0.5.1

Published

Import and transform Wordpress blogs to Prismic.io

Downloads

22

Readme

Wordprismic

npm

Wordprismic is a small and fully configurable Node utility for importing existing Wordpress blogs into the Prismic.io content platform.

Requirements

Make sure you meet the following requirements before using the importer:

  • Wordpress's REST API enabled (included and auto-enabled in core from WP 4.4+)
  • Both Node 7.6+ and Ruby installed
  • Any Wordpress plugins that add or change content models (eg: Advanced Custom Fields, YOAST, etc) hooked up to the REST API, via plugins or otherwise

Configuration

Create a JavaScript configuration file with the following properties

Property | Description ------------------------------------|---------------------------------------------------------------------------------------------------------------------------------- wordpress.url | The full URL of your wordpress blog prismic.repo | The name of your Prismic repository prismic.locale | The locale of language locale of your imported documents in Prismic (see Settings -> Translations & locales) prismic.categoriesType (optional) | The content type of post categories in prismic, if available optimizeMediaRequests (optional) | Whether to attempt to only fetch required media assets. Shortens import time, but can cause 503 errors on some Wordpress servers. schema | A function to transform Wordpress data to your Prismic content model, see documentation below

module.exports = {
  wordpress: {
    url: 'https://myblog.com'
  },
  prismic: {
    repo: 'myNewBlog',
    locale: 'en-au',
    categoriesType: 'category'
  },
  optimizeMediaRequests: false,
  schema: async function(post, html) {
    return {
      type: 'post',
      uid: post.slug,
      category: {
        id: post.categories[0].prismic.id,
        mask: 'category'
      },
      author: post.author.name,
      title: html.decode(post.title.rendered),
      featured_image: {
        origin: {
          url: post.featured_media.guid.rendered
        },
        alt: post.featured_media.alt_text
      },
      excerpt: await html.parse(post.excerpt.rendered),
      content: await html.parse(post.content.rendered)
    };
  }
};

Defining your schema

The config schema describes how your Wordpress posts map to your Prismic content model. It's written as a function that is given two paramaters:

  1. The imported post from Wordpress
  2. Helper functions html.parse(), which creates Prismic RichText objects out of HTML strings, and html.decode(), which decodes HTML strings with entities

See the Wordpress Posts API Reference for all properties available on the post object provided. However, the following properties on post have been changed by Wordprismic:

  • author is the full user object, rather than just the ID
  • featured_media is the media object object of the asset, rather than just the ID
  • Each item in categories has been populated with a matching Prismic category if it's available (from prismicCategories type in config) as follows: { wordpress: [category], prismic: [document] }

The html.parse() function is asynchronous, so make sure you await it and flag your schema as async.

Importing

You can now run the importer directly from NPM, with the following arguments

Argument | Description ------------------|------------------------------------------------------------------------- --config (-c) | Path to your config file --dest (-d) | Location to save zip archive for imorting, defaults to current directory

npx wordprismic -c ./path/to/config.js

Or if you'd prefer, install the module globally first

npm i -g wordprismic

wordprismic -c ./path/to/config.js

Your new Prismic posts will be saved to in a folder called wordprismic-import. Compress the contents (not the folder itself) to a .zip archive, then import it to Prismic.


© MIT Tomorrow