Skip to content

mpolitze/metalsmith-rssfeed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A metalsmith plugin to create RSS feeds from files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published