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
- Host: GitHub
- URL: https://github.com/zspecza/reshape-rss
- Owner: zspecza
- License: mit
- Created: 2016-06-17T18:18:38.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-06-01T01:14:19.000Z (almost 6 years ago)
- Last Synced: 2025-04-04T12:28:25.132Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 73.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://travis-ci.org/declandewet/reshape-rss)
[](https://codecov.io/gh/declandewet/reshape-rss)
[](https://david-dm.org/declandewet/reshape-rss)
[](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))
})
```

```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
```