Skip to content

Commit

Permalink
Last second rename for #84
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 9, 2024
1 parent 292f4b7 commit 85fef01
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getEleventyPackageJson, getWorkingProjectPackageJson } from "./Util/Imp
import RenderPlugin, * as RenderPluginExtras from "./Plugins/RenderPlugin.js";
import I18nPlugin, * as I18nPluginExtras from "./Plugins/I18nPlugin.js";
import HtmlBasePlugin, * as HtmlBasePluginExtras from "./Plugins/HtmlBasePlugin.js";
import { TransformPlugin as PathToUrlTransformPlugin } from "./Plugins/PathToUrl.js";
import { TransformPlugin as PathToUrlTransformPlugin } from "./Plugins/InputPathToUrl.js";

const pkg = getEleventyPackageJson();
const debug = debugUtil("Eleventy");
Expand Down
8 changes: 4 additions & 4 deletions src/Plugins/PathToUrl.js → src/Plugins/InputPathToUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ function FilterPlugin(eleventyConfig) {
inputDir = input;
});

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

filepath = normalizeInputPath(filepath, inputDir, contentMap);

let urls = contentMap[filepath];
if (!urls || urls.length === 0) {
throw new Error("`pathToUrl` filter could not find a matching target for " + filepath);
throw new Error("`inputPathToUrl` filter could not find a matching target for " + filepath);
}

return urls[0];
Expand All @@ -69,7 +69,7 @@ function TransformPlugin(eleventyConfig, defaultOptions = {}) {

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

Expand Down
5 changes: 3 additions & 2 deletions src/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import slugFilter from "./Filters/Slug.js";
import slugifyFilter from "./Filters/Slugify.js";
import getLocaleCollectionItem from "./Filters/GetLocaleCollectionItem.js";
import getCollectionItemIndex from "./Filters/GetCollectionItemIndex.js";
import { FilterPlugin as PathToUrlFilterPlugin } from "./Plugins/PathToUrl.js";
import { FilterPlugin as InputPathToUrlFilterPlugin } from "./Plugins/InputPathToUrl.js";
import { UrlTransformer } from "./Util/UrlTransformer.js";

/**
Expand Down Expand Up @@ -90,14 +90,15 @@ export default function (config) {
return getLocaleCollectionItem.call(this, config, collection, pageOverride, langCode, 1);
});

// Used for the HTML <base> and InputPathToUrl plugins
let ut = new UrlTransformer();
config.urlTransformer = ut;
config.addTransform("eleventy.urlTransformer", async function (content) {
return ut.transformContent(this.outputPath, content, this);
});

// Maps an input path to output URL
config.addPlugin(PathToUrlFilterPlugin, {
config.addPlugin(InputPathToUrlFilterPlugin, {
immediate: true,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from "ava";

import { TransformPlugin } from "../src/Plugins/PathToUrl.js";
import { TransformPlugin } from "../src/Plugins/InputPathToUrl.js";
import { default as HtmlBasePlugin } from "../src/Plugins/HtmlBasePlugin.js";
import Eleventy from "../src/Eleventy.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";
Expand Down
6 changes: 3 additions & 3 deletions test/stubs-pathtourl/filter.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title></title>
<link rel="stylesheet" href="{{ 'css.njk' | pathToUrl }}">
<script src="{{ 'css.njk' | pathToUrl }}"></script>
<link rel="stylesheet" href="{{ 'css.njk' | inputPathToUrl }}">
<script src="{{ 'css.njk' | inputPathToUrl }}"></script>
</head>
<body>
<a href="/">Home</a>
<a href="{{ 'tmpl.njk' | pathToUrl }}">Test</a>
<a href="{{ 'tmpl.njk' | inputPathToUrl }}">Test</a>
</body>
</html>

0 comments on commit 85fef01

Please sign in to comment.