Skip to content

Commit

Permalink
InputPathToUrl plugin simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Apr 7, 2024
1 parent 2cf8aca commit 15c36a8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ charset = utf-8
[*.yml]
indent_style = space

[/test/**/*]
indent_style = space

[/test/stubs*/**]
insert_final_newline = false
trim_trailing_whitespace = false
12 changes: 2 additions & 10 deletions src/Plugins/InputPathToUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ function FilterPlugin(eleventyConfig) {
contentMap = inputPathToUrl;
});

let inputDir;
eleventyConfig.on("eleventy.directories", function ({ input }) {
inputDir = input;
});

eleventyConfig.addFilter("inputPathToUrl", function (filepath) {
if (!contentMap) {
throw new Error("Internal error: contentMap not available for `inputPathToUrl` filter.");
}

let inputDir = eleventyConfig.directories.input;
filepath = normalizeInputPath(filepath, inputDir, contentMap);

let urls = contentMap[filepath];
Expand All @@ -63,15 +59,11 @@ function TransformPlugin(eleventyConfig, defaultOptions = {}) {
contentMap = inputPathToUrl;
});

let inputDir;
eleventyConfig.on("eleventy.directories", function ({ input }) {
inputDir = input;
});

eleventyConfig.htmlTransformer.addUrlTransform(opts.extensions, function (filepathOrUrl) {
if (!contentMap) {
throw new Error("Internal error: contentMap not available for the `pathToUrl` Transform.");
}
let inputDir = eleventyConfig.directories.input;
filepathOrUrl = normalizeInputPath(filepathOrUrl, inputDir, contentMap);

let urls = contentMap[filepathOrUrl];
Expand Down
4 changes: 3 additions & 1 deletion src/TemplateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ class TemplateConfig {

// Add the ProjectDirectories instance to the user accessible config.
if (this.directories) {
mergedConfig.directories = this.directories.getUserspaceInstance();
let dirs = this.directories.getUserspaceInstance();
mergedConfig.directories = dirs;
this.userConfig.directories = dirs;
}

// Delay processing plugins until after the result of localConfig is returned
Expand Down
2 changes: 0 additions & 2 deletions src/TemplateRender.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { TemplatePath } from "@11ty/eleventy-utils";

import EleventyBaseError from "./Errors/EleventyBaseError.js";
import EleventyExtensionMap from "./EleventyExtensionMap.js";
import CustomEngine from "./Engines/Custom.js";
Expand Down
5 changes: 0 additions & 5 deletions test/InputPathToUrlPluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ test("Using the transform (and the filter too)", async (t) => {
},
});

await elev.initializeConfig();

elev.setIsVerbose(false);
elev.disableLogger();

Expand All @@ -73,7 +71,6 @@ test("Using the filter", async (t) => {
// FilterPlugin is available in the default config.
configPath: false,
});
await elev.initializeConfig();

elev.setIsVerbose(false);
elev.disableLogger();
Expand All @@ -98,7 +95,6 @@ test("Using the transform and the base plugin", async (t) => {
eleventyConfig.addPlugin(HtmlBasePlugin);
},
});
await elev.initializeConfig();

elev.setIsVerbose(false);
elev.disableLogger();
Expand All @@ -123,7 +119,6 @@ test("Using the transform and the base plugin, reverse order", async (t) => {
eleventyConfig.addPlugin(TransformPlugin);
},
});
await elev.initializeConfig();

elev.setIsVerbose(false);
elev.disableLogger();
Expand Down
8 changes: 4 additions & 4 deletions test/TemplateRenderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { getTemplateConfigInstance } from "./_testHelpers.js";

async function getNewTemplateRender(name, inputDir) {
let eleventyConfig = await getTemplateConfigInstance({
dir: {
input: inputDir
}
});
dir: {
input: inputDir
}
});

let tr = new TemplateRender(name, eleventyConfig);
tr.extensionMap = new EleventyExtensionMap([], eleventyConfig);
Expand Down

0 comments on commit 15c36a8

Please sign in to comment.