-
-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to add eleventyImportCollections, fixes #975
- Loading branch information
Showing
5 changed files
with
222 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const test = require("ava"); | ||
const TemplateMap = require("../../../src/TemplateMap"); | ||
const TemplateConfig = require("../../../src/TemplateConfig"); | ||
|
||
const getNewTemplateForTests = require("../../_getNewTemplateForTests"); | ||
|
||
function getNewTemplate(filename, input, output, eleventyConfig) { | ||
return getNewTemplateForTests( | ||
filename, | ||
input, | ||
output, | ||
null, | ||
null, | ||
eleventyConfig | ||
); | ||
} | ||
|
||
test("Get ordered list of templates", async (t) => { | ||
let eleventyConfig = new TemplateConfig(); | ||
let tm = new TemplateMap(eleventyConfig); | ||
|
||
// These two templates are add-order-dependent | ||
await tm.add( | ||
getNewTemplate( | ||
"./test/_issues/975/post.md", | ||
"./test/_issues/975/", | ||
"./test/_issues/975/_site", | ||
eleventyConfig | ||
) | ||
); | ||
|
||
await tm.add( | ||
getNewTemplate( | ||
"./test/_issues/975/another-post.md", | ||
"./test/_issues/975/", | ||
"./test/_issues/975/_site", | ||
eleventyConfig | ||
) | ||
); | ||
|
||
// This template should always be last | ||
await tm.add( | ||
getNewTemplate( | ||
"./test/_issues/975/index.md", | ||
"./test/_issues/975/", | ||
"./test/_issues/975/_site", | ||
eleventyConfig | ||
) | ||
); | ||
|
||
let [first, second, third, fourth] = tm.getFullTemplateMapOrder(); | ||
t.deepEqual( | ||
first.filter((entry) => !entry.startsWith(TemplateMap.tagPrefix)), | ||
[ | ||
"./test/_issues/975/post.md", | ||
"./test/_issues/975/another-post.md", | ||
"./test/_issues/975/index.md", | ||
] | ||
); | ||
}); | ||
|
||
test("Get ordered list of templates (reverse add)", async (t) => { | ||
let eleventyConfig = new TemplateConfig(); | ||
let tm = new TemplateMap(eleventyConfig); | ||
|
||
// This template should always be last | ||
await tm.add( | ||
getNewTemplate( | ||
"./test/_issues/975/index.md", | ||
"./test/_issues/975/", | ||
"./test/_issues/975/_site", | ||
eleventyConfig | ||
) | ||
); | ||
|
||
// These two templates are add-order-dependent | ||
await tm.add( | ||
getNewTemplate( | ||
"./test/_issues/975/another-post.md", | ||
"./test/_issues/975/", | ||
"./test/_issues/975/_site", | ||
eleventyConfig | ||
) | ||
); | ||
|
||
await tm.add( | ||
getNewTemplate( | ||
"./test/_issues/975/post.md", | ||
"./test/_issues/975/", | ||
"./test/_issues/975/_site", | ||
eleventyConfig | ||
) | ||
); | ||
|
||
let [first, second, third, fourth] = tm.getFullTemplateMapOrder(); | ||
t.deepEqual( | ||
first.filter((entry) => !entry.startsWith(TemplateMap.tagPrefix)), | ||
[ | ||
"./test/_issues/975/another-post.md", | ||
"./test/_issues/975/post.md", | ||
"./test/_issues/975/index.md", | ||
] | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
tags: | ||
- post | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
eleventyImportCollections: | ||
- post | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
tags: | ||
- post | ||
--- |