@nuxtjs/feed
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -5,3 +5,13 @@ # Change Log | ||
<a name="0.1.0"></a> | ||
# [0.1.0](https://github.com/nuxt-community/feed-module/compare/v0.0.1...v0.1.0) (2018-04-18) | ||
### Features | ||
* accept a factory function as feed parameter ([740ec07](https://github.com/nuxt-community/feed-module/commit/740ec07)) | ||
<a name="0.0.1"></a> | ||
## 0.0.1 (2018-04-14) |
@@ -16,5 +16,13 @@ const path = require('path') | ||
module.exports = async function feed (moduleOptions) { | ||
const options = Object.assign([], this.options.feed, moduleOptions).map(o => Object.assign({}, defaults, o)) | ||
module.exports = async function feed () { | ||
if (typeof this.options.feed === 'function') { | ||
this.options.feed = await this.options.feed() | ||
} | ||
if (!Array.isArray(this.options.feed)) { | ||
this.options.feed = [this.options.feed] | ||
} | ||
const options = Object.assign([], this.options.feed).map(o => Object.assign({}, defaults, o)) | ||
const feedCache = new AsyncCache({ | ||
@@ -21,0 +29,0 @@ maxAge: options.cacheTime, |
{ | ||
"name": "@nuxtjs/feed", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -99,4 +99,49 @@ # Feed module - Everyone deserves RSS, Atom and Json | ||
Using the `create` function gives you unlimited possibilities to customize your feed! | ||
Using the `create` function gives you almost unlimited possibilities to customize your feed! | ||
### Using a feed factory function | ||
There is one more thing. Imagine you want to add a feed per blog category, but you don't want | ||
to add every category by hand. | ||
You can use a `factory function` to solve that problem. Instead of a hardcoded array, you can setup | ||
a function that will be called up on feed generation. The function **must** return an array with all | ||
feeds you want to generate. | ||
```js | ||
{ | ||
feed: async () => { | ||
const posts = (await axios.get('https://my-url.com/posts')).data | ||
const tags = (await axios.get('https://my-url.com/tags')).data | ||
return tags.map(t => { | ||
const relevantPosts = posts.filter(/*filter posts somehow*/) | ||
return { | ||
path: `/${t.slug}.xml`, // The route to your feed. | ||
async create (feed) { | ||
feed.options = { | ||
title: `${t.name} - My blog`, | ||
description: `All posts related to ${t.name} of my blog`, | ||
} | ||
relevantPosts.forEach(post => { | ||
feed.addItem({ | ||
title: post.title, | ||
id: post.id, | ||
link: `https://blog.lichter.io/posts/${post.slug}`, | ||
description: post.excerpt, | ||
content: post.text | ||
}) | ||
}) | ||
}, | ||
cacheTime: 1000 * 60 * 15, | ||
type: 'rss2' | ||
} | ||
}) | ||
}, | ||
} | ||
``` | ||
## Development | ||
@@ -103,0 +148,0 @@ |
10301
67
157