From 115ff705cccd6ebebcd62be9968602551785f878 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 1 Apr 2020 09:07:15 -0500 Subject: [PATCH] Fixes #1061 --- src/ComputedData.js | 10 +++++-- test/TemplateTest.js | 26 +++++++++++++++++++ .../eleventyComputed/permalink-simple.njk | 6 +++++ .../stubs/eleventyComputed/permalink-slug.njk | 5 ++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/stubs/eleventyComputed/permalink-simple.njk create mode 100644 test/stubs/eleventyComputed/permalink-slug.njk diff --git a/src/ComputedData.js b/src/ComputedData.js index 9d62f5e01..ead57d251 100644 --- a/src/ComputedData.js +++ b/src/ComputedData.js @@ -1,5 +1,6 @@ const lodashGet = require("lodash/get"); const lodashSet = require("lodash/set"); +const debug = require("debug")("Eleventy:ComputedData"); const DependencyGraph = require("dependency-graph").DepGraph; class ComputedData { @@ -51,7 +52,6 @@ class ComputedData { let graph = new DependencyGraph(); let proxyData = this.getProxyData(); - for (let key of this.computedKeys) { let computed = lodashGet(this.computed, key); graph.addNode(key); @@ -65,9 +65,15 @@ class ComputedData { } // squelch console logs for this fake proxy data pass 😅 + let output; let savedLog = console.log; console.log = () => {}; - let output = await computed(proxyData); + try { + // Mitigation for #1061, errors on the first pass shouldn’t fail the whole thing. + output = await computed(proxyData); + } catch (e) { + debug("Computed Data first pass data resolution error: %o", e); + } console.log = savedLog; let vars = this.findVarsInOutput(output); diff --git a/test/TemplateTest.js b/test/TemplateTest.js index 69d099e15..74d9d9a22 100644 --- a/test/TemplateTest.js +++ b/test/TemplateTest.js @@ -2082,6 +2082,32 @@ test("eleventyComputed permalink", async t => { t.is(data.dependsOnPage, "depends:/haha-value1.html"); }); +test("eleventyComputed simple permalink", async t => { + let tmpl = new Template( + "./test/stubs/eleventyComputed/permalink-simple.njk", + "./test/stubs/", + "./dist" + ); + let templates = await tmpl.getTemplates(await tmpl.getData()); + let data = templates[0].data; + t.is(data.page.url, "/haha-value1.html"); + t.is(data.page.outputPath, "./dist/haha-value1.html"); + t.is(data.permalink, "haha-value1.html"); +}); + +test("eleventyComputed permalink using slug", async t => { + let tmpl = new Template( + "./test/stubs/eleventyComputed/permalink-slug.njk", + "./test/stubs/", + "./dist" + ); + let templates = await tmpl.getTemplates(await tmpl.getData()); + let data = templates[0].data; + t.is(data.page.url, "/haha-this-is-a-string.html"); + t.is(data.page.outputPath, "./dist/haha-this-is-a-string.html"); + t.is(data.permalink, "haha-this-is-a-string.html"); +}); + test("eleventyComputed js front matter (function)", async t => { let tmpl = new Template( "./test/stubs/eleventyComputed/second.njk", diff --git a/test/stubs/eleventyComputed/permalink-simple.njk b/test/stubs/eleventyComputed/permalink-simple.njk new file mode 100644 index 000000000..039f63910 --- /dev/null +++ b/test/stubs/eleventyComputed/permalink-simple.njk @@ -0,0 +1,6 @@ +--- +key1: value1 +eleventyComputed: + permalink: "haha-{{key1}}.html" +--- +hi:{{ key2 }} \ No newline at end of file diff --git a/test/stubs/eleventyComputed/permalink-slug.njk b/test/stubs/eleventyComputed/permalink-slug.njk new file mode 100644 index 000000000..544853307 --- /dev/null +++ b/test/stubs/eleventyComputed/permalink-slug.njk @@ -0,0 +1,5 @@ +--- +key1: "This is a string" +eleventyComputed: + permalink: "haha-{{key1 | slug}}.html" +--- \ No newline at end of file