Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@11ty/eleventy-plugin-rss

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/eleventy-plugin-rss - npm Package Compare versions

Comparing version 2.0.0-beta.5 to 2.0.0-beta.6

2

package.json
{
"name": "@11ty/eleventy-plugin-rss",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "A pack of Eleventy plugins for generating an RSS feed using the Nunjucks templating engine.",

@@ -5,0 +5,0 @@ "publishConfig": {

@@ -5,4 +5,3 @@ const pkg = require("../package.json");

function getFeedContent(type, { stylesheet, collectionName, limit }) {
let stylesheetUrl = stylesheet?.[type];
function getFeedContent({ type, stylesheet, collection }) {
// Note: page.lang comes from the i18n plugin: https://www.11ty.dev/docs/plugins/i18n/#page.lang

@@ -13,3 +12,3 @@

return `<?xml version="1.0" encoding="utf-8"?>
${stylesheetUrl ? `<?xml-stylesheet href="${stylesheetUrl}" type="text/xsl"?>\n` : ""}<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:base="{{ metadata.base | addPathPrefixToFullUrl }}" xmlns:atom="http://www.w3.org/2005/Atom">
${stylesheet ? `<?xml-stylesheet href="${stylesheet}" type="text/xsl"?>\n` : ""}<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:base="{{ metadata.base | addPathPrefixToFullUrl }}" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>

@@ -21,3 +20,3 @@ <title>{{ metadata.title }}</title>

<language>{{ metadata.language or page.lang }}</language>
{%- for post in collections.${collectionName} | reverse | head(${limit}) %}
{%- for post in collections.${collection.name} | reverse | head(${collection.limit}) %}
{%- set absolutePostUrl = post.url | htmlBaseUrl(metadata.base) %}

@@ -40,3 +39,3 @@ <item>

return `<?xml version="1.0" encoding="utf-8"?>
${stylesheetUrl ? `<?xml-stylesheet href="${stylesheetUrl}" type="text/xsl"?>\n` : ""}<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ metadata.language or page.lang }}">
${stylesheet ? `<?xml-stylesheet href="${stylesheet}" type="text/xsl"?>\n` : ""}<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ metadata.language or page.lang }}">
<title>{{ metadata.title }}</title>

@@ -46,3 +45,3 @@ <subtitle>{{ metadata.subtitle }}</subtitle>

<link href="{{ metadata.base | addPathPrefixToFullUrl }}" />
<updated>{{ collections['${collectionName}'] | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<updated>{{ collections['${collection.name}'] | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ metadata.base | addPathPrefixToFullUrl }}</id>

@@ -53,3 +52,3 @@ <author>

</author>
{%- for post in collections['${collectionName}'] | reverse | head(${limit}) %}
{%- for post in collections['${collection.name}'] | reverse | head(${collection.limit}) %}
{%- set absolutePostUrl %}{{ post.url | htmlBaseUrl(metadata.base) }}{% endset %}

@@ -82,3 +81,3 @@ <entry>

"items": [
{%- for post in collections['${collectionName}'] | reverse | head(${limit}) %}
{%- for post in collections['${collection.name}'] | reverse | head(${collection.limit}) %}
{%- set absolutePostUrl %}{{ post.url | htmlBaseUrl(metadata.base) }}{% endset %}

@@ -101,6 +100,2 @@ {

function getInputPath(type) {
return `virtual:eleventy-plugin-rss:${type}.njk`;
}
async function eleventyFeedPlugin(eleventyConfig, options = {}) {

@@ -118,11 +113,11 @@ eleventyConfig.versionCheck(">=3.0.0-alpha.11");

options = DeepCopy({
collectionName: false, // required
limit: 0, // limit number of entries, 0 means no limit
files: {
// rss and json also supported
atom: "/feed.xml",
// rss and json also supported
type: "atom",
collection: {
name: false, // required
limit: 0, // limit number of entries, 0 means no limit
},
templateData: {
// atom: {},
},
outputPath: "/feed.xml",
inputPath: `virtual:eleventy-plugin-feed-${options.type || "atom"}.njk`, // TODO make this more unique
templateData: {},
metadata: {

@@ -140,10 +135,12 @@ title: "Blog Title",

if(!options.collectionName) {
throw new Error("Missing `collectionName` option in feedPlugin from @11ty/eleventy-plugin-rss.");
if(!options.collection?.name) {
throw new Error("Missing `collection.name` option in feedPlugin from @11ty/eleventy-plugin-rss.");
}
let templateData = {
eleventyExcludeFromCollections: [ options.collectionName ],
...options?.templateData || {},
permalink: options.outputPath,
eleventyExcludeFromCollections: [ options.collection.name ],
eleventyImport: {
collections: [ options.collectionName ],
collections: [ options.collection.name ],
},

@@ -158,3 +155,3 @@ layout: false,

if(n < 0) {
throw new Error("`limit` option must be a positive number.");
throw new Error("`collection.limit` option must be a positive number.");
}

@@ -165,23 +162,3 @@ return array.slice(0, n);

for(let type in options.files) {
let files = options.files[type];
let inputPath;
let outputPath;
if(Array.isArray(files) && files.length >= 2) {
[inputPath, outputPath] = files;
} else if(typeof files === "string") {
inputPath = getInputPath(type);
outputPath = files;
} else {
throw new Error("Invalid `files` option. Needs an array of length 2 [inputPath, outputPath] or a string `outputPath`");
}
let data = {
permalink: outputPath,
...options?.templateData?.[type] || {},
...templateData,
};
eleventyConfig.addTemplate(inputPath, getFeedContent(type, options), data);
}
eleventyConfig.addTemplate(options.inputPath, getFeedContent(options), templateData);
};

@@ -188,0 +165,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc