-
-
Notifications
You must be signed in to change notification settings - Fork 471
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
no index.html is generated at _site #2928
Comments
I would suggest that it is not a bug, but is expected behavior. It appears that you're asking Eleventy to paginate a collection that is empty. As you note, the result is no output of the index.html file. Two things come to mind:
I hope this helps. |
I agree that it's not a bug, but this is probably what you're looking for: https://www.11ty.dev/docs/pagination/#generating-an-empty-results-page |
@bobmonsour Thanks for your reply.
Don't you think it would be better to have some kind of warning at least?
I understand your suggestion about adding code to check that the collection is not empty and, if so, output an error message, and appreciate it. But to me, this behaivor should be included by default, without me having to add anything. I appreacite if you can share and discuss my concern with the group on eleventy. I think my suggestion is pretty reasonable. @pdehaan thank you. Having a 404 page is better that what I have right now, but anyway, links could be pointing to that page, that will end on a 404. Not good. |
The ---
# src/index.njk
title: Available Products
pagination:
data: collections.posts
size: 3
alias: posts
reverse: true
generatePageOnEmptyData: true
---
{% if posts.length == 0 %}
<h1>NO POSTS FOUND</h1>
{% else %}
<div class="card-grid">
{% for post in posts %}
<div class="card">
<header>
<h1>{{ post.data.title}}</h1>
</header>
</div>
{% endfor %}
</div>
{% endif %} // eleventy.config.js
/**
* @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
* @returns {ReturnType<import("@11ty/eleventy/src/defaultConfig")>}
*/
module.exports = function (eleventyConfig) {
// Create an empty collection.
eleventyConfig.addCollection("posts", collectionApi => []);
return {
dir: {
input: "src",
output: "www",
}
};
}; OUTPUT> eleventy
[11ty] Writing www/index.html from ./src/index.njk
[11ty] Wrote 1 file in 0.03 seconds (v2.0.1) <!-- www/index.html -->
<h1>NO POSTS FOUND</h1> If I comment out > eleventy
[11ty] Wrote 0 files in 0.02 seconds (v2.0.1) Relevant PRs with more discussion/context are #2208 and #1698. |
@pdehaan Thank you very much. Really appreaciate your suggestion. I like that solution. |
Thank you @pdehaan for finding a much better answer than my lame suggestion
to code around it. I was trying to be helpful. Had I dug into the docs a
bit more, I might have discovered your better solution. Apologies for going
off half-cocked.
…On Sun, May 14, 2023 at 8:04 AM Bruno Sastre ***@***.***> wrote:
@pdehaan <https://github.com/pdehaan> Thank you very much. Really
appreaciate your suggestion. I like that solution.
How did you manage to insert stylized colored code here?
—
Reply to this email directly, view it on GitHub
<#2928 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABAWW5GCCBZBOT2RJCEY4DXGDX6FANCNFSM6AAAAAAX26VRRI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@bobmonsour It's a very new API and actually the first time I've used it. And your solution is still excellent and valid, and I 💯 dig the idea of using the |
You can just add a language after the three backticks like so:
If you write this:
It will look like this: console.log("Hello, world!") |
console.log('Thank you!'); |
@bobmonsour I also like your solution about outputing an error message if the collection is empty. However, I would like to make this a global rule/check, that would work for every collection that I currently have, or may have later. For that purpose, I think the place for verification would be as an example:
|
@bsastregx You could try overriding +const assert = require("node:assert/strict");
/**
* @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
* @returns {ReturnType<import("@11ty/eleventy/src/defaultConfig")>}
*/
module.exports = function (eleventyConfig) {
+ eleventyConfig.addCollection("all", function (collectionApi) {
+ const posts = collectionApi.getAllSorted();
+ assert.equal(posts.length, 5, "Unexpected number of pages");
+ return posts;
+ });
return {
dir: {
input: "src",
output: "www",
}
};
}; |
@pdehaan Thank you! I will try that out later. I'm at the office right now. |
|
Operating system
Windows 10
Eleventy
2.0.1
Describe the bug
Not sure if this is a bug.
I have the following index.njk at the root of my project:
(the nunjuck logic it doesn't really matter, I think, so don't waste time paying attention to it. Keep reading..)
Then, I have four posts, at /posts:
They are all the same in structure, prety simple:
When I build, _site/index.html displays the posts, everything working fine.
BUT, If I remove "posts" from "tags" in the front matter of every post (the four of them), and build, no index.html is generated under _site, and I have no errors. The end result is that when I go to the homepage, I get
Cannot GET /
I think having no errors at all at the console, is PRETTY dangerous. Imagine that there is only one post left with "posts" tag in it, and I remove it, or change the tag for another one... then I will get an inexsitent index.html with no warning at all from eleventy.
Reproduction steps
Expected behavior
I guess to have some kind of error in the console, since I am trying to do a loop of posts, and I have none.
Reproduction URL
No response
Screenshots
The text was updated successfully, but these errors were encountered: