wxr-generator
XML(WXR) file generator for fully support official WordPress Import Plugin. Inspired By node-wxr.
Install
npm install wxr-generator
How To Use
var Importer = ;var importer = ; importer; console;
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 = ;var 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 beopen
orclosed
. - ping_status: post ping status, default is
open
, it can beopen
orclosed
. - password: post visit password if it should, default is empty.
- categories: post categories, it's an array item. Every item should has
slug
andname
prototype. - tags: post tags, it's an array item. Every item should has
slug
andname
prototype. - image: id of attached image to use as featured image for this post
Example
importer
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
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
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
// 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 = ; // importer.addPost(...) var xmlString = importer;;
Contributing
Contributions welcome!