Created
August 11, 2020 13:46
-
-
Save 5t3ph/9c37f7e79db4b317bcb148a8dfcf466e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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