Open teekay opened 3 years ago
When I add eleventyExcludeFromCollections: true
to the front matter data, the problem seems to disappear:
---js
{
permalink: "tango/rss/index.xml",
excludeFromSitemap: true,
eleventyExcludeFromCollections: true,
pubDate: new Date()
}
---
I took the hint from the comments to #522.
It still takes me by surprise because all of my collections are specified by the glob ...**/*.md
. This page is a nunjucks template, not a post. It must've been added to collections.all
nevertheless, right?
I suddenly started seeing this error too today.
It does not happen on the initial build of eleventy --serve
but if I save a markdown file afterwards it fails.
It looks like the error comes from node_modules/@11ty/eleventy-plugin-rss/.eleventy.js:28:7
:
eleventyConfig.addNunjucksAsyncFilter("htmlToAbsoluteUrls", (htmlContent, base, callback) => {
if(!htmlContent) {
callback(null, "");
return;
}
let posthtmlOptions = Object.assign({
// default PostHTML render options
closingSingleTag: "slash"
}, options.posthtmlRenderOptions);
convertHtmlToAbsoluteUrls(htmlContent, base, posthtmlOptions).then(html => {
callback(null, html); // <- THIS LINE
});
});
I have Eleventy 1.0.0 and eleventy-plugin-rss 1.1.2
I am facing the exact same symptoms as @andeersg with eleventy 1.1.0 and eleventy-plugin-rss 1.1.2 and nunjucks template:
Initial build is ok. Modifying a file in the post
collection generates the same error from the plugin but the issue doesn't happen for pages which are not in the post collection.
Is there a workaround or something we can do about this?
(I don't have a minimal example to reproduce but this repo exhibits the behavior: clone, npm install
, npm run dev
then edit any file in the src/posts
directory and you get the error)
I am having this issue too! In several for loops (e.g. {% for entry in collections.all %}
), when I call entry.templateContent
I get: Tried to use templateContent too early
. Nevertheless, in some other pages it works. I cannot figure out if there is any pattern or any particular reason.
Please, refer to this set of examples to reproduce the issue.
Thanks a lot! T
What I've done to make it better in development is to enable the plugin only in the production build (rss.html
is the only file using the filters added by the plugin):
// .eleventy.js
// ... other imports
const rssPlugin = require('@11ty/eleventy-plugin-rss');
module.exports = (config) => {
config.ignores.add("./src/rss.html");
if (process.env.NODE_ENV === "production") {
config.ignores.delete("./src/rss.html");
config.addPlugin(rssPlugin);
}
// ... the rest
}
Hope that can help someone while a fix is found!
Eleventy does its best to generated an ordered dependency graph of the content to generate templateContent
correctly. You can read more about that here:
https://www.11ty.dev/docs/advanced-order/
That said, there are some edge cases here, because we don’t yet take into account the AST of the templates to determine what they consume (only where they publish to), as noted on the docs above.
One easy way to influence that order is to use eleventyExcludeFromCollections
. That being said, in my mind this is another vote for https://github.com/11ty/eleventy/issues/975 as an escape hatch to have more control over the ordering (until we get a more advanced solution in place).
I don’t think this has anything specifically to do with the RSS plugin, it’s just where the templateContent
property was referenced from.
I was not able to reproduce from https://github.com/11ty/eleventy/issues/1615#issuecomment-1060652030
So, just to summarize: I will leave this one open as the home base for a more automated solution to parse the templates to see what collections they consume. But a more short-term solution will be #975
Related to https://github.com/11ty/eleventy/issues/108 as well
@zachleat My bad in #1615 (comment) I should have linked to this commit because after that I disabled the feed template on local build to temporarily avoid the issue.
I agree that the issues you linked seems like good solution options for this issue :+1:
The build process sometimes ends with an exception
TemplateContentPrematureUseError
.Steps to reproduce Steps to reproduce the behavior:
/_site/tango/rss/index.njk
The build script invokes
.\node_modules\.bin\eleventy.cmd --output=./build
. This comes out on the command line:The first item in the stack trace (in which post this error occurs) changes from time to time. And sometimes, there is no error and everything works as expected.
When I remove this line from
/_site/tango/rss/index.njk
, there is no error:Expected behavior The build process finishes normally
Environment:
0.11.1