wpxpost
v1.0.10
Published
pull articles from an RSS feed, pull details from post page, create excerpt post and upload to wordpress
Downloads
5
Readme
wpxpost
cross-posting script for RSS to a wordpress installation
- grab articles from an RSS feed
- grab content and featured image from full articles using selectors
- try and match author to original author ('dc:creator') to author on new wordpress site (great if you are cross-posting between two sites with the same authors)
- create new article on destination wordpress site with:
- same author (if possible) or specified author id
- same publish date
- stripped down excerpt of original post body
- link to original content
- specified categories and tags
usage
wpxpost.go({
endpoint: <destination wordpress wp-json endpoint url>,
username: <destination wordpress username>,
password: <destination wordpress password>,
webhookURL: <slack webhook url (optional)>,
sourceURL: <source RSS feed url>,
lastRunFile: <filename to store last run>,
featuredImageSelector: <css selector to find primary img>,
postBodySelector: <css selector for primary content>,
excerptWordCount: <# of words to use in the excerpt>,
/** wordpress options **/
postStatus: "draft", // draft, private, publish
tags: [214], // array of wp tag ids
categories: [1], // array of wp category ids
authorID: 38 // wp author id
})
customization
if we like, we can override some methods, but we'll have to bring in some modules
const axios = require('axios')
const {JSDOM} = require('jsdom')
const {stripExtras} = require('./lib/utils.js')
then we can change how we get the post details
wpxpost.getArticle = async (url) => {
return await axios.get(url).then((response) => {
const dom = new JSDOM(response.data)
const title = dom.window.document.querySelector('title').textContent
const heroImage = dom.window.document.querySelector(wpxpost.opts.featuredImageSelector).src
const body = stripExtras(dom.window.document.querySelector(wpxpost.opts.postBodySelector).innerHTML)
const trimmedBody = body.split(' ').slice(0, wpxpost.opts.excerptWordCount).join(' ').replace(/,$/, '') + '...'
return {
title,
heroImage,
body: trimmedBody,
}
})
}
...or change how we build the post content
wpxpost.createBody = async (info) => {
const body =
`<div class="excerpt">${info['body']}</div><br>` +
`<div class="bottomdesc">${info['description']}</div></div>` +
`<style>.bottomdesc a { font-weight: bold; text-decoration: underline;}</style>`
return body
}