11ty / eleventy-plugin-rss

A pack of Eleventy plugins for generating an RSS feed.
https://www.11ty.dev/docs/plugins/rss/
MIT License
92 stars 22 forks source link

Problems importing eleventy-plugin-rss v2.0 via a custom plugin #52

Open nathan-bottomley opened 2 weeks ago

nathan-bottomley commented 2 weeks ago

I'm playing around with updating to version 2.0 of eleventy-plugin-rss. (I'm on Eleventy 3.0.0-alpha.13.)

I have a podcast plugin which I've written, which imports and adds eleventy-plugin-rss. That podcast plugin is imported and added to the main config file. I also have a nunjucks template which uses the filters supplied by eleventy-plugin-rss.

All this worked fine with eleventy-plugin-rss v1.x. With eleventy-plugin-rss v2.0, the filters don't get added to the main config.

[11ty] 1. Having trouble rendering njk template ./podcast.njk (via TemplateContentRenderError)
[11ty] 2. (./podcast.njk)
[11ty]   Error: filter not found: dateToRfc3339 (via Template render error)

However, if I add the podcast plugin to the main config file with { immediate: true }, everything works fine.

Here's a minimal repository illustrating the problem: https://github.com/nathan-bottomley/rss-test

I know that some changes have been made to the way plugin imports work, so I'm imagining that it's something to do with that. Having to add { immediate: true } isn't such an imposition: I'm just not sure if that's how things are meant to work.

zachleat commented 2 weeks ago

The RSS plugin swapped to an async plugin in v2.0.0 but I don’t think it was necessary to do so. I’m going to move it back to a synchronous plugin in v2.0.2. However, this will require a change in core, so it will have to wait for 2.0.0-canary.14.

In the mean time, the workaround is to await on the addPlugin call for the rss plugin, like so:

import rssPlugin from '@11ty/eleventy-plugin-rss'

export default async function(eleventyConfig) {
  await eleventyConfig.addPlugin(rssPlugin)
}
zachleat commented 1 week ago

Apologies, I flubbed this one on -alpha.14. It’ll go up with core v3.0.0-alpha.15.