New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: don't render if permalink: false and eleventyExcludeFromCollections: true
#1700
Comments
|
An alternative could be to set |
|
I've run in to this myself - having to use eleventyIgnore in a really manual way to get Eleventy to stop evaluating a file. I'd much prefer if I could do this on the basis of frontmatter - which could be related to the requested feature of supporting drafts or a callback / frontmatter / function to determine whether to process a file. |
|
First thoughts here: Though, fair enough that it needn’t evaluate layouts if it only applies to collections. |
|
@zachleat that's right, I should have mentioned that I also set If So maybe what I suggest here could be done if both |
|
Ah hmm, that’s a fair idea! I do want to point out in the mean time that permalink objects (added for serverless but don’t require serverless) solve this problem already: https://www.11ty.dev/docs/plugins/serverless/#step-3-use-a-permalink-object Templates only render with a classic Code:
|
permalink: false and eleventyExcludeFromCollections: true
|
|
@zachleat thanks for your comment above about how to really, really disable outputting the file. Personally, if this is the mechanism to fully remove a page from outputting (to collections etc) - this might be helpful to have documented in the Collections page or Permalink page. I, like a few others, wanted a "draft" mechanism, but ran into issues with I ended up with the following, based on @pdehaan's example here.: module.exports = {
layout: 'base',
tags: 'documentation',
eleventyComputed: {
permalink: (data) => {
if (data.draft && process.env.NODE_ENV === 'production') {
return {}; // <-- really, really remove from build
}
return data.permalink !== '' ? data.permalink : `/${data.page.fileSlug}/`;
},
eleventyExcludeFromCollections: (data) => {
if (data.draft && process.env.NODE_ENV === 'production') {
return true;
}
return data.eleventyExcludeFromCollections;
},
},
}; |
While trying to identify the source of issue #1696, I discovered that templates/layouts are evaluated even if their
permalinkis set tofalse, either directly in the source file Front Matter or via the data cascade, including_data/eleventyComputed.js.Here's a reduced test case, in the
computed-permalink-falsebranch of this repository:https://github.com/nhoizey/11ty-reduced-test-cases/tree/computed-permalink-false
If the template/layout tries to use
{{ page.outputPath }}or{{ page.url }}with filters built for strings, there will be an error, as these have afalsevalue.For example, I had to replace
{% if 'archives' in page.url %}with{% if page.url != false and 'archives' in page.url %}because{% if 'archives' in page.url %}gives an error when{{ page.url }}equalsfalse.As no page will be generated, it might be better not to parse the content of the source file, apart from the Front Matter, once the data cascade has been completed, if
permalinkis evaluated tofalse.It might even make the full build faster.
The text was updated successfully, but these errors were encountered: