GithubHelp home page GithubHelp logo

eleventy-rss-helper's Introduction

eleventy-rss-helper

Create RSS 2.0 feeds for an Eleventy site.

This is a wrapper around the rss module.

Install

npm install eleventy-rss-helper

Usage

1. Create feed file

Create a feed file (e.g. feed.11ty.js) in a directory that Eleventy will process.

Paste this boilerplate into the file:

const createRssFeed = require('eleventy-rss-helper');

module.exports = createRssFeed({
  permalink: '/feed.xml',
  feedOptions(data) {
    return {

    };
  },
  items(collections, data) {

  },
  itemOptions(item, data) {
    return {

    };
  }
});

2. Fill in the empty functions

feedOptions(data)

Receives

  • Eleventy data object

Returns object to be used as feedOptions with the rss module.

items(collections, data)

Receives

Returns array of items to include in the feed.

itemOptions(item, data)

Invoked once for each element in array returned by items().

Receives

  • An item from the array returned by your items() function
  • Eleventy data object

Returns object to be used as itemOptions with the rss module.

Example

const createRssFeed = require('eleventy-rss-helper');

const permalink = '/feed.xml';
const baseUrl = 'https://mysite.com';

module.exports = createRssFeed({
  permalink,
  feedOptions(data) {
    return {
      title: 'mysite.com',
      description: 'Latest posts from mysite.com',
      feed_url: `${baseUrl}${permalink}`,
      site_url: baseUrl
    };
  },
  items(collections, data) {
    // last 20 posts, newest first
    return collections.post
      .slice(-20)
      .reverse();
  },
  itemOptions(item, data) {
    return {
      title: item.data.title,
      description: '...',
      url: `${baseUrl}${item.url}`,
      date: item.date
    };
  }
});

License

MIT

eleventy-rss-helper's People

Contributors

dependabot[bot] avatar psalaets avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.