Skip to content

Commit

Permalink
A few more tests for #188
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 16, 2024
1 parent 5a65b24 commit 00285b2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ class Template extends TemplateContent {
);
}

filters = filters.map((extension) => {
if (extension.startsWith(".")) {
return extension;
}

return `.${extension}`;
});

if (!filters.some((extension) => extension === "*" || inputPath.endsWith(extension))) {
// skip
continue;
Expand Down
63 changes: 62 additions & 1 deletion test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ test("#1419: Shortcode in a permalink", async (t) => {
t.is(results[0].url, `/url-slug/`);
});

test("#188: Content preprocessing", async (t) => {
test("#188: Content preprocessing (dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", ".njk", (data, content) => {
Expand All @@ -1547,3 +1547,64 @@ test("#188: Content preprocessing", async (t) => {
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (no dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", "njk", (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});


test("#188: Content preprocessing (array, no dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", ["njk"], (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (array, dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", [".njk"], (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

0 comments on commit 00285b2

Please sign in to comment.