Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* Place in your _data directory to create an Eleventy data source from an RSS feed
* View package docs for full available parsed schema: https://www.npmjs.com/package/rss-parser
*
* TO USE in Nunjucks assuming a filename of `rssposts`
*
* {% for post in rssposts %}
* <article>
* <h3>
* <a href="{{ post.url }}">{{ post.title }}</a>
* </h3>
* <p>
* {{ post.description }}
* </p>
* </article>
* {% endfor %}
*/
const Parser = require("rss-parser");
const parser = new Parser();
module.exports = async () => {
const feed = await parser.parseURL("[FEED_URL]");
const content = feed.items[0].contentSnippet;
return [
{
title: feed.items[0].title,
url: feed.items[0].link,
description:
content.replace(/(<([^>]+)>)/gi, "").substr(0, content.lastIndexOf(" ", 160)) + "...",
},
];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.