Feed module - Everyone deserves RSS, Atom and Json
Feed module enables everyone to have RSS, Atom and Json.
Features
- Three different feed types (RSS 2.0, ATOM 1.0 and JSON 1.0)
- As many feeds as you like!
- Completely customizable. Need to fetch data before? No problem!
- Works with all modes (yes, even generate!)
- For Nuxt 2.x and higher
Setup
- Add
@nuxtjs/feed
dependency to your project
yarn add @nuxtjs/feed # or npm install @nuxtjs/feed
- Add
@nuxtjs/feed
to themodules
section ofnuxt.config.js
modules: '@nuxtjs/feed' // Your feeds here
Using top level options
modules: '@nuxtjs/feed' feed: // Your feeds here
Configuration
So.. how to get these feeds working now?
Configuration object overview
feed: // A default feed configuration object path: '/feed.xml' // The route to your feed. async {} // The create function (see below) cacheTime: 1000 * 60 * 15 // How long should the feed be cached type: 'rss2' // Can be: rss2, atom1, json1 data: 'Some additional data' // Will be passed as 2nd argument to `create` function
Feed create function
Let's take a closer look on the create
function. This is the API that
actually modifies your upcoming feed.
A simple create function could look like this:
// In your `feed` array:async { feedoptions = title: 'My blog' link: 'https://lichter.io/feed.xml' description: 'This is my personal feed!' const posts = await axiosdata posts feed feed}
Feed creation is based on the feed package.
Please use it as reference and further documentation for modifying the feed
object
that is passed to the create
function.
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.
feed: async { const posts = await axiosdata const tags = await axiosdata return tags }
In case you want to pass in data into the factory function, you can use a factory object.
feed: data: 'Your data here' {/* your factory function */}
Development
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
License
Copyright (c) - Nuxt Community