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

mrs-wxr-generator

v0.3.6

Published

XML(WXR) file generator for fully support official WordPress Import Plugin with Custom Post Meta.

Downloads

9

Readme

mrs-wxr-generator

npm license

XML(WXR) file generator for fully support official WordPress Import Plugin. Inspired By node-wxr and wxr-generator.

Install

npm install mrs-wxr-generator

How To Use

var Importer = require("mrs-wxr-generator")
var importer = new Importer()

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

console.log(importer.stringify())

API

new Importer(options)

Returns a new instance of Importer.

  • options:
    • name: site name
    • url: site url
    • description: site description
    • language: site language, default is en-US
    • base_site_url: same as url
    • base_blog_url: same as url

Example

var Importer = require("mrs-wxr-generator")
var importer = new Importer({
  name: "another wordpress blog",
  url: "http://test.wordpress.com",
  description: "this is another wordpress blog test",
  language: "en-US",
})

// importer.addPost(...)

addPost(options)

Adds new post for Importer object.

  • options:
    • id: post Id, if not provied, random ID will be generated.
    • url: post permalink url.
    • slug: post slug name if it exists.
    • date: post create time.
    • title: post title.
    • author: post author, it equals author's login name.
    • content: post content
    • summary: post summary
    • comment_status: post comment status, default is open, it can be open or closed.
    • ping_status: post ping status, default is open, it can be open or closed.
    • password: post visit password if it should, default is empty.
    • categories: post categories, it's an array item. Every item should has slug and name prototype.
    • tags: post tags, it's an array item. Every item should has slug and name prototype.
    • image: id of attached image to use as featured image for this post

Example

importer.addPost({
  id: 1,
  title: "hello world",
  url: "http://localhost/hello-world.html",
  slug: "hello-world",
  date: "2017-07-03 10:00:00",
  author: "admin",
  content:
    "Welcome to WordPress. This is your first post. Edit or delete it, then start writing!",
  summary: "Welcome",
  comment_status: "open",
  ping_status: "closed",
  password: "",
  categories: [
    { slug: "life", name: "Life" },
    { slug: "wp", name: "wordpress" },
  ],
  tags: [{ slug: "blog", name: "Blog" }],
  image: 1000,
  postMeta: [{ key: "custom_key", value: "custom_value" }],
})

addPage(options)

Adds new page for Importer object. All parameters are same as addPost(options).

addCategory(options)

Adds new category for Importer object.

  • options:
    • id: category Id. If not provided, random ID will be generated.
    • slug: category slug. Used in URLS, e.g. "js-rocks"
    • name: category title, e.g. "Everything about JS"
    • parent_id: category parent id if it existed.
    • description: category description string, default is empty.

Example

importer.addCategory({
  id: 5,
  parent_id: 3,
  name: "Everything about JS",
  slug: "js-rocks",
  description: "tech about js",
})

addTag(options)

Adds new tag for Importer object.

  • options:
    • id: tag Id, if not provied, random ID will be generated.
    • slug: tag slug. Used in URLS, e.g. "js-rocks"
    • name: tag title, e.g. "JS"
    • description: tag description string, default is empty.

Example

importer.addTag({
  id: 5,
  name: "JS",
  slug: "js-rocks",
  description: "tech about js",
})

addUser(options)

Add new user for Importer object.

  • options:
    • id: user Id
    • username: user login name
    • email: user email
    • display_name: user nickname
    • first_name: user first name
    • last_name: user last name

addAttachment(options)

Adds new attachment(image) for Importer object.

  • options:
    • id: attachment Id. If not provided, random ID will be generated.
    • url: attachment absolute url.
    • date: attachment create time.
    • file: attachment relative path if it exist.
    • title: attachment title.
    • author: attachment uploader.
    • description: attachment description.
    • post_id: post id relate to the attachment.
    • meta_data: other serialized attach meta data.

Exmaples

importer.addAttachment({
  id: 5,
  url: "https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg",
  date: "2015-10-05 00:27:25",
  file: "/wp-content/upload/2015/10/05/minka.jpg",
  title: "Fig. 1. Cats and puppies",
  author: "admin",
  description: "Fig. 1. Cats and puppies",
  post_id: 3,
})
// Example of adding featured image with post
let i = 100 // i should exist as the index of a loop
const image = 'http://example.com/image.jpg'
const imageId = (image) ? randomNum() : '' // use a different number range from i to avoid overlaps

importer.addPost({
  id: i,
  title: 'title'
  slug: 'slug',
  date: '2020-01-01 00:00:00',
  author: 'admin',
  content: 'post content',
  summary: 'excerpt',
  comment_status: 'closed',
  ping_status: 'closed',
  image: imageId
})

if(image){
  importer.addAttatchment({
    id: imageId,
    url: image,
    date: '2020-01-01 00:00:00',
    title: 'title',
    author: 'admin',
    post_id: i
 })
}

addComment(options)

TODO

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.")
})

Contributing

Contributions welcome!

License

MIT