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

wpxpost

v1.0.10

Published

pull articles from an RSS feed, pull details from post page, create excerpt post and upload to wordpress

Downloads

21

Readme

wpxpost

cross-posting script for RSS to a wordpress installation

  1. grab articles from an RSS feed
  2. grab content and featured image from full articles using selectors
  3. 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)
  4. create new article on destination wordpress site with:
    1. same author (if possible) or specified author id
    2. same publish date
    3. stripped down excerpt of original post body
    4. link to original content
    5. 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
}