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

wxr

v0.1.2

Published

WP Import WXR-file generator for Node.js

Downloads

52

Readme

node-wxr

Docman GitHub issues Docman GitHub forks Docman GitHub stars Docman GitHub license

XML (WXR) file generator for official Wordpress Import Plugin. Add categories and posts in clean readable way, and then serialize it into Wordpress Import XML file.

Install

npm install wxr

Usage

var Importer = require('wxr')
var importer = new Importer()

importer.addCategory({
  slug : "perfect-category",
  title: "Perfect Category"
})

importer.addPost({
  title         : "Hello, world!",
  contentEncoded: "<p>Hey, this is my post</p><p>BTW, cats are awesome!</p>",
  excerptEncoded: "Cool preview for my post. Check it out!",
  categories    : [
    {
      slug : "perfect-category",
      title: "Perfect Category"
    }
  ]
})

importer.addAttachment({
  id            : 15,
  date          : "2015-10-05 00:27:25",
  title         : "Fig. 1. Cats and puppies",
  author        : "admin",
  description   : "Fig. 1. Cats and puppies",
  excerptEncoded: "Fig. 1. Cats and puppies",
  status        : "inherit",
  parent        : 0,
  attachmentURL : "https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg"
})

console.log(importer.stringify());

Outputs:

<?xml version="1.0"?>
<rss xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.2/" version="2.0">
    <channel>
        <wp:wxr_version>1.2</wp:wxr_version>
        <wp:category>
            <wp:term_id>72583</wp:term_id>
            <wp:category_nicename>perfect-category</wp:category_nicename>
            <wp:cat_name>
                <![CDATA[Perfect Category]]>
            </wp:cat_name>
        </wp:category>
        <item>
            <wp:post_id>14455</wp:post_id>
            <title>Hello, world!</title>
            <wp:post_name/>
            <description>Default description for post</description>
            <wp:post_date>Thu Jul 23 2015 13:57:10 GMT+0000 (UTC)</wp:post_date>
            <wp:status>publish</wp:status>
            <wp:post_parent>0</wp:post_parent>
            <wp:post_type>post</wp:post_type>
            <dc:creator>
                <![CDATA[admin]]>
            </dc:creator>
            <content:encoded>
                <![CDATA[<p>Hey, this is my post</p><p>BTW, cats are awesome!</p>]]>
            </content:encoded>
            <excerpt:encoded>
                <![CDATA[Cool preview for my post. Check it out!]]>
            </excerpt:encoded>
            <category domain="category" nicename="perfect-category">
                <![CDATA[Perfect Category]]>
            </category>
            <category domain="category" nicename="bad-category">
                <![CDATA[Bad Category]]>
            </category>
        </item>
        <item>
            <wp:post_id>15</wp:post_id>
            <wp:post_date>Thu Jul 23 2015 13:57:10 GMT+0000 (UTC)</wp:post_date>
            <title>Fig. 1. Cats and puppies</title>
            <dc:creator>
                <![CDATA[admin]]>
            </dc:creator>
            <description>Fig. 1. Cats and puppies</description>
            <excerpt:encoded>
                <![CDATA[Fig. 1. Cats and puppies]]>
            </excerpt:encoded>
            <wp:status>inherit</wp:status>
            <wp:post_parent>0</wp:post_parent>
            <wp:post_type>attachment</wp:post_type>
            <wp:attachment_url>https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg</wp:attachment_url>
        </item>
    </channel>
</rss>

API

new Importer()

Returns a new instance of Importer.

Example

var Importer = require('wxr');
var importer = new Importer();

// importer.addPost(...)

addCategory(options)

Adds new category for Importer object.

  • options json:
    • id integer: category ID. If not provided, random ID will be generated. E.g. 5
    • slug string: category slug. Used in URLS, e. g. "js-rocks"
    • title string: category title, ex. "Everything about JS"

Example

importer.addCategory({
  id: 5,
  title: "Everything about JS",
  slug: "js-rocks"
})

addPost(options)

Adds new post for Importer object.

  • options json:
    • id integer: post ID. If not provided, random ID will be generated. E.g. 10
    • title string: post title, ex. "Why JS is so awesome"
    • name string: post name (slug). Used in URLS, e. g. "why-js-is-so-awesome"
    • description string: post description, e.g. "Quick tips about JS"
    • date date string: post date, e.g. "2015-10-05 00:27:25"
    • status string: post status, e.g. "publish"
    • author string: post aurhor, username. Will be created during import or assigned to existing user. E.g. "admin"
    • contentEncoded string: post content HTML, e.g. <p>Hey, this is my post\</p><p>BTW, cats are awesome!</p>
    • excerptEncoded string: post excerpt, e.g. "Cool preview for my post. Check it out!"
    • categories array: post catgories array, where each object is JSON object with:
      • slug string: category slug. Used in URLS, e. g. "js-rocks"
      • title string: category title, ex. "Everything about JS"

Example

importer.addPost({
  id            : 10,
  title         : "Why JS is so awesome",
  name          : "why-js-is-so-awesome",
  description   : "Quick tips about JS",
  date          : "2015-10-05 00:27:25",
  status        : "publish",
  author        : "admin",
  contentEncoded: "<p>Hey, this is my post</p><p>BTW, cats are awesome!</p>",
  excerptEncoded: "Cool preview for my post. Check it out!",
  categories    : [
    {
      title: "Everything about JS",
      slug: "js-rocks"
    }
  ]
})

addAttachment(options)

Adds new attachment (image) for Importer instance.

  • options json:
    • id integer: attachment ID. If not provided, random ID will be generated. E.g. 15
    • date date string: attachment date, e.g. "2015-10-05 00:27:25"
    • title string: attachment caption, ex. "Fig. 1. Cats and puppies"
    • author string: attachment author (username). Will be created during import or assigned to existing user. E.g. "admin"
    • description string: attachment description, e.g. "Fig. 1. Cats and puppies"
    • excerptEncoded string: attachment excerpt, e.g. "Fig. 1. Cats and puppies"
    • status string: attachment status, e.g. "inherit"
    • parent integer: parent post ID. If not provided, will be 0
    • attachmentURL string: attachment URL, e.g. https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg

Example

importer.addAttachment({
  id            : 5,
  dat           : "2015-10-05 00:27:25",
  title         : "Fig. 1. Cats and puppies",
  author        : "admin",
  description   : "Fig. 1. Cats and puppies",
  excerptEncoded: "Fig. 1. Cats and puppies",
  status        : "inherit",
  parent        : 0,
  attachmentURL : "https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg"
})

stringify()

Generates result XML (WXR) string for importing to Wordpress.

Example

var importer = new Importer();

// importer.addPost(...)

var xmlString = importer.stringify();
require("fs").writeFile("export.xml", xmlString, function(err) {
  if (err) {
    console.log(err);
  }

  console.log("File was saved! Now it's time to import.")
});

License

Copyright (c) 2015, Ilya Rusanen. (MIT License)

See LICENSE for more info.