GithubHelp home page GithubHelp logo

code0987 / metalsmith-rssfeed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mpolitze/metalsmith-rssfeed

0.0 3.0 0.0 16 KB

A metalsmith plugin to create RSS feeds from files

License: Apache License 2.0

JavaScript 100.00%

metalsmith-rssfeed's Introduction

metalsmith-rssfeed

Build Status npm version

Yet another metalsmith plugin to generate an RSS feeds.

Compatible with (but does not depend on):

Installation

$ npm install metalsmith-rssfeed --save

Usage

var rssfeed     = require('metalsmith-rssfeed');

// create a rss feed from the first 20 elements of the collection posts
// and save it as feed.xml
metalsmith.use(rssfeed({
    collection: "posts",
    limit: 20,
    name: "feed.xml",
});

Examples

create a rss feed for containing every post with a specific tag and save it in one file per tag:

metalsmith.use(rssfeed({
    collectionKey: "tags",
    name: ":collection.xml",
});

create a rss feed for containing every post with a specific tag and save it in one file per tag:

metalsmith.use(rssfeed({
    collectionKey: "tags",
    name: ":collection.xml",
});

merge all tagged posts in a single feed alltags.xml:

metalsmith.use(rssfeed({
    title: 'Tagged Posts'
    description: 'All tagged posts are in this feed.'
    collectionKey: "tags",
    name: "alltags.xml",
});

Options and default values

{
    // filename of the rss feed. 
    // options.replaceToken will be replaced by the feed name when 
    // generating multiple feeds e.g. one for each tag.
    name: ':collection.xml',

    // ** feed options **
    // if not set explicitely will try to read these from metalsmith 
    // metadata like:
    // metadata[key] or metadata.site[key]

    // author of rss feed.    
    author: '',
    // title of rss feed.
    // options.replaceToken will be replaced by the feed name when 
    // generating multiple feeds e.g. one for each tag.
    title:  '',
    // description of rss feed.
    // options.replaceToken will be replaced by the feed name when 
    // generating multiple feeds e.g. one for each tag.
    description: '',
    // url of the site
    siteUrl: '',
    // generator of the rss feed.
    generator: 'metalsmith-rssfeed',
    // a custom function returning the feed options above.
    // other options will be ignored if this is set.
    feedOptions: (CollectionName, collection, options) => ({
            generator: options.generator,
            site_url: options.siteUrl,
            author: options.author.name || options.author,
            description: options.description.replace(o.replaceToken, c),
            title: options.title.replace(o.replaceToken, c),
            feed_url: options.pathToUrl(feedName)
    }),

    // ** feed items **

    // generate feed for a specific collection.
    // if it is an array will generate a feed for each item. 
    // if false generate for all colletions in options.collectionKey
    collection: false,
    // key to use to look for collections. 
    // defaults to 'collections' if options.collection was set. 
    collectionKey: o.collection ? 'collections' : false,
    // token to be replaced by collection name.
    replaceToken: ':collection',
    // pattern to filter files if neither collection nor
    // collection key were specified.
    pattern: '**';
    // key to permalink of file
    permalinkKey: 'permalink';
    // max number of items in the feed
    // if false all files are included.
    o.limit: false;
    // function to generate absolute url from file path
    pathToUrl: p => url.resolve(options.siteUrl, p);
    // a custom function to return the feed items
    // defaults will be ignored if this is set.
    itemOptions:  (file, options) => ({
            title: file.title,
            description: file.less || file.excerpt || file.contents,
            author: file.author.name || file.author,
            url: options.pathToUrl(file[options.permalinkKey] || file.path, options),
            date: file.date,            
            guid: file[options.permalinkKey] ? null : file.path
    })

Notes

metalsmith-feed is another great feed creation plugin, however it strictly depends on collections.

metalsmith-rssfeed's People

Contributors

mpolitze avatar code0987 avatar khaledgarbaya avatar

Watchers

James Cloos avatar  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.