Unable to call absoluteUrl from leventy-plugin-rss.
Getting error "Unable to call absoluteUrl, which is undefined or falsey"
Any extra step I need to be able to use this? I add this to .eleventy.js and package.json
const pluginRss = require("@11ty/eleventy-plugin-rss");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
}
Are you using absoluteUrl as a nunjucks filter from a nunjucks file, like the sample file does?
{%- for post in collections.posts %}
{% set absolutePostUrl %}{{ post.url | url | absoluteUrl(metadata.url) }}{% endset %}
<!-- ... -->
{%- endfor %}
The plugin only defines a nunjucks filter for use in .njk files, not a universal filter. So that could be the culprit. Are you trying to use it from another template language (i.e. liquid or handlebars)?
https://github.com/11ty/eleventy-plugin-rss/blob/master/.eleventy.js#L17
Yes, I use that in .njk
Actually it don't even work in https://github.com/11ty/eleventy-base-blog
You can try change /sitemap.xml.njk line 8
from
{{ page.url | url | absoluteUrl(metadata.url) }}
to
{{ absoluteUrl(metadata.url) }}
{{ absoluteUrl(metadata.url) }} isn't proper nunjucks filter syntax. (Can't call them like functions)
Tried this syntax? {{ metadata.url | absoluteUrl }}
Edit: What I mean is that a nunjucks filter is applied to an initial value, like this:
{{ someValue | someFilter }}
Ahhhh thanks, this part {{ page.url | url | absoluteUrl(metadata.url) }} made me think I can call it like a function.
Sarunw, encountered something similar, looks like that example is using some plugins that would enable that syntax. You鈥檇 need to make sure those were also installed.
@sarunw specifically, you need to add the @11ty/eleventy-plugin-rss package to your project.
absoluteUrl belongs to the api of that package.
To clear up the syntax question, this is valid syntax for a nunjucks filter. Here's the docs on filters:
Filters are essentially functions that can be applied to variables. They are called with a pipe operator (
|) and can take arguments.{{ foo | title }} {{ foo | join(",") }} {{ foo | replace("foo", "bar") | capitalize }}
In this particular case, this is the example used in the eleventy-base-blog
Which adds the filter via the eleventy-plugin-rss plugin like this (slightly simplified):
eleventyConfig.addNunjucksFilter("absoluteUrl", (href, base) => {
let { URL } = require("url");
return (new URL(href, base)).toString()
})
So as long as that the rss plugin is installed in your project, or you've manually added the filter above, you should be able to use that filter like this {{ url | absoluteUrl(metadata.url) }}
Also, make sure you've added your project URL to a metadata data file
Most helpful comment
To clear up the syntax question, this is valid syntax for a nunjucks filter. Here's the docs on filters:
In this particular case, this is the example used in the eleventy-base-blog
Which adds the filter via the eleventy-plugin-rss plugin like this (slightly simplified):
So as long as that the rss plugin is installed in your project, or you've manually added the filter above, you should be able to use that filter like this
{{ url | absoluteUrl(metadata.url) }}Also, make sure you've added your project URL to a
metadatadata file