11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.94k stars 491 forks source link

Two separate collections: problem to output its own tags for each one #1951

Closed rocc-o closed 3 years ago

rocc-o commented 3 years ago

I have two separate collections and I want in each directory the tags output like this: /sights/tags/(all tags for sights); /sounds/tags/(all tags for sounds).

But instead I get: /sights/tags/(all tags for sights and sounds); /sounds/tags/(all tags for sounds and sights).

It seems that permalink, as I have it, cannot use dynamic data (I get errors). So I tried Computed data to define the permalink but I can't figure it out how to do it porperly; even tried filters and I failed miserably.

I have a repo here: https://github.com/rocc-o/raw-test-git

If anyone could suggest me how to solve this I would be very grateful. Thanks.

pdehaan commented 3 years ago

@rocc-o,

I'm not sure I'm following which files in the repo I'm supposed to be looking at, but what about converting the tagsList from a custom collection to a filter?

  eleventyConfig.addFilter("tagsList", (arr = []) => {
    const tagsSet = new Set();
    arr.forEach((item) => item.data.tags?.forEach((tag) => tagsSet.add(tag)));
    return [...tagsSet].sort((b, a) => b.localeCompare(a));
  });

That way you can specify the specific collection you want a tag list for (currently I think it works as-designed since you're using {% for tag in collections.tagsList %} which uses collectionApi.getAll() which is why it's merging sights+sounds (if I'm reading it all correctly).

<p>
  <!-- PROBLEM -->
  <!-- outputs tags. Should be all tags for collection.sounds only, but outputs also all collections.sights tags - I don't want this to happen and I have to find a solution -->  
{% for tag in collections.sounds | tagsList %}
    <a href="/sounds/tags/{{ tag | slug }}" class="tags">{{tag}}</a>
{% endfor %}
</p>

Not sure if that's correct or what you wanted, but the site builds correctly with the following output:

npm run build

> raw-test-git@1.0.0 build /private/tmp/raw-test-git
> eleventy

Writing _site/README/index.html from ./README.md.
Writing _site/sounds/index.html from ./sounds/index.njk.
Writing _site/sounds/tags/audio-three-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/index.html from ./sights/index.njk.
Writing _site/sights/tags/audio-three-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/1/index.html from ./sounds/index.njk.
Writing _site/sounds/tags/audio-test/index.html from ./sounds/tags.njk.
Writing _site/sights/1/index.html from ./sights/index.njk.
Writing _site/sights/tags/audio-test/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-tag-3/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-tag-3/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-one-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-one-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-promo/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-promo/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-tag-1/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-tag-1/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/video-one-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/video-one-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/ident-1-video/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/ident-1-video/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/one-video-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/one-video-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/video-four-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/video-four-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/promo-video/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/promo-video/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/a-video-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/a-video-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-four-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-four-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-check/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-check/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-tag-4/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-tag-4/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-two-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-two-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-skit/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-skit/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/audio-tag-2/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/audio-tag-2/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/video-three-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/video-three-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/docu-video/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/docu-video/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/another-video-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/another-video-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/video-two-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/video-two-tag/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/ident-video/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/ident-video/index.html from ./sights/tags.njk.
Writing _site/sounds/tags/this-video-tag/index.html from ./sounds/tags.njk.
Writing _site/sights/tags/this-video-tag/index.html from ./sights/tags.njk.
Writing _site/index.html from ./index.njk.
Writing _site/sounds/audio-three/index.html from ./sounds/audio-three.njk.
Writing _site/sounds/audio-one/index.html from ./sounds/audio-one.njk.
Writing _site/sights/video-one/index.html from ./sights/video-one.njk.
Writing _site/sights/video-four/index.html from ./sights/video-four.njk.
Writing _site/sounds/audio-four/index.html from ./sounds/audio-four.njk.
Writing _site/sounds/audio-two/index.html from ./sounds/audio-two.njk.
Writing _site/sights/video-three/index.html from ./sights/video-three.njk.
Writing _site/sights/video-two/index.html from ./sights/video-two.njk.

Wrote 62 files in 0.41 seconds (6.6ms each, v0.12.1)

I submitted https://github.com/rocc-o/raw-test-git/pull/1 which hopefully has a bit better context.

rocc-o commented 3 years ago

@pdehaan

I've tried your changes but I still get all tags mixed: /sights/tags/(all tags for sights and sounds); /sounds/tags/(all tags for sounds and sights).

And instead I wanted Eleventy to build: /sights/tags/(all tags for sights); /sounds/tags/(all tags for sounds).

Furthermore, with this change the tags (even mixed) are no longer outputed in /sounds/tags.njk" and /sights/tags.njk.

So I tried to add "data: collections.sounds" and "data: collections.sights" respectively in /sounds/tags.njk" and /sights/tags.njk, but I get the same old error due to same old problem: it seems that permalink, as I have it, cannot use dynamic data:

`` PS C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims> npx @11ty/eleventy --serve Problem writing Eleventy templates: (more in DEBUG output)

Having trouble rendering njk template ./sights/tags.njk

TemplateContentRenderError was thrown

(./sights/tags.njk) Error: slugify: string argument expected

Template render error was thrown: Template render error: (./sights/tags.njk) Error: slugify: string argument expected at Object._prettifyError (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\nunjucks\src\lib.js:36:11) at C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\nunjucks\src\environment.js:563:19 at Template.root [as rootRenderFunc] (eval at _compile (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\nunjucks\src\environment.js:633:18), :19:3) at Template.render (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\nunjucks\src\environment.js:552:10) at C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\Engines\Nunjucks.js:236:14 at new Promise () at C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\Engines\Nunjucks.js:235:14 at Template.render (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\TemplateContent.js:199:28) at async Template._getLink (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\Template.js:130:26) at async Template.getOutputLink (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\Template.js:161:16) Copied 93 files / Wrote 0 files in 0.39 seconds (v0.12.1) Watching… [Browsersync] Access URLs:

   Local: http://localhost:8080
External: http://192.168.1.8:8080

      UI: http://localhost:3001

UI External: http://localhost:3001

[Browsersync] Serving files from: _ ``

pdehaan commented 3 years ago

New PR at https://github.com/rocc-o/raw-test-git/pull/2/files?diff=split&w=1

The Template render error: (./sights/tags.njk) Error: slugify: string argument expected error usually means that you are trying to slug something that isn't a string (like an object or usually undefined).

rocc-o commented 3 years ago

@pdehaan

something strange is happening.

With your changes it works perfectly, tags are not mixed up anyomre and all tags outputs are fine.

But, as soon as I use my own tags on each article, e.g.:

in /sights/video-one.njk

tags:

instead of your tags:

tags:

I get:

PS C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims> npx @11ty/eleventy --serve

Problem writing Eleventy templates: (more in DEBUG output)

Output conflict: multiple input files are writing to _site/sights/tags/documentary/index.html. Use distinct permalink values to resolve this conflict.

  1. ./sights/tags.njk
  2. ./sights/tags.njk

DuplicatePermalinkOutputError was thrown: (Repeated output has been truncated…) at TemplateMap.checkForDuplicatePermalinks (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\TemplateMap.js:547:13) at TemplateMap.cache (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\TemplateMap.js:308:10) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async TemplateWriter._createTemplateMap (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\TemplateWriter.js:170:5) at async TemplateWriter.writeTemplates (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\TemplateWriter.js:203:5) at async TemplateWriter.write (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\TemplateWriter.js:254:25) at async Eleventy.write (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\Eleventy.js:743:13) at async Eleventy.watch (C:\Users\ricca\OneDrive\Documenti\Websites\rawriddims\node_modules\@11ty\eleventy\src\Eleventy.js:650:5) Copied 91 files / Wrote 0 files in 0.70 seconds (v0.12.1) Watching… [Browsersync] Access URLs:

   Local: http://localhost:8080
External: http://192.168.1.8:8080

      UI: http://localhost:3001

UI External: http://localhost:3001

[Browsersync] Serving files from: _site

Could it be because I'm using same tag "documentary" in different articles? But I need to gather all documentaries under tag "documentary", for example, and also for some other common tags.

pdehaan commented 3 years ago

Duplicate permalink error from same page… My guess is that it might be something like one page uses “documentary” and another uses “Documentary” where the case is different but they resolve to the same slug. Just a guess, but worth a check. Apart from that, I’d need to check your repo and see what your dynamic pagination permalink key is for sights/tags.njk is to see what else might be colliding.

rocc-o commented 3 years ago

Your guess is right, sir! Capital D in one documentary tag it was. Now it works properly, except on /sounds/index.njk there's no output for /sounds/tags/(any-tag)/ (only in /sounds/index.njk; /sights/index.njk is fine) immagine

pdehaan commented 3 years ago

If you push your latest code to the GitHub repo, I can take a look later today.

rocc-o commented 3 years ago

I hope i did it correctly - I'm new on Github - I've done: Approve. Submit feedback and approve merging these changes. Whatever, and finally I've been able to push the latest code to my repo, it seems. I can see all files updated on my repo now.

pdehaan commented 3 years ago

Yeah, I think you just approved the changes from my PR, but not merged them. You'll need to click the green merge button, or just push your local version of the repo to the main/master branch and I can repull it locally.

Or if the latest/only changes are what I had in that approved PR, I can just try that locally and see if I can reproduce (but probably better to use your front matter data and content, plus a good exercise in git/GitHub).

rocc-o commented 3 years ago

@pdehaan

I think I did push my local version of the repo to the main/master branch with the latest changes from your "A few random tweaks #2" plus my own tags to reproduce the latest problem: on /sounds/index.njk there's no output for /sounds/tags/(any-tag)/ - and anyway I've changed the "Documentary" tag which was causing the previous problem from uppercase to lowercase "documentary". I can see it updated on my repo now. I don't see any green merge button right now. I will have to come back tomorrow to make some exercise in git anyway - I'm starting now to understand how it works. if you need me to do anything else please just let me know and tomorrow I will dedicate myself full time. Thanks!

pdehaan commented 3 years ago

Here's what I see when I build locally and look at a /sounds/tags/{{tag}}/ page:

localhost_8080_sounds_tags_mixtape_

rocc-o commented 3 years ago

This morning I build locally and the missing output at /sounds/tags/{{tag}}/ page was gone. I suppose I had this problem yesterday because I did not delete sights and sounds directories in _site output before building and perhaps it was a sum of errors, maybe, I really don't know. Anyway, this morning I ran a fresh build and everything works properly now.

I have some questions, please:

1) in https://github.com/rocc-o/raw-test-git/pull/2 I see a list of "Conflicting files" on all files that have been modified, except /sounds/index.njk. What does it mean?

2) in https://github.com/rocc-o/raw-test-git/pull/1

.eleventy.js

  eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
    if (idx < 0) {
      return arr.slice(idx);
    }
    return arr.slice(0, idx);
  });

You write: "You can probably ignore this...". I removed it. Is it ok? I've tried some more builds and no problem occurs at this moment.

3) Do I have to write comments in Nunjucks files only like this {# some comment #} ?

Thank you so much Peter for your great help, I was totally lost.

rocc-o commented 3 years ago

Sorry Peter, it's me again

the missing output is now happening at /sights/index.html I did delete sights and sounds directories in _site output to avoid any possible error and ran again builds several times but the problem persists. I did not change anything since this morning when it was working fine.

I have updated my repo, but I did not change anything from your previous modifications, I've just changed the index.njk in my repo which I'm not running here locally and so it cannot be the problem. Locally I have an index.njk with html code only .

Here's the _site html output for /sights/index.njk where you can see there's no output data into the last part of html code for item.date; item.data.title; item.data.details. There's only the item.url outputted and working at the beginning :

                        <article class="card">
                            <div class="article-cards-item">
                                <a href="/sights/tags/sun-ra/">
                                    <div class="article-cards-img-cntr">
                                        <picture>
                                            <source sizes="(min-width: 1760px) 335px, (min-width: 1280px) calc(16.96vw + 40px), (min-width: 1040px) calc(28.64vw - 17px), (min-width: 768px) 42.5vw, 85vw" srcset="544w, 638w, 690w, 852w" type="image/webp"><img sizes="(min-width: 1760px) 335px, (min-width: 1280px) calc(16.96vw + 40px), (min-width: 1040px) calc(28.64vw - 17px), (min-width: 768px) 42.5vw, 85vw" srcset="544w, 638w, 690w, 852w" src="" width="852"
                                                height="480" alt="" loading="lazy"></picture>
                                    </div>
                                    <p class="article-cards-date"><time datetime=""></time></p>
                                    <h2 class="article-cards-title"></h2>
                                    <p class="article-cards-details"></p>
                                </a>
                            </div>
                        </article>

immagine

rocc-o commented 3 years ago

Sorry again, I've noticed that when I comment out the "head filter" in eleventy.js the problem does not occurs anymore:

// (?) You can probably ignore this. I think it was from the index.njk and was throwing errors saying there wasn't a "head" filter,
// so I took a random guess. But then ended up using Nunjucks comments to comment out those code blocks anyways.
// https://github.com/rocc-o/raw-test-git/pull/1
//  eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
//    if (idx < 0) {
//      return arr.slice(idx);
//    }
//    return arr.slice(0, idx);
//  });

I'm running now more builds ad libitum to see if some magic happens. Hopefully that was the problem.

pdehaan commented 3 years ago
  1. in A few random tweaks rocc-o/raw-test-git#2 I see a list of "Conflicting files" on all files that have been modified, except /sounds/index.njk. What does it mean?

That means that a bunch of files changed in the target branch (main/master) from the time that I submitted the PR and now. So if you merged that PR somehow, you might overwrite newer changes. In order to fix that, I'd need to modify my PR to sync with the latest changes and then resolve any git conflicts. If your code is all working in the main/master branch, we can just ignore/close those PRs.


  1. in A few random tweaks rocc-o/raw-test-git#1

    .eleventy.js

  eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
    if (idx < 0) {
      return arr.slice(idx);
    }
    return arr.slice(0, idx);
  });

You write: "You can probably ignore this...". I removed it. Is it ok? I've tried some more builds and no problem occurs at this moment.

Yeah, I think this was an issue w/ index.njk (or maybe the README.md file) where it was referencing some head filter which wasn't in the .eleventy.js file, so I took a stab at implementing it. Then I realized which code was calling the filter and then just commented that code out.


  1. Do I have to write comments in Nunjucks files only like this {# some comment #} ?

You don't HAVE to, but there are some subtle "gotchas" with comments sometimes. I think of Nunjucks as a preprocessor. So if you do HTML style <!-- ... --> comments, Nunjucks will still process all that content to your page and just hide it in the HTML output. Can be useful for debugging in some cases. But if you do Nunjucks style {# ... #} comments, Nunjucks won't try processing any of that and it won't be rendered into the output file. This was the head comment I was making earlier. Since the code was in an HTML comment, Nunjucks was still processing those tags and looking for a filter that didn't exist and was throwing errors, so I switched to Nunjucks comments since the code in question was more an internal discussion and TODOs.

pdehaan commented 3 years ago

If you're getting empty output, you might need to confirm which collection you are looping over. Remember, your custom sightsTagsList collection is only an array of tag names, not actual posts. So you might need to do something like this:

diff --git a/index.njk b/index.njk
index 474a758..c3aff02 100644
--- a/index.njk
+++ b/index.njk
@@ -14,17 +14,12 @@ eleventyNavigation:

 <h2>Latest articles in Sights</h2>
 {# START articles #}
-    {% set postslist = collections.sightsTagsList | head(-4) %}
-    {% set postslistCounter = collections.sightsTagsList | length %}
+    {% set postListItems = collections.sights | head(-4) %}
     {% include "partials/components/post-list.njk" %}
 {# END articles #}

-
 <h2>Latest articles in Sounds</h2>
 {# START articles #}
-    {% set postslist = collections.soundsTagsList | head(-4) %}
-    {% set postslistCounter = collections.soundsTagsList | length %}
+    {% set postListItems = collections.sounds | head(-4) %}
     {% include "partials/components/post-list.njk" %}
 {# END articles #}
rocc-o commented 3 years ago

Thanks Peter, I will look this matter of Latest post later, because now I have that missing output problem I was mentioning before keeping coming: After several builds, made just for testing, without touching any code at all, I get the missing output sometimes in /sights/index.njk and sometimes in /sounds/index.njk. Now it's happening in /sights/index.njk, before in /sounds/index.njk. I really have no clue. The strange thing - if can be of any help - is that in my _site output in /sights/ directory (the one which is having this problem right now) I see 7 pagination folders when it should be less as there are only a few posts . In fact, in /sounds/ directory which is outputting correctly at this moment I see just 2 pagination folders. The only thing causing some problem I can think of are that html comments I still have in some article pages - I'm going to change them in Nunjack comments as soon as possible. Could be that? PS unbelievable, I just made right now another build for test and the problem is gone! And I did not touch a thing. I will keep making more builds because I've noticed that after several the problem is back.

pdehaan commented 3 years ago

Oh interesting. I think I saw that once where it wasn't outputting the title and stuff, but then it disappeared after a rebuild and I don't remember seeing it again. I figured it was just I didn't save one of my templates while debugging. But not sure why that would ever be intermittently rendering.

I'll take another look at sights/index.njk and see if anything looks curious.

pdehaan commented 3 years ago

OK, this is weird. Sometimes it renders 2 pages, sometimes 8. I think its semi-related to the pagination of the tags as well. So the intermittent issue might be due to which order the stuff gets built. If it gets to sights/tags/ pagination first, then there are 8-ish templates that it finds. If it does sights/index.njk first, then it seems to only write 2 files (because I guess there are 4 videos with a pagination size of 2).

I'm still trying to think of a workaround or explanation.


UPDATE:

I'm still playing w/ sights/index.njk, but if I rebuild the site 4-8 times with no changes, it alternates randomly between writing 34 files or 40 files.

Wrote 40 files in 0.22 seconds (5.5ms each, v0.12.1)
...
Wrote 34 files in 0.24 seconds (7.1ms each, v0.12.1)

When it builds 34 files, it seems to work as expected. When it builds 40 files, it seems to include ./sights/tags/* pages and render some empty blocks (presumably because the frontmatter in tags pages doesn't have the expected fields). But looking at the random paginated _site/sights/5/index.html file, I do see this state which I think proves the theory:

<!-- this is a list of posts which serves the pagination and tag overview pages -->
<!-- START articles -->
<article>
  <div>
    <a href="/sights/tags/clip/">
      <p><time datetime=""></time></p>
      <h2></h2>
      <p></p>
    </a>
  </div>
</article>
<!-- END articles -->

<!-- this is a list of posts which serves the pagination and tag overview pages -->
<!-- START articles -->
<article>
  <div>
    <a href="/sights/video-four/">
      <p><time datetime="2021-07-10">10 July, 2021</time></p>
      <h2>Video Test Four</h2>
      <p>Promo, 2020</p>
    </a>
  </div>
</article>
<!-- END articles -->

Note that the /sights/tags/clip/ has empty data, whereas /sights/video-four/ has the expected data (because it is an entry and not a tag archive page).

pdehaan commented 3 years ago

OK, maybe not ideal, but one workaround seems to be changing ./sights/tags.njk to ./sights_tags.njk so it sits outside the ./sights/ folder and doesn't get picked up by that collection.getFilteredByGlob("./sights/*.njk"); collection glob. After trying that locally I always seem to get the expected 34 files built.

rocc-o commented 3 years ago

I see. But in this way I will have a confusing site navigation. I'd rather to upload the site (directly the output _site) to github / cloudflare pages only when the build is done correctly. Also, could be possible that when I will have more articles on each directory, with pagination size let's say 8 or 12, Eleventy will builds in the expected order?

pdehaan commented 3 years ago

The site navigation doesn't change, the permalinks in the sights/sounds tags.njk files still write the files to the same place.

I don't think there is ever a guaranteed order in which eleventy pipeline builds the site. But something feels a bit strange here so I'll see if I can create a simpler test case that reproduces the error and file that as a new bug.

rocc-o commented 3 years ago

Ok, I see. Now it's 23.00 pm here in Italy. Tomorrow morning I will change into ./sights_tags.njk and ./sounds_tags.njk, run some more builds, check how many files are written each time and I will let you know. Thank you Peter.

rocc-o commented 3 years ago

Hi Peter, I've changed to ./sights_tags.njk and ./sounds_tags.njk, made several builds and each time is working properly without rendering empty blocks and it's always the same number of files built. I've noticed though that the order in which Eleventy pipeline builds the site is different each time. Please note I'm running Eleventy v0.12.1 with Node v14.16.1 on Windows 10.

rocc-o commented 3 years ago

Peter, meanwhile I'm trying your change for latest posts on homepage

     {% set postListItems = collections.sights | head(-4) %}
     {% include "partials/components/post-list.njk" %}

But i get:

File changed: index.njk
Problem writing Eleventy templates: (more in DEBUG output)
> Having trouble rendering njk template ./index.njk

`TemplateContentRenderError` was thrown
> (./index.njk)
  Error: filter not found: head
pdehaan commented 3 years ago

Sorry again, I've noticed that when I comment out the "head filter" in eleventy.js the problem does not occurs anymore:

// (?) You can probably ignore this. I think it was from the index.njk and was throwing errors saying there wasn't a "head" filter,
// so I took a random guess. But then ended up using Nunjucks comments to comment out those code blocks anyways.
// https://github.com/rocc-o/raw-test-git/pull/1
//  eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
//    if (idx < 0) {
//      return arr.slice(idx);
//    }
//    return arr.slice(0, idx);
//  });

Make sure you uncomment out that custom filter in your .eleventy.js file.

rocc-o commented 3 years ago

Yes Peter, now it works. Thank you very much for everything. Thanks to you now I begin to understand something more about SSG and Eleventy.

pdehaan commented 3 years ago

Awesome, congrats! Feel free to close this issue and we can open a new one (or use the Discussions tab) if you run into any other issues.

rocc-o commented 3 years ago

Ok 🥇