New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nuxtjs/feed

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/feed

[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/feed/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/feed) [![npm](https://img.shields.io/npm/dt/@nuxtjs/feed.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/feed) [

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.2K
decreased by-2%
Maintainers
1
Weekly downloads
 
Created
Source

Feed module - Everyone deserves RSS, Atom and Json

npm (scoped with tag) npm Build Status codecov Dependencies js-standard-style

📖 Release Notes

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!)

Setup

  • Add @nuxtjs/feed dependency using yarn or npm to your project
  • Add @nuxtjs/feed to modules section of nuxt.config.js
{
  modules: [
    // Simple usage
    '@nuxtjs/feed',
 ],
 feed: [
   // Your feeds here
 ]
}
  • Configure it as you need

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 create (feed) {}, // The create function (see below)
     cacheTime: 1000 * 60 * 15, // How long should the feed be cached
     type: 'rss2' // Can be: rss2, atom1, json1
   }
 ],
 //...
}

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:

create = async feed => {
  feed.options = {
    title: 'My blog',
    description: 'This is my personal feed!',
  }
  
  const posts = await axios.get('https://blog.lichter.io/posts/').data
  posts.forEach(post => { 
    feed.addItem({
        title: post.title,
        id: post.url,
        link: post.url,
        description: post.description,
        content: post.content
  })
  
  feed.addCategory('Nuxt.js')
  
  feed.addContributor({
    name: 'Alexander Lichter',
    email: 'example@lichter.io',
    link: 'https://lichter.io/'
  })
}

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

  • Clone this repository
  • Install dependencies using yarn install or npm install
  • Start development server using npm run dev

License

MIT License

Copyright (c) Alexander Lichter

Keywords

FAQs

Package last updated on 18 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc