Giter VIP home page Giter VIP logo

jsonfeed-to-atom's Introduction

jsonfeed-to-atom

npm version build status coverage downloads js-standard-style

Convert a JSON feed to an atom feed.

JSON feed icon

Installation

$ npm install jsonfeed-to-atom

Usage

const jsonfeedToAtom = require('jsonfeed-to-atom')
const someJSONFeed = require('./load-some-json-feed-data.json')

const atomFeed = jsonfeedToAtom(someJSONFeed) // Returns an atom formatted json feed

Example input:

{
 "version": "https://jsonfeed.org/version/1",
 "title": "bret.io log",
 "home_page_url": "https://bret.io",
 "feed_url": "https://bret.io/feed.json",
 "description": "A running log of announcements, projects and accomplishments.",
 "next_url": "https://bret.io/2017.json",
 "icon": "https://bret.io/icon-512x512.png",
 "author": {
  "name": "Bret Comnes",
  "url": "https://bret.io",
  "avatar": "https://gravatar.com/avatar/8d8b82740cb7ca994449cccd1dfdef5f?size=512"
 },
 "items": [
  {
   "date_published": "2018-04-07T20:48:02.000Z",
   "content_text": "Wee wooo this is some content. \n Maybe a new paragraph too",
   "url": "https://bret.io/my-text-post",
   "id": "https://bret.io/my-text-post-2018-04-07T20:48:02.000Z"
  },
  {
   "date_published": "2018-04-07T22:06:43.000Z",
   "content_html": "<p>Hello, world!</p>",
   "title": "This is a blog title",
   "url": "https://bret.io/my-blog-post",
   "external_url": "https://example.com/some-external-link",
   "id": "https://bret.io/my-blog-post-2018-04-07T22:06:43.000Z"
  }
 ]
}

Example output:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>bret.io log</title>
  <id>https://bret.io/feed.xml</id>
  <updated>2018-04-07T22:06:43.000Z</updated>
  <link rel="self" type="application/atom+xml" href="https://bret.io/feed.xml"/>
  <link rel="alternate" type="application/json" href="https://bret.io/feed.json"/>
  <link rel="alternate" type="text/html" href="https://bret.io"/>
  <link rel="next" href="https://bret.io/2017.xml"/>
  <author>
    <name>Bret Comnes</name>
    <uri>https://bret.io</uri>
  </author>
  <generator uri="https://github.com/bcomnes/jsonfeed-to-atom#readme" version="1.0.0">jsonfeed-to-atom</generator>
  <rights>© 2018 Bret Comnes</rights>
  <subtitle>A running log of announcements, projects and accomplishments.</subtitle>
  <entry>
    <id>https://bret.io/my-text-post-2018-04-07T20:48:02.000Z</id>
    <title>Wee wooo this is some content.</title>
    <updated>2018-04-07T20:48:02.000Z</updated>
    <published>2018-04-07T20:48:02.000Z</published>
    <content type="text">Wee wooo this is some content. 
 Maybe a new paragraph too</content>
    <link rel="alternate" href="https://bret.io/my-text-post"/>
  </entry>
  <entry>
    <id>https://bret.io/my-blog-post-2018-04-07T22:06:43.000Z</id>
    <title>This is a blog title</title>
    <updated>2018-04-07T22:06:43.000Z</updated>
    <published>2018-04-07T22:06:43.000Z</published>
    <content type="html">
      <![CDATA[<p>Hello, world!</p>]]>
    </content>
    <link rel="alternate" href="https://bret.io/my-blog-post"/>
    <link rel="related" href="https://example.com/some-external-link"/>
  </entry>
</feed>

API

jsonfeedToAtom(parsedJsonfeed, opts)

Coverts a parsed JSON feed into an atom feed. Returns the string of the atom feed.

Opts include:

{
  // a function that returns the atom feed url
  feedURLFn: (feedURL, jf) => feedURL.replace(/\.json\b/, '.xml')
}

See also

License

MIT

jsonfeed-to-atom's People

Contributors

bcomnes avatar feross avatar greenkeeper[bot] avatar xriss avatar zamfofex avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.