Skip to content

Commit

Permalink
Fixes #1061
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Apr 1, 2020
1 parent 9976deb commit 115ff70
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ComputedData.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions test/TemplateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions test/stubs/eleventyComputed/permalink-simple.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
key1: value1
eleventyComputed:
permalink: "haha-{{key1}}.html"
---
hi:{{ key2 }}
5 changes: 5 additions & 0 deletions test/stubs/eleventyComputed/permalink-slug.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
key1: "This is a string"
eleventyComputed:
permalink: "haha-{{key1 | slug}}.html"
---

0 comments on commit 115ff70

Please sign in to comment.