An open API service indexing awesome lists of open source software.

https://github.com/zspecza/reshape-rss

Reshape plugin for RSS feeds
https://github.com/zspecza/reshape-rss

Last synced: 10 months ago
JSON representation

Reshape plugin for RSS feeds

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.org/declandewet/reshape-rss.svg?branch=master)](https://travis-ci.org/declandewet/reshape-rss)
[![codecov](https://codecov.io/gh/declandewet/reshape-rss/branch/master/graph/badge.svg)](https://codecov.io/gh/declandewet/reshape-rss)
[![dependencies Status](https://david-dm.org/declandewet/reshape-rss/status.svg)](https://david-dm.org/declandewet/reshape-rss)
[![devDependencies Status](https://david-dm.org/declandewet/reshape-rss/dev-status.svg)](https://david-dm.org/declandewet/reshape-rss?type=dev)

# reshape-rss

[Reshape](https://github.com/reshape/reshape) plugin for generating RSS feeds.

> **Note**: this project is still in early development and not all features may be implemented yet.

### Example Usage

```js
const reshape = require('reshape')
const rss = require('reshape-rss')

let feed = {}

reshape({
plugins: [
rss(feed)
]
})
.process(`


Blog Posts



Read the latest posts from my blog



The Genius Loki of Utopia



A sample blog post


Joe West
31 Comments
Read More

© mysite.com 2013

`)
.then((result) => {
console.log(rss.convertToXML(feed))
})
```

![arrow pointing down](http://imgh.us/downarrow_1.png)

```xml


Blog Posts
Read the latest posts from my blog
© mysite.com 2013
reshape-rss
http://mysite.com/blog
Sat, 13 Jul 2013 13:12:00 EST
Fri, 12 Jul 2013 11:13:00 EST
en-US

The Genius Loki of Utopia
A sample blog post
Joe West
Fri, 12 Jul 2013 11:13:00 EST
http://mysite.com/blog/the-genius-loki-of-utopia
http://mysite.com/blog/the-genius-loki-of-utopia
random
http://mysite.com/blog/the-genius-loki-of-utopia/#/comments

```

### Installation

```sh
$ npm install reshape-rss --save
```

### Pass an empty object to `rss`

`reshape-rss` takes one option: an empty object. As your HTML file is parsed for `rss-*` attributes, this object will be populated with information about your RSS feed. For the example above, it would look like this once parsing is done:

```js
{
channels: [{
title: 'Blog Posts',
description: 'Read the latest posts from my blog',
link: 'http://mysite.com/blog',
copyright: '© mysite.com 2013',
language: 'en-US',
lastBuildDate: 'Sat, 13 Jul 2013 13:12:00 EST',
pubDate: 'Fri, 12 Jul 2013 11:13:00 EST'
items: [{
title: 'The Genius Loki of Utopia',
description: 'A sample blog post',
author: 'Joe West',
pubDate: 'Fri, 12 Jul 2013 11:13:00 EST',
link: 'http://mysite.com/blog/the-genius-loki-of-utopia',
guid: {
isPermaLink: true,
value: 'http://mysite.com/blog/the-genius-loki-of-utopia'
},
categories: ['random'],
comments: 'http://mysite.com/blog/the-genius-loki-of-utopia/#/comments'
}]
}]
}
```

### Converting to XML

You can use the `rss.convertToXML()` method to convert your feed object to a string of XML. You can then do whatever you like with this string, like write it out to a file.

```js
const rss = require('reshape-rss')
rss.convertToXML(feed) // => "..."
```

### Merging Many Feeds

`reshape-rss` exposes one more method: `rss.mergeFeeds()`. Pass this method two or more feed objects, and it will merge them together. It's useful if you are working with multiple files that produce multiple RSS feeds but you only want to render them out to one XML file.

```js
const rss = require('reshape-rss')
rss.mergeFeeds({
channels: [{
title: 'Foo',
description: 'Bar',
link: 'http://baz.com'
}]
}, {
channels: [{
title: 'Fizz',
description: 'Buzz',
link: 'http://fizzbuzz.com'
}]
})
/* => {
channels: [{
title: 'Foo',
description: 'Bar',
link: 'http://baz.com'
}, {
title: 'Fizz',
description: 'Buzz',
link: 'http://fizzbuzz.com'
}]
} */
```

### Specifying Attributes

In your HTML file, you can specify an `rss-channel` attribute on any element. An element with an `rss-channel` attribute can have other `rss-*` attributes directly on or as a descendant of itself. These attributes will become properties of the `rss-channel`. One HTML file can have many `rss-channel` attributes. A channel requires an `rss-title`, `rss-description` and `rss-link` attribute.

```html

Foo


bar


Go to foo
...

```

An `rss-channel` attribute must have at least one child with an `rss-item` attribute. Any `rss-*` attributes directly on or descendant of an `rss-item` attribute will become properties of that `rss-item`. An item requires an `rss-title`, `rss-description` and `rss-link` attribute. An `rss-channel` can have many descendant `rss-item`s.

```html

Foo


bar


Go to foo

Fizz


Bazz


Read More

```

The attributes can be specified anywhere in the markup **as long as** the properties of `rss-channel` are placed on or within `rss-channel`, an `rss-item` occurs only within an `rss-channel`, and properties of `rss-item` are placed on or within `rss-item`.

Most `rss-*` attributes will attempt to infer their value from the `.innerText` property of the HTML node they are placed on, however, special case is given to `rss-guid`, `rss-link` and `rss-comments`, which will grab their value from their elements' `href` attribute if present. You may override this behavior by passing in a value directly, like so:

```html

Foo


bar


Go to foo

Fizz


Bazz


Read More

```