Skip to content

Commit

Permalink
Merge branch 'pr/3277'
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 11, 2024
2 parents 7bfed71 + 4db7a36 commit ac3770e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"moo": "^0.5.2",
"node-retrieve-globals": "^6.0.0",
"nunjucks": "^3.2.4",
"p-map": "^7.0.2",
"please-upgrade-node": "^3.2.0",
"posthtml": "^0.16.6",
"posthtml-match-helper": "^2.0.2",
Expand Down
46 changes: 26 additions & 20 deletions src/TemplateMap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DepGraph as DependencyGraph } from "dependency-graph";
import { isPlainObject, TemplatePath } from "@11ty/eleventy-utils";
import debugUtil from "debug";
import os from "node:os";
import pMap from "p-map";

import TemplateCollection from "./TemplateCollection.js";
import EleventyErrorUtil from "./Errors/EleventyErrorUtil.js";
Expand Down Expand Up @@ -540,31 +542,35 @@ class TemplateMap {
// Note that empty pagination templates will be skipped here as not renderable
let filteredMap = orderedMap.filter((entry) => entry.template.isRenderable());

for (let map of filteredMap) {
if (!map._pages) {
throw new Error(`Internal error: _pages not found for ${map.inputPath}`);
}

// IMPORTANT: this is where template content is rendered
try {
for (let pageEntry of map._pages) {
pageEntry.templateContent =
await pageEntry.template.renderPageEntryWithoutLayout(pageEntry);
await pMap(
filteredMap,
async (map) => {
if (!map._pages) {
throw new Error(`Internal error: _pages not found for ${map.inputPath}`);
}
} catch (e) {
if (EleventyErrorUtil.isPrematureTemplateContentError(e)) {
usedTemplateContentTooEarlyMap.push(map);

// Reset cached render promise
// IMPORTANT: this is where template content is rendered
try {
for (let pageEntry of map._pages) {
pageEntry.template.resetCaches({ render: true });
pageEntry.templateContent =
await pageEntry.template.renderPageEntryWithoutLayout(pageEntry);
}
} catch (e) {
if (EleventyErrorUtil.isPrematureTemplateContentError(e)) {
usedTemplateContentTooEarlyMap.push(map);

// Reset cached render promise
for (let pageEntry of map._pages) {
pageEntry.template.resetCaches({ render: true });
}
} else {
throw e;
}
} else {
throw e;
}
}
debugDev("Added this.map[...].templateContent, outputPath, et al for one map entry");
}
debugDev("Added this.map[...].templateContent, outputPath, et al for one map entry");
},
{ concurrency: os.availableParallelism() },
);

for (let map of usedTemplateContentTooEarlyMap) {
try {
Expand Down

0 comments on commit ac3770e

Please sign in to comment.