Skip to content

Commit

Permalink
Add support for directories methods for Eleventy Virtual Layout Tem…
Browse files Browse the repository at this point in the history
…plates #1612
  • Loading branch information
zachleat committed Jul 2, 2024
1 parent 510c336 commit f28ca21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/Util/ProjectDirectories.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ class ProjectDirectories {
}

// for a hypothetical template file
getInputPath(filePath) {
getInputPath(filePathRelativeToInputDir) {
// TODO change ~/ to project root dir
return TemplatePath.addLeadingDotSlash(
TemplatePath.join(this.input, TemplatePath.standardizeFilePath(filePath)),
TemplatePath.join(this.input, TemplatePath.standardizeFilePath(filePathRelativeToInputDir)),
);
}

Expand All @@ -274,9 +274,13 @@ class ProjectDirectories {
return TemplatePath.stripLeadingSubPath(filePathRelativeToInputDir, inputDir);
}

getLayoutPath(filePath) {
// for a hypothetical Eleventy layout file
getLayoutPath(filePathRelativeToLayoutDir) {
return TemplatePath.addLeadingDotSlash(
TemplatePath.join(this.layouts || this.includes, TemplatePath.standardizeFilePath(filePath)),
TemplatePath.join(
this.layouts || this.includes,
TemplatePath.standardizeFilePath(filePathRelativeToLayoutDir),
),
);
}

Expand Down
10 changes: 6 additions & 4 deletions test/EleventyVirtualTemplatesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ test("RSS virtual templates plugin", async (t) => {
test("Virtual templates as layouts, issue #2307", async (t) => {
let elev = new Eleventy("./test/stubs-virtual-nowrite", "./test/stubs-virtual-nowrite/_site", {
config: function (eleventyConfig) {
eleventyConfig.addTemplate("virtual.md", `# Hello`, {
layout: "virtual.html"
});
eleventyConfig.addTemplate("_includes/virtual.html", `<!-- Layout -->{{ content }}`)
eleventyConfig.addTemplate("virtual.md", `# Hello`, {
layout: "virtual.html"
});

let layoutPath = eleventyConfig.directories.getLayoutPathRelativeToInputDirectory("virtual.html");
eleventyConfig.addTemplate(layoutPath, `<!-- Layout -->{{ content }}`);
},
});

Expand Down

0 comments on commit f28ca21

Please sign in to comment.