Socket
Socket
Sign inDemoInstall

@11ty/eleventy-plugin-rss

Package Overview
Dependencies
844
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.9 to 1.1.0

sample/_site/feed.json

46

.eleventy.js

@@ -1,19 +0,9 @@

const dateToISO = require("./src/dateToISO");
const dateRfc3339 = require("./src/dateRfc3339");
const absoluteUrl = require("./src/absoluteUrl");
const htmlToAbsoluteUrls = require("./src/htmlToAbsoluteUrls");
const convertHtmlToAbsoluteUrls = require("./src/htmlToAbsoluteUrls");
const getNewestCollectionItemDate = require("./src/getNewestCollectionItemDate");
module.exports = function(eleventyConfig) {
eleventyConfig.addNunjucksFilter("rssLastUpdatedDate", collection => {
if( !collection || !collection.length ) {
throw new Error( "Collection is empty in rssLastUpdatedDate filter." );
}
module.exports = function(eleventyConfig, options = {}) {
eleventyConfig.addNunjucksFilter("absoluteUrl", absoluteUrl);
// Newest date in the collection
return dateToISO(new Date(Math.max(...collection.map(item => {return item.date}))));
});
eleventyConfig.addNunjucksFilter("rssDate", dateObj => dateToISO(dateObj));
eleventyConfig.addNunjucksFilter("absoluteUrl", (href, base) => absoluteUrl(href, base));
eleventyConfig.addNunjucksAsyncFilter("htmlToAbsoluteUrls", (htmlContent, base, callback) => {

@@ -25,6 +15,28 @@ if(!htmlContent) {

htmlToAbsoluteUrls(htmlContent, base).then(result => {
callback(null, result.html);
let posthtmlOptions = Object.assign({
// default PostHTML render options
closingSingleTag: "slash"
}, options.posthtmlRenderOptions);
convertHtmlToAbsoluteUrls(htmlContent, base, posthtmlOptions).then(html => {
callback(null, html);
});
});
// Dates
eleventyConfig.addNunjucksFilter("getNewestCollectionItemDate", getNewestCollectionItemDate);
eleventyConfig.addNunjucksFilter("dateToRfc3339", dateRfc3339);
// Deprecated, these names are incorrect! Issue #8
eleventyConfig.addNunjucksFilter("rssLastUpdatedDate", collection => {
return dateRfc3339(getNewestCollectionItemDate(collection));
});
// Deprecated, this name is incorrect! Issue #8
eleventyConfig.addNunjucksFilter("rssDate", dateRfc3339);
};
module.exports.dateToRfc3339 = dateRfc3339;
module.exports.getNewestCollectionItemDate = getNewestCollectionItemDate;
module.exports.absoluteUrl = absoluteUrl;
module.exports.convertHtmlToAbsoluteUrls = convertHtmlToAbsoluteUrls;
{
"name": "@11ty/eleventy-plugin-rss",
"version": "1.0.9",
"version": "1.1.0",
"description": "A pack of Eleventy plugins for generating an RSS feed using the Nunjucks templating engine.",

@@ -11,3 +11,3 @@ "publishConfig": {

"test": "npx ava",
"sample": "npx @11ty/eleventy --input=sample"
"sample": "cd sample && npx @11ty/eleventy --config=config-sample.js"
},

@@ -40,9 +40,9 @@ "repository": {

"devDependencies": {
"ava": "^1.0.1"
"ava": "^3.15.0"
},
"dependencies": {
"debug": "^4.1.1",
"posthtml": "^0.13.0",
"debug": "^4.3.1",
"posthtml": "^0.15.1",
"posthtml-urls": "1.0.0"
}
}

@@ -0,35 +1,35 @@

<p align="center"><img src="https://www.11ty.dev/img/logo-github.png" alt="eleventy Logo"></p>
# eleventy-plugin-rss
A pack of [Eleventy](https://github.com/11ty/eleventy) plugins for generating Atom and JSON feeds using the Nunjucks templating engine.
A pack of [Eleventy](https://github.com/11ty/eleventy) filters for generating Atom and JSON feeds using the Nunjucks templating engine.
_Note: the plugin is called RSS but does not technically include an example of an RSS feed. Generally feed readers that support RSS also support Atom. If you’d like to contribute an example, a pull request would be welcome!_
## Installation
See `sample/feed.njk` for an example Atom feed template or `sample/feed.json` for an example JSON feed template.
Available on [npm](https://www.npmjs.com/package/@11ty/eleventy-plugin-rss).
## [The full `eleventy-plugin-rss` documentation is on 11ty.dev](https://www.11ty.dev/docs/plugins/rss/).
```
npm install @11ty/eleventy-plugin-rss --save-dev
```
* _This is a plugin for the [Eleventy static site generator](https://www.11ty.dev/)._
* Find more [Eleventy plugins](https://www.11ty.dev/docs/plugins/).
* Please star [Eleventy on GitHub](https://github.com/11ty/eleventy/), follow [@eleven_ty](https://twitter.com/eleven_ty) on Twitter, and support [11ty on Open Collective](https://opencollective.com/11ty)
Open up your Eleventy config file (probably `.eleventy.js`) and use `addPlugin`:
[![npm Version](https://img.shields.io/npm/v/@11ty/eleventy-plugin-rss.svg?style=for-the-badge)](https://www.npmjs.com/package/@11ty/eleventy-plugin-rss) [![GitHub issues](https://img.shields.io/github/issues/11ty/eleventy-plugin-rss.svg?style=for-the-badge)](https://github.com/11ty/eleventy-plugin-rss/issues)
## Installation
```
const pluginRss = require("@11ty/eleventy-plugin-rss");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
};
npm install @11ty/eleventy-plugin-rss
```
Read more about [Eleventy plugins.](https://www.11ty.io/docs/plugins/)
_[The full `eleventy-plugin-rss` documentation is on 11ty.dev](https://www.11ty.dev/docs/plugins/rss/)._
## Usage
## Tests
See `sample/feed.njk` for an example Atom feed template or `sample/feed.json` for an example JSON feed template.
```
npm run test
```
### Supplies: Nunjucks Filters
- We use the [ava JavaScript test runner](https://github.com/avajs/ava) ([Assertions documentation](https://github.com/avajs/ava/blob/master/docs/03-assertions.md))
- ℹ️ To keep tests fast, thou shalt try to avoid writing files in tests.
* `rssLastUpdatedDate`: Gets the most recently updated content in the collection and retrieves the properly formatted Date for the top-level `<updated>` element.
* `rssDate`: format a Date to be used for individual `<entry><updated>` elements.
* `absoluteUrl`: converts a single URL (relative or absolute path) to a full absolute URL including protocol, domain, full path.
* `htmlToAbsoluteUrls`: transforms all of the URLs in a block of HTML with `absoluteUrl` above. Uses [posthtml-urls](https://github.com/posthtml/posthtml-urls) with `a[href]`, `video[src]`, `audio[src]`, `source`, `img[src]`, `[srcset]` and [a whole bunch more](https://github.com/posthtml/posthtml-urls/blob/307c91342a211b3f9fb22bc57264bbb31f235fbb/lib/defaultOptions.js).

@@ -5,3 +5,3 @@ const posthtml = require('posthtml');

module.exports = function(htmlContent, base) {
module.exports = async function(htmlContent, base, processOptions = {}) {
if( !base ) {

@@ -12,11 +12,4 @@ throw new Error( "eleventy-plugin-rss, htmlToAbsoluteUrls(absolutePostUrl) was missing the full URL base `absolutePostUrl` argument.")

let options = {
eachURL: function(url, attr, element) {
url = url.trim();
// #anchor in-page
if( url.indexOf("#") === 0 ) {
return url;
}
return absoluteUrl(url, base);
eachURL: function(url) {
return absoluteUrl(url.trim(), base);
}

@@ -27,3 +20,4 @@ };

return modifier.process(htmlContent);
let result = await modifier.process(htmlContent, processOptions);
return result.html;
};

@@ -1,13 +0,27 @@

import test from "ava";
import htmlToAbsUrls from "../src/htmlToAbsoluteUrls.js";
const test = require("ava");
const htmlToAbsUrls = require("../src/htmlToAbsoluteUrls.js");
test("Changes a link href", async t => {
t.is((await htmlToAbsUrls(`<a href="#testanchor">Hello</a>`, "http://example.com/")).html, `<a href="#testanchor">Hello</a>`);
t.is((await htmlToAbsUrls(`<a href="/test.html">Hello</a>`, "http://example.com/")).html, `<a href="http://example.com/test.html">Hello</a>`);
t.is((await htmlToAbsUrls(`<img src="/test.png">`, "http://example.com/")).html, `<img src="http://example.com/test.png">`);
t.is((await htmlToAbsUrls(`<a href="http://someotherdomain/">Hello</a>`, "http://example.com/")).html, `<a href="http://someotherdomain/">Hello</a>`);
t.is(await htmlToAbsUrls(`<a href="#testanchor">Hello</a>`, "http://example.com/"), `<a href="http://example.com/#testanchor">Hello</a>`);
t.is(await htmlToAbsUrls(`<a href="#testanchor">Hello</a>`, "http://example.com/web/"), `<a href="http://example.com/web/#testanchor">Hello</a>`);
t.is(await htmlToAbsUrls(`<a href="/test.html">Hello</a>`, "http://example.com/"), `<a href="http://example.com/test.html">Hello</a>`);
t.is(await htmlToAbsUrls(`<img src="/test.png">`, "http://example.com/"), `<img src="http://example.com/test.png">`);
t.is(await htmlToAbsUrls(`<a href="http://someotherdomain/">Hello</a>`, "http://example.com/"), `<a href="http://someotherdomain/">Hello</a>`);
});
test("Bad link href", async t => {
t.is((await htmlToAbsUrls(`<a href="http://#">Hello</a>`, "http://example.com/")).html, `<a href="http://#">Hello</a>`);
t.is(await htmlToAbsUrls(`<a href="http://#">Hello</a>`, "http://example.com/"), `<a href="http://#">Hello</a>`);
});
test("Line breaks, Issue #12", async t => {
let processOptions = {
closingSingleTag: "slash"
};
t.is(await htmlToAbsUrls(`<br/>`, "http://example.com/"), `<br>`);
t.is(await htmlToAbsUrls(`<br/>`, "http://example.com/", processOptions), `<br />`);
let processedHtml = await htmlToAbsUrls(`<img src="/test.png">`, "http://example.com/", processOptions);
t.is(processedHtml, `<img src="http://example.com/test.png" />`);
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc