author
int64
658
755k
date
stringlengths
19
19
timezone
int64
-46,800
43.2k
hash
stringlengths
40
40
message
stringlengths
5
490
mods
list
language
stringclasses
20 values
license
stringclasses
3 values
repo
stringlengths
5
68
original_message
stringlengths
12
491
699
11.05.2022 10:15:52
18,000
eed47c33c1c7b94a5504dc1ce05b3b56771f4984
Trim those extensions
[ { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -768,7 +768,8 @@ class UserConfig {\nparser = options.parser;\n}\n- for (let extension of extensionList.split(\",\")) {\n+ let extensions = extensionList.split(\",\").map((s) => s.trim());\n+ for (let extension of extensions) {\nthis.dataExtensions.set(extension, {\nextension,\nparser,\n" } ]
JavaScript
MIT License
11ty/eleventy
Trim those extensions #2378
699
11.05.2022 17:12:42
18,000
ff6bd8d611541c3f789b7d8e0ec7e9db3b407c6d
Updates to defer to approach from
[ { "change_type": "MODIFY", "old_path": "test/PaginationTest.js", "new_path": "test/PaginationTest.js", "diff": "@@ -64,7 +64,7 @@ test(\"Empty paged data\", async (t) => {\nt.is((await paging.getPageTemplates()).length, 0);\n});\n-test(\"Empty paged data with pageOnEmptyData enabled\", async (t) => {\n+test(\"Empty paged data with generatePageOnEmptyData enabled\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\nlet tmpl = getNewTemplate(\n\"./test/stubs/paged/paged-empty-pageonemptydata.njk\",\n@@ -79,8 +79,8 @@ test(\"Empty paged data with pageOnEmptyData enabled\", async (t) => {\nlet paging = new Pagination(data, tmpl.config);\npaging.setTemplate(tmpl);\n- t.is(paging.getPageCount(), 0);\n- t.is(paging.pagedItems.length, 0);\n+ t.is(paging.getPageCount(), 1);\n+ t.is(paging.pagedItems.length, 1);\nt.is((await paging.getPageTemplates()).length, 1);\n});\n" }, { "change_type": "MODIFY", "old_path": "test/stubs/paged/paged-empty-pageonemptydata.njk", "new_path": "test/stubs/paged/paged-empty-pageonemptydata.njk", "diff": "pagination:\ndata: items\nsize: 1\n- pageOnEmptyData: true\n+ generatePageOnEmptyData: true\nitems: []\n---\n<ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol>\n" } ]
JavaScript
MIT License
11ty/eleventy
Updates #1698 to defer to approach from #2208
699
12.05.2022 07:51:03
18,000
b185c53121825897acf63c3d04bc480adeafc5ed
Another dep update
[ { "change_type": "MODIFY", "old_path": "docs/release-instructions.md", "new_path": "docs/release-instructions.md", "diff": "-# List of dependencies that went ESM\n+# Dependency notes\n+\n+- `@iarna/toml` has a 3.0 that we have never been on but it was released the same day as the last 2.x https://github.com/BinaryMuse/toml-node/commits/master (needs more investigation)\n+\n+## List of dependencies that went ESM\n- `@sindresorhus/slugify` ESM at 2.x\n- `multimatch` is ESM at 6\n" }, { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "},\n\"dependencies\": {\n\"@11ty/dependency-tree\": \"^2.0.1\",\n- \"@11ty/eleventy-dev-server\": \"^1.0.0-canary.8\",\n+ \"@11ty/eleventy-dev-server\": \"^1.0.0-canary.9\",\n\"@11ty/eleventy-utils\": \"^1.0.1\",\n\"@iarna/toml\": \"^2.2.5\",\n\"@sindresorhus/slugify\": \"^1.1.2\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Another dep update
699
12.05.2022 08:18:22
18,000
e88624b778acf485d7766004a2dc72dc9fffe0e1
Moved a test function into the test code
[ { "change_type": "MODIFY", "old_path": "src/Template.js", "new_path": "src/Template.js", "diff": "@@ -711,19 +711,6 @@ class Template extends TemplateContent {\n}\n}\n- // TODO move this into tests (this is only used by tests)\n- async getRenderedTemplates(data) {\n- let pages = await this.getTemplates(data);\n- await Promise.all(\n- pages.map(async (page) => {\n- let content = await page.template.render(page.data);\n-\n- page.templateContent = content;\n- })\n- );\n- return pages;\n- }\n-\nasync _write({ url, outputPath }, finalContent) {\nlet shouldWriteFile = true;\n" }, { "change_type": "MODIFY", "old_path": "test/PaginationTest.js", "new_path": "test/PaginationTest.js", "diff": "@@ -4,6 +4,7 @@ const Pagination = require(\"../src/Plugins/Pagination\");\nconst TemplateConfig = require(\"../src/TemplateConfig\");\nconst getNewTemplate = require(\"./_getNewTemplateForTests\");\n+const getRenderedTmpls = require(\"./_getRenderedTemplates\");\ntest(\"No data passed to pagination\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n@@ -365,7 +366,7 @@ test(\"Permalink with pagination variables (and an if statement, liquid)\", async\nt.is(pages[1].outputPath, \"./dist/paged/page-1/index.html\");\n});\n-test(\"Template with Pagination, getRenderedTemplates\", async (t) => {\n+test(\"Template with Pagination\", async (t) => {\nlet tmpl = getNewTemplate(\n\"./test/stubs/paged/pagedpermalinkif.njk\",\n\"./test/stubs/\",\n@@ -376,7 +377,7 @@ test(\"Template with Pagination, getRenderedTemplates\", async (t) => {\nlet outputPath = await tmpl.getOutputPath(data);\nt.is(outputPath, \"./dist/paged/index.html\");\n- let templates = await tmpl.getRenderedTemplates(data);\n+ let templates = await getRenderedTmpls(tmpl, data);\nt.is(templates.length, 2);\n});\n@@ -395,7 +396,7 @@ test(\"Issue 135\", async (t) => {\n);\nlet data = await tmpl.getData();\n- let templates = await tmpl.getRenderedTemplates(data);\n+ let templates = await getRenderedTmpls(tmpl, data);\nt.is(data.articles.length, 1);\nt.is(data.articles[0].title, \"Do you even paginate bro?\");\nt.is(\n@@ -424,7 +425,7 @@ test(\"Template with Pagination, getTemplates has page variables set\", async (t)\nt.is(templates[1].data.page.outputPath, \"./dist/paged/page-1/index.html\");\n});\n-test(\"Template with Pagination, getRenderedTemplates has page variables set\", async (t) => {\n+test(\"Template with Pagination, has page variables set\", async (t) => {\nlet tmpl = getNewTemplate(\n\"./test/stubs/paged/pagedpermalinkif.njk\",\n\"./test/stubs/\",\n@@ -432,7 +433,7 @@ test(\"Template with Pagination, getRenderedTemplates has page variables set\", as\n);\nlet data = await tmpl.getData();\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].data.page.url, \"/paged/\");\nt.is(pages[0].data.page.outputPath, \"./dist/paged/index.html\");\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateMapTest.js", "new_path": "test/TemplateMapTest.js", "diff": "@@ -7,6 +7,7 @@ const normalizeNewLines = require(\"./Util/normalizeNewLines\");\nconst TemplateConfig = require(\"../src/TemplateConfig\");\nconst getNewTemplateForTests = require(\"./_getNewTemplateForTests\");\n+const getRenderedTmpls = require(\"./_getRenderedTemplates\");\nfunction getNewTemplate(filename, input, output, eleventyConfig) {\nreturn getNewTemplateForTests(\n@@ -229,7 +230,7 @@ test(\"Issue #115, mixing pagination and collections\", async (t) => {\nt.is(Object.keys(map[2].data.collections.foos).length, 1);\nt.is(Object.keys(map[2].data.collections.bars).length, 1);\n- let entry = await map[2].template.getRenderedTemplates(map[2].data);\n+ let entry = await getRenderedTmpls(map[2].template, map[2].data);\nt.deepEqual(\nnormalizeNewLines(entry[0].templateContent),\n`This page is foos\n@@ -294,7 +295,7 @@ test(\"Issue #115 with layout, mixing pagination and collections\", async (t) => {\nt.is(Object.keys(map[2].data.collections.foos).length, 1);\nt.is(Object.keys(map[2].data.collections.bars).length, 1);\n- let entry = await map[2].template.getRenderedTemplates(map[2].data);\n+ let entry = await getRenderedTmpls(map[2].template, map[2].data);\nt.deepEqual(\nnormalizeNewLines(entry[0].templateContent),\n`This page is foos\n@@ -691,7 +692,8 @@ test(\"Should be able to paginate a tag generated collection (and it has template\n\"./test/stubs/templateMapCollection/paged-tag-dogs-templateContent.md\"\n);\n- let templates = await pagedMapEntry.template.getRenderedTemplates(\n+ let templates = await getRenderedTmpls(\n+ pagedMapEntry.template,\npagedMapEntry.data\n);\nt.is(templates.length, 2);\n@@ -737,10 +739,10 @@ test(\"Should be able to paginate a tag generated collection when aliased (and it\n\"./test/stubs/templateMapCollection/paged-tag-dogs-templateContent-alias.md\"\n);\n- let templates = await pagedMapEntry.template.getRenderedTemplates(\n+ let templates = await getRenderedTmpls(\n+ pagedMapEntry.template,\npagedMapEntry.data\n);\n-\nt.is(templates.length, 1);\nt.is(templates[0].data.pagination.pageNumber, 0);\nt.is(\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateTest-JavaScript.js", "new_path": "test/TemplateTest-JavaScript.js", "diff": "const test = require(\"ava\");\n-const Template = require(\"../src/Template\");\nconst semver = require(\"semver\");\nconst getNewTemplate = require(\"./_getNewTemplateForTests\");\n+const getRenderedTmpls = require(\"./_getRenderedTemplates\");\ntest(\"JavaScript template type (function)\", async (t) => {\nlet tmpl = getNewTemplate(\n@@ -14,7 +14,7 @@ test(\"JavaScript template type (function)\", async (t) => {\nt.is(await tmpl.getOutputPath(data), \"./dist/function/index.html\");\ndata.name = \"Zach\";\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Zach</p>\");\n});\n@@ -28,7 +28,7 @@ test(\"JavaScript template type (class with data getter)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(await tmpl.getOutputPath(data), \"./dist/class-data/index.html\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -42,7 +42,7 @@ test(\"JavaScript template type (class with data method)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(await tmpl.getOutputPath(data), \"./dist/class-data-fn/index.html\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -57,7 +57,7 @@ if (semver.gte(process.version, \"12.4.0\")) {\nlet data = await tmpl.getData();\nt.is(await tmpl.getOutputPath(data), \"./dist/classfields-data/index.html\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n}\n@@ -75,7 +75,7 @@ test(\"JavaScript template type (class with shorthand data method)\", async (t) =>\n\"./dist/class-data-fn-shorthand/index.html\"\n);\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -89,7 +89,7 @@ test(\"JavaScript template type (class with async data method)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(await tmpl.getOutputPath(data), \"./dist/class-async-data-fn/index.html\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -109,7 +109,7 @@ test(\"JavaScript template type (class with data getter and a javascriptFunction)\nlet data = await tmpl.getData();\nt.is(await tmpl.getOutputPath(data), \"./dist/class-data-filter/index.html\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>TED</p>\");\n});\n@@ -132,7 +132,7 @@ test(\"JavaScript template type (class with data method and a javascriptFunction)\nawait tmpl.getOutputPath(data),\n\"./dist/class-data-fn-filter/index.html\"\n);\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>TED</p>\");\n});\n@@ -208,7 +208,7 @@ test(\"JavaScript template type (should use the same class instance for data and\n);\nlet data = await tmpl.getData();\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\n// the template renders the random number created in the class constructor\n// the data returns the random number created in the class constructor\n// if they are different, the class is not reused.\n@@ -223,7 +223,7 @@ test(\"JavaScript template type (multiple exports)\", async (t) => {\n);\nlet data = await tmpl.getData();\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -237,7 +237,7 @@ test(\"JavaScript template type (multiple exports, promises)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data.name, \"Ted\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -251,7 +251,7 @@ test(\"JavaScript template type (object)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data.name, \"Ted\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -265,7 +265,7 @@ test(\"JavaScript template type (object, no render method)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data.name, \"Ted\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"\");\n});\n@@ -279,7 +279,7 @@ test(\"JavaScript template type (class, no render method)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data.name, \"Ted\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"\");\n});\ntest(\"JavaScript template type (data returns a string)\", async (t) => {\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateTest.js", "new_path": "test/TemplateTest.js", "diff": "@@ -11,6 +11,7 @@ const normalizeNewLines = require(\"./Util/normalizeNewLines\");\nconst eventBus = require(\"../src/EventBus\");\nconst getNewTemplate = require(\"./_getNewTemplateForTests\");\n+const getRenderedTmpls = require(\"./_getRenderedTemplates\");\nasync function getRenderedData(tmpl, pageNumber = 0) {\nlet data = await tmpl.getData();\n@@ -147,7 +148,7 @@ test(\"Test raw front matter from template (yaml)\", async (t) => {\nt.is(data.key1, \"value1\");\nt.is(data.key3, \"value3\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"c:value1:value2:value3\");\n});\n@@ -166,7 +167,7 @@ test(\"Test raw front matter from template (json)\", async (t) => {\nt.is(data.key1, \"value1\");\nt.is(data.key3, \"value3\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"c:value1:value2:value3\");\n});\n@@ -185,7 +186,7 @@ test(\"Test raw front matter from template (js)\", async (t) => {\nt.is(data.key1, \"value1\");\nt.is(data.key3, \"value3\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"c:value1:VALUE2:value3\");\n});\n@@ -453,7 +454,7 @@ test(\"Layout from template-data-file that has a permalink (fileslug) Issue #121\"\n);\nlet data = await tmpl.getData();\n- let renderedTmpl = (await tmpl.getRenderedTemplates(data))[0];\n+ let renderedTmpl = (await getRenderedTmpls(tmpl, data))[0];\nt.is(renderedTmpl.templateContent, \"Wrapper:Test 1:test\");\nt.is(await tmpl.getOutputPath(data), \"./dist/test/index.html\");\n});\n@@ -466,7 +467,7 @@ test(\"Fileslug in an 11ty.js template Issue #588\", async (t) => {\n);\nlet data = await tmpl.getData();\n- let renderedTmpl = (await tmpl.getRenderedTemplates(data))[0];\n+ let renderedTmpl = (await getRenderedTmpls(tmpl, data))[0];\nt.is(renderedTmpl.templateContent, \"<p>fileslug</p>\");\n});\n@@ -658,7 +659,7 @@ test(\"Issue #603: page.date Liquid\", async (t) => {\nt.truthy(data.page.date);\nt.truthy(data.page.date.toUTCString());\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), data.page.date.toString());\n});\n@@ -673,7 +674,7 @@ test(\"Issue #603: page.date Nunjucks\", async (t) => {\nt.truthy(data.page.date);\nt.truthy(data.page.date.toUTCString());\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), data.page.date.toString());\n});\n@@ -689,7 +690,7 @@ test(\"Issue #603: page.date.toUTCString() Nunjucks\", async (t) => {\nt.truthy(data.page.date);\nt.truthy(data.page.date.toUTCString());\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), data.page.date.toUTCString());\n});\n@@ -727,6 +728,7 @@ test(\"getTemplates() data has all the page variables\", async (t) => {\nt.is(templates[0].data.page.outputPath, \"./dist/template/index.html\");\n});\n+// Warning `getRenderedTemplates()` is a test function now, so this might be a test testing the tests\ntest(\"getRenderedTemplates() data has all the page variables\", async (t) => {\nlet tmpl = getNewTemplate(\n\"./test/stubs/template.ejs\",\n@@ -735,7 +737,7 @@ test(\"getRenderedTemplates() data has all the page variables\", async (t) => {\n);\nlet data = await tmpl.getData();\n- let templates = await tmpl.getRenderedTemplates(data);\n+ let templates = await getRenderedTmpls(tmpl, data);\nt.is(templates[0].data.page.url, \"/template/\");\nt.is(templates[0].data.page.fileSlug, \"template\");\nt.is(templates[0].filePathStem, \"/template\");\n@@ -1156,7 +1158,7 @@ test(\"Front Matter Tags (Single)\", async (t) => {\nlet fulldata = await tmpl.getData();\nt.deepEqual(fulldata.tags, [\"single-tag\"]);\n- let pages = await tmpl.getRenderedTemplates(fulldata);\n+ let pages = await getRenderedTmpls(tmpl, fulldata);\nt.is(pages[0].templateContent.trim(), \"Has single-tag\");\n});\n@@ -1172,7 +1174,7 @@ test(\"Front Matter Tags (Multiple)\", async (t) => {\nlet fulldata = await tmpl.getData();\nt.deepEqual(fulldata.tags, [\"multi-tag\", \"multi-tag-2\"]);\n- let pages = await tmpl.getRenderedTemplates(fulldata);\n+ let pages = await getRenderedTmpls(tmpl, fulldata);\nt.is(pages[0].templateContent.trim(), \"Has multi-tag-2\");\n});\n@@ -1186,7 +1188,7 @@ test(\"Front matter date with quotes (liquid), issue #258\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data.mydate.toISOString(), \"2009-04-15T11:34:34.000Z\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"2009-04-15\");\n});\n@@ -1200,7 +1202,7 @@ test(\"Front matter date with quotes (njk), issue #258\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data.mydate.toISOString(), \"2009-04-15T00:34:34.000Z\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"2009-04-15T00:34:34.000Z\");\n});\n@@ -1789,7 +1791,7 @@ test(\"global variable with dashes Issue #567 (liquid)\", async (t) => {\nlet data = await tmpl.getData();\nt.is(data[\"is-it-tasty\"], \"Yes\");\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"Yes\");\n});\n@@ -1802,7 +1804,7 @@ test(\"Issue #446: Layout has a permalink with a different template language than\nlet data = await tmpl.getData();\n// this call is needed for page data to be added\n- let pages = await tmpl.getRenderedTemplates(data);\n+ let pages = await getRenderedTmpls(tmpl, data);\nt.is(data.permalink, \"/{{ page.fileSlug }}/\");\nt.is(data.page.url, \"/test/\");\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/_getRenderedTemplates.js", "diff": "+module.exports = async function getRenderedTemplates(template, data) {\n+ let pages = await template.getTemplates(data);\n+ await Promise.all(\n+ pages.map(async (page) => {\n+ let content = await page.template.render(page.data);\n+\n+ page.templateContent = content;\n+ })\n+ );\n+ return pages;\n+};\n" } ]
JavaScript
MIT License
11ty/eleventy
Moved a test function into the test code
699
12.05.2022 16:28:42
18,000
fbf2037cf25a0ff44b4fd0df98f90a5438e9d2cb
Fixes Use a dependency graph to manage config dependencies so we know when to reload the config.
[ { "change_type": "MODIFY", "old_path": "src/Eleventy.js", "new_path": "src/Eleventy.js", "diff": "@@ -649,6 +649,28 @@ Arguments:\nthis.watchManager.addToPendingQueue(changedFilePath);\n}\n+ _shouldResetConfig() {\n+ let configFilePath = this.eleventyConfig.getLocalProjectConfigFile();\n+ let configFileChanged = this.watchManager.hasQueuedFile(configFilePath);\n+ if (configFileChanged) {\n+ return true;\n+ }\n+\n+ // Any dependencies of the config file changed\n+ let configFileDependencies =\n+ this.watchTargets.getDependenciesOf(configFilePath);\n+ for (let dep of configFileDependencies) {\n+ if (this.watchManager.hasQueuedFile(dep)) {\n+ // Delete from require cache so that updates to the module are re-required\n+ deleteRequireCache(TemplatePath.absolutePath(dep));\n+\n+ return true;\n+ }\n+ }\n+\n+ return false;\n+ }\n+\n/**\n* tbd.\n*\n@@ -667,11 +689,7 @@ Arguments:\nawait this.config.events.emit(\"eleventy.beforeWatch\", queue);\n// reset and reload global configuration :O\n- if (\n- this.watchManager.hasQueuedFile(\n- this.eleventyConfig.getLocalProjectConfigFile()\n- )\n- ) {\n+ if (this._shouldResetConfig()) {\nthis.resetConfig();\n}\n" }, { "change_type": "MODIFY", "old_path": "src/EleventyWatchTargets.js", "new_path": "src/EleventyWatchTargets.js", "diff": "const { TemplatePath } = require(\"@11ty/eleventy-utils\");\n+const { DepGraph } = require(\"dependency-graph\");\nconst deleteRequireCache = require(\"./Util/DeleteRequireCache\");\nconst JavaScriptDependencies = require(\"./Util/JavaScriptDependencies\");\n@@ -9,6 +10,8 @@ class EleventyWatchTargets {\nthis.dependencies = new Set();\nthis.newTargets = new Set();\nthis._watchJavaScriptDependencies = true;\n+\n+ this.graph = new DepGraph();\n}\nset watchJavaScriptDependencies(watch) {\n@@ -41,6 +44,29 @@ class EleventyWatchTargets {\nreturn this.targets.has(target);\n}\n+ addToDependencyGraph(parent, deps) {\n+ if (!this.graph.hasNode(parent)) {\n+ this.graph.addNode(parent);\n+ }\n+ for (let dep of deps) {\n+ if (!this.graph.hasNode(dep)) {\n+ this.graph.addNode(dep);\n+ }\n+ this.graph.addDependency(parent, dep);\n+ }\n+ }\n+\n+ uses(parent, dep) {\n+ return this.getDependenciesOf(parent).includes(dep);\n+ }\n+\n+ getDependenciesOf(parent) {\n+ if (!this.graph.hasNode(parent)) {\n+ return [];\n+ }\n+ return this.graph.dependenciesOf(parent);\n+ }\n+\naddRaw(targets, isDependency) {\nfor (let target of targets) {\nlet path = TemplatePath.addLeadingDotSlash(target);\n@@ -81,6 +107,9 @@ class EleventyWatchTargets {\ndeps = deps.filter(filterCallback);\n}\n+ for (let target of targets) {\n+ this.addToDependencyGraph(target, deps);\n+ }\nthis.addRaw(deps, true);\n}\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyWatchTargetsTest.js", "new_path": "test/EleventyWatchTargetsTest.js", "diff": "@@ -45,6 +45,16 @@ test(\"JavaScript addDependencies\", (t) => {\nlet targets = new EleventyWatchTargets();\ntargets.addDependencies(\"./test/stubs/config-deps.js\");\nt.deepEqual(targets.getTargets(), [\"./test/stubs/config-deps-upstream.js\"]);\n+\n+ t.true(\n+ targets.uses(\n+ \"./test/stubs/config-deps.js\",\n+ \"./test/stubs/config-deps-upstream.js\"\n+ )\n+ );\n+ t.false(\n+ targets.uses(\"./test/stubs/config-deps.js\", \"./test/stubs/config-deps.js\")\n+ );\n});\ntest(\"JavaScript addDependencies (one file has two dependencies)\", (t) => {\n@@ -54,6 +64,25 @@ test(\"JavaScript addDependencies (one file has two dependencies)\", (t) => {\n\"./test/stubs/dependencies/dep1.js\",\n\"./test/stubs/dependencies/dep2.js\",\n]);\n+\n+ t.true(\n+ targets.uses(\n+ \"./test/stubs/dependencies/two-deps.11ty.js\",\n+ \"./test/stubs/dependencies/dep1.js\"\n+ )\n+ );\n+ t.true(\n+ targets.uses(\n+ \"./test/stubs/dependencies/two-deps.11ty.js\",\n+ \"./test/stubs/dependencies/dep2.js\"\n+ )\n+ );\n+ t.false(\n+ targets.uses(\n+ \"./test/stubs/dependencies/two-deps.11ty.js\",\n+ \"./test/stubs/dependencies/dep3.js\"\n+ )\n+ );\n});\ntest(\"JavaScript addDependencies (skip JS deps)\", (t) => {\n@@ -61,6 +90,25 @@ test(\"JavaScript addDependencies (skip JS deps)\", (t) => {\ntargets.watchJavaScriptDependencies = false;\ntargets.addDependencies(\"./test/stubs/dependencies/two-deps.11ty.js\");\nt.deepEqual(targets.getTargets(), []);\n+\n+ t.false(\n+ targets.uses(\n+ \"./test/stubs/dependencies/two-deps.11ty.js\",\n+ \"./test/stubs/dependencies/dep1.js\"\n+ )\n+ );\n+ t.false(\n+ targets.uses(\n+ \"./test/stubs/dependencies/two-deps.11ty.js\",\n+ \"./test/stubs/dependencies/dep2.js\"\n+ )\n+ );\n+ t.false(\n+ targets.uses(\n+ \"./test/stubs/dependencies/two-deps.11ty.js\",\n+ \"./test/stubs/dependencies/dep3.js\"\n+ )\n+ );\n});\ntest(\"JavaScript addDependencies with a filter\", (t) => {\n@@ -69,6 +117,12 @@ test(\"JavaScript addDependencies with a filter\", (t) => {\nreturn path.indexOf(\"./test/stubs/\") === -1;\n});\nt.deepEqual(targets.getTargets(), []);\n+ t.false(\n+ targets.uses(\n+ \"./test/stubs/dependencies/config-deps.js\",\n+ \"./test/stubs/dependencies/config-deps-upstream.js\"\n+ )\n+ );\n});\ntest(\"add, addDependencies falsy values are filtered\", (t) => {\n" } ]
JavaScript
MIT License
11ty/eleventy
Fixes #1052. Use a dependency graph to manage config dependencies so we know when to reload the config.
699
13.05.2022 10:25:19
18,000
457884601363fe235977ec1af4c09a3408a08be9
Refactor addGlobalData fetching into a separate class so we can reuse it on Edge
[ { "change_type": "MODIFY", "old_path": "src/TemplateData.js", "new_path": "src/TemplateData.js", "diff": "-const pkg = require(\"../package.json\");\nconst fs = require(\"fs\");\nconst fastglob = require(\"fast-glob\");\nconst path = require(\"path\");\nconst lodashset = require(\"lodash/set\");\nconst lodashget = require(\"lodash/get\");\nconst lodashUniq = require(\"lodash/uniq\");\n-const semver = require(\"semver\");\nconst { TemplatePath, isPlainObject } = require(\"@11ty/eleventy-utils\");\nconst merge = require(\"./Util/Merge\");\n@@ -13,6 +11,7 @@ const TemplateRender = require(\"./TemplateRender\");\nconst TemplateGlob = require(\"./TemplateGlob\");\nconst EleventyExtensionMap = require(\"./EleventyExtensionMap\");\nconst EleventyBaseError = require(\"./EleventyBaseError\");\n+const TemplateDataInitialGlobalData = require(\"./TemplateDataInitialGlobalData\");\nconst debugWarn = require(\"debug\")(\"Eleventy:Warnings\");\nconst debug = require(\"debug\")(\"Eleventy:TemplateData\");\n@@ -66,6 +65,10 @@ class TemplateData {\n// It's common for data files not to exist, so we avoid going to the FS to\n// re-check if they do via a quick-and-dirty cache.\nthis._fsExistsCache = new FSExistsCache();\n+\n+ this.initialGlobalData = new TemplateDataInitialGlobalData(\n+ this.eleventyConfig\n+ );\n}\nget extensionMap() {\n@@ -303,28 +306,7 @@ class TemplateData {\n}\nasync getInitialGlobalData() {\n- let globalData = {};\n-\n- // via eleventyConfig.addGlobalData\n- if (this.config.globalData) {\n- let keys = Object.keys(this.config.globalData);\n- for (let key of keys) {\n- let returnValue = this.config.globalData[key];\n-\n- if (typeof returnValue === \"function\") {\n- returnValue = await returnValue();\n- }\n-\n- lodashset(globalData, key, returnValue);\n- }\n- }\n-\n- if (!(\"eleventy\" in globalData)) {\n- globalData.eleventy = {};\n- }\n- // #2293 for meta[name=generator]\n- globalData.eleventy.version = semver.coerce(pkg.version).toString();\n- globalData.eleventy.generator = `Eleventy v${globalData.eleventy.version}`;\n+ let globalData = await this.initialGlobalData.getData();\nif (this.environmentVariables) {\nif (!(\"env\" in globalData.eleventy)) {\n" }, { "change_type": "ADD", "old_path": null, "new_path": "src/TemplateDataInitialGlobalData.js", "diff": "+const pkg = require(\"../package.json\");\n+const semver = require(\"semver\");\n+const lodashset = require(\"lodash/set\");\n+\n+class TemplateDataInitialGlobalData {\n+ constructor(templateConfig) {\n+ if (!templateConfig) {\n+ throw new TemplateDataConfigError(\"Missing `config`.\");\n+ }\n+ this.templateConfig = templateConfig;\n+ this.config = this.templateConfig.getConfig();\n+ }\n+\n+ async getData() {\n+ let globalData = {};\n+\n+ // via eleventyConfig.addGlobalData\n+ if (this.config.globalData) {\n+ let keys = Object.keys(this.config.globalData);\n+ for (let key of keys) {\n+ let returnValue = this.config.globalData[key];\n+\n+ if (typeof returnValue === \"function\") {\n+ returnValue = await returnValue();\n+ }\n+\n+ lodashset(globalData, key, returnValue);\n+ }\n+ }\n+\n+ if (!(\"eleventy\" in globalData)) {\n+ globalData.eleventy = {};\n+ }\n+ // #2293 for meta[name=generator]\n+ globalData.eleventy.version = semver.coerce(pkg.version).toString();\n+ globalData.eleventy.generator = `Eleventy v${globalData.eleventy.version}`;\n+\n+ return globalData;\n+ }\n+}\n+\n+module.exports = TemplateDataInitialGlobalData;\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateDataTest.js", "new_path": "test/TemplateDataTest.js", "diff": "@@ -213,22 +213,13 @@ test(\"getAllGlobalData() with js function data file\", async (t) => {\ntest(\"getAllGlobalData() with config globalData\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n- let dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\n+ eleventyConfig.userConfig.addGlobalData(\"example\", () => \"one\");\n+ eleventyConfig.userConfig.addGlobalData(\"example2\", async () => \"two\");\n+ eleventyConfig.userConfig.addGlobalData(\"example3\", \"static\");\n- dataObj._setConfig({\n- ...dataObj.config,\n- globalData: {\n- example: () => {\n- return \"one\";\n- },\n- example2: async () => {\n- return \"two\";\n- },\n- example3: \"static\",\n- },\n- });\n+ let dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\n- let data = await dataObj.cacheData(true);\n+ let data = await dataObj.cacheData();\nt.is(data.example, \"one\");\nt.is(data.example2, \"two\");\n" } ]
JavaScript
MIT License
11ty/eleventy
Refactor addGlobalData fetching into a separate class so we can reuse it on Edge
699
18.05.2022 15:47:03
18,000
1db6a10a98f35b6f6bcac94222cdd8597e6f7928
Serverless middleware no longer runs res.end() (and does run `next`) to let downstream middlewares consume or modify the output. More context at
[ { "change_type": "MODIFY", "old_path": "src/Plugins/ServerlessBundlerPlugin.js", "new_path": "src/Plugins/ServerlessBundlerPlugin.js", "diff": "@@ -167,11 +167,19 @@ class BundlerHelper {\nres.writeHead(result.statusCode, result.headers || {});\nres.write(result.body);\n- res.end();\nthis.eleventyConfig.logger.forceLog(\n`Serverless (${this.name}): ${req.url} (${Date.now() - start}ms)`\n);\n+\n+ // eleventy-dev-server 1.0.0-canary.10 and newer\n+ if (\"_shouldForceEnd\" in res) {\n+ res._shouldForceEnd = true;\n+ next();\n+ } else {\n+ // eleventy-dev-server 1.0.0-canary.9 and below\n+ res.end();\n+ }\n}.bind(this);\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Serverless middleware no longer runs res.end() (and does run `next`) to let downstream middlewares consume or modify the output. More context at https://github.com/11ty/eleventy-dev-server/issues/29
699
16.06.2022 08:49:08
18,000
83c90bfc0340a5983a8b9a8b5bc2f4a4fe7f190f
Saw some error stack traces on the tracker where e.message was not a string
[ { "change_type": "MODIFY", "old_path": "src/EleventyErrorUtil.js", "new_path": "src/EleventyErrorUtil.js", "diff": "@@ -72,7 +72,7 @@ class EleventyErrorUtil {\ne.originalError.name === \"UndefinedVariableError\") &&\ne.originalError.originalError instanceof\nTemplateContentPrematureUseError) || // Liquid\n- e.message.indexOf(\"TemplateContentPrematureUseError\") > -1\n+ (e.message || \"\").indexOf(\"TemplateContentPrematureUseError\") > -1\n); // Nunjucks\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Saw some error stack traces on the tracker where e.message was not a string
699
16.06.2022 11:59:13
18,000
1bdbd2441cc240af29d6ae633247d7a407411d53
Fixes Adds new `amendLibrary` configuration API method to alter both default or custom library instances (set via setLibrary)
[ { "change_type": "MODIFY", "old_path": "src/Engines/Markdown.js", "new_path": "src/Engines/Markdown.js", "diff": "@@ -24,6 +24,9 @@ class Markdown extends TemplateEngine {\n});\n}\n+ // Disable indented code blocks by default (Issue #2438)\n+ this.mdLib.disable(\"code\");\n+\nthis.setEngineLib(this.mdLib);\n}\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/TemplateEngine.js", "new_path": "src/Engines/TemplateEngine.js", "diff": "@@ -155,6 +155,11 @@ class TemplateEngine {\nsetEngineLib(engineLib) {\nthis.engineLib = engineLib;\n+\n+ // Run engine amendments (via issue #2438)\n+ for (let amendment of this.config.libraryAmendments[this.name] || []) {\n+ amendment(engineLib);\n+ }\n}\ngetEngineLib() {\n" }, { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -88,6 +88,8 @@ class UserConfig {\nthis.useTemplateCache = true;\nthis.dataFilterSelectors = new Set();\n+\n+ this.libraryAmendments = {};\n}\nversionCheck(expected) {\n@@ -460,6 +462,16 @@ class UserConfig {\nthis.libraryOverrides[engineName.toLowerCase()] = libraryInstance;\n}\n+ /* These callbacks run on both libraryOverrides and default library instances */\n+ amendLibrary(engineName, callback) {\n+ let name = engineName.toLowerCase();\n+ if (!this.libraryAmendments[name]) {\n+ this.libraryAmendments[name] = [];\n+ }\n+\n+ this.libraryAmendments[name].push(callback);\n+ }\n+\nsetPugOptions(options) {\nthis.pugOptions = options;\n}\n@@ -838,6 +850,7 @@ class UserConfig {\nuseTemplateCache: this.useTemplateCache,\nprecompiledCollections: this.precompiledCollections,\ndataFilterSelectors: this.dataFilterSelectors,\n+ libraryAmendments: this.libraryAmendments,\n};\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Fixes #2438. Adds new `amendLibrary` configuration API method to alter both default or custom library instances (set via setLibrary)
699
16.06.2022 12:18:30
18,000
e65e9d2a465078d4b8ea755435508a6daf9150ac
Two more tests for
[ { "change_type": "MODIFY", "old_path": "test/TemplateRenderMarkdownTest.js", "new_path": "test/TemplateRenderMarkdownTest.js", "diff": "@@ -379,6 +379,22 @@ test(\"Markdown Render: use amendLibrary to re-enable indented code blocks. Issue\nlet tr = getNewTemplateRender(\"md\", null, eleventyConfig);\n+ let fn = await tr.getCompiledTemplate(\" This is a test\");\n+ let content = await fn();\n+ t.is(\n+ normalizeNewLines(content.trim()),\n+ `<pre><code>This is a test\n+</code></pre>`\n+ );\n+});\n+\n+test(\"Markdown Render: amendLibrary works with setLibrary to re-enable indented code blocks. Issue #2438\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ let userConfig = eleventyConfig.userConfig;\n+ userConfig.amendLibrary(\"md\", (lib) => lib.enable(\"code\"));\n+\n+ let tr = getNewTemplateRender(\"md\", null, eleventyConfig);\n+\nlet mdLib = md();\ntr.engine.setLibrary(mdLib);\n@@ -391,6 +407,27 @@ test(\"Markdown Render: use amendLibrary to re-enable indented code blocks. Issue\n);\n});\n+test(\"Markdown Render: multiple amendLibrary calls. Issue #2438\", async (t) => {\n+ t.plan(3);\n+\n+ let eleventyConfig = new TemplateConfig();\n+ let userConfig = eleventyConfig.userConfig;\n+ userConfig.amendLibrary(\"md\", (lib) => {\n+ t.true(true);\n+ lib.enable(\"code\");\n+ });\n+ userConfig.amendLibrary(\"md\", (lib) => {\n+ t.true(true);\n+ lib.disable(\"code\");\n+ });\n+\n+ let tr = getNewTemplateRender(\"md\", null, eleventyConfig);\n+\n+ let fn = await tr.getCompiledTemplate(\" This is a test\");\n+ let content = await fn();\n+ t.is(normalizeNewLines(content.trim()), \"<p>This is a test</p>\");\n+});\n+\ntest(\"Markdown Render: use amendLibrary to add a Plugin\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\nlet userConfig = eleventyConfig.userConfig;\n" } ]
JavaScript
MIT License
11ty/eleventy
Two more tests for #2438
699
17.06.2022 10:19:51
18,000
5a00a5946b868ee82f6a09590fb7d4c8625117ac
Update Eleventy Edge to version 2, read more:
[ { "change_type": "MODIFY", "old_path": "src/Plugins/EdgePlugin.js", "new_path": "src/Plugins/EdgePlugin.js", "diff": "@@ -193,7 +193,7 @@ function EleventyEdgePlugin(eleventyConfig, opts = {}) {\nfunctionsDir: \"./netlify/edge-functions/\",\n// for the default Deno import\n- eleventyEdgeVersion: \"1.0.1\",\n+ eleventyEdgeVersion: \"2.0.0\",\n// runtime compatibity check with Eleventy core version\ncompatibility: \">=2\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Update Eleventy Edge to version 2, read more: https://github.com/11ty/eleventy/issues/2422#issuecomment-1158913315
699
22.06.2022 14:14:04
18,000
d628e33a628cc13f354bb68e126c260613cc6d0e
Filed remaining work from as a separate issue [skip ci]
[ { "change_type": "MODIFY", "old_path": "src/TemplatePassthroughManager.js", "new_path": "src/TemplatePassthroughManager.js", "diff": "@@ -123,7 +123,7 @@ class TemplatePassthroughManager {\npass.setDryRun(this.isDryRun);\n- // TODO https://github.com/11ty/eleventy/issues/2174#issuecomment-1162420197\n+ // TODO https://github.com/11ty/eleventy/issues/2452\n// De-dupe both the input and output paired together to avoid the case\n// where an input/output pair has been added via multiple passthrough methods (glob, file suffix, etc)\n// Probably start with the `filter` callback in recursive-copy but it only passes relative paths\n" } ]
JavaScript
MIT License
11ty/eleventy
Filed remaining work from #2174 as a separate issue [skip ci]
699
23.06.2022 16:58:33
18,000
2dc27703fdb12839968bec0080f35aa517dbea0d
Adds eleventyConfig.setServerPassthroughCopyBehavior("copy"); configuration API method to revert to previous passthrough copy file copy behavior for
[ { "change_type": "MODIFY", "old_path": "src/Eleventy.js", "new_path": "src/Eleventy.js", "diff": "@@ -977,6 +977,7 @@ Arguments:\nawait watchRun(path);\n});\n+ if (this.config.serverPassthroughCopyBehavior === \"passthrough\") {\n// Separate watcher for passthrough copy, we only want to trigger a server reload for changes to these files\nthis.passthroughWatcher = chokidar.watch(\nthis.eleventyFiles.getGlobWatcherFilesForPassthroughCopy(),\n@@ -991,6 +992,7 @@ Arguments:\nthis.logger.forceLog(`Passthrough copy file added: ${path}`);\nthis.triggerServerReload([path]);\n});\n+ }\nprocess.on(\"SIGINT\", () => this.stopWatch());\n}\n@@ -999,7 +1001,11 @@ Arguments:\ndebug(\"Cleaning up chokidar and server instances, if they exist.\");\nthis.eleventyServe.close();\nthis.watcher.close();\n+\n+ if (this.passthroughWatcher) {\nthis.passthroughWatcher.close();\n+ }\n+\nprocess.exit();\n}\n" }, { "change_type": "MODIFY", "old_path": "src/EleventyFiles.js", "new_path": "src/EleventyFiles.js", "diff": "@@ -429,12 +429,16 @@ class EleventyFiles {\n// TODO improvement: tie the includes and data to specific file extensions (currently using `**`)\nlet directoryGlobs = this._getIncludesAndDataDirs();\n- // TODO config API method to revert to previous passthrough copy behavior\n- // return this.validTemplateGlobs.concat(this.passthroughGlobs).concat(directoryGlobs);\n-\n+ if (this.config.serverPassthroughCopyBehavior === \"passthrough\") {\nreturn this.validTemplateGlobs.concat(directoryGlobs);\n}\n+ // Revert to old passthroughcopy copy files behavior\n+ return this.validTemplateGlobs\n+ .concat(this.passthroughGlobs)\n+ .concat(directoryGlobs);\n+ }\n+\n/* For `eleventy --watch` */\ngetGlobWatcherFilesForPassthroughCopy() {\nreturn this.passthroughGlobs;\n" }, { "change_type": "MODIFY", "old_path": "src/TemplatePassthrough.js", "new_path": "src/TemplatePassthrough.js", "diff": "@@ -195,7 +195,10 @@ class TemplatePassthrough {\nlet promises = fileMap.map((entry) => {\n// For-free passthrough copy\n- if (this.runMode === \"serve\" || this.runMode === \"watch\") {\n+ if (\n+ this.config.serverPassthroughCopyBehavior === \"passthrough\" &&\n+ (this.runMode === \"serve\" || this.runMode === \"watch\")\n+ ) {\nlet aliasMap = {};\naliasMap[entry.inputPath] = entry.outputPath;\n" }, { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -90,6 +90,8 @@ class UserConfig {\nthis.dataFilterSelectors = new Set();\nthis.libraryAmendments = {};\n+\n+ this.serverPassthroughCopyBehavior = \"passthrough\";\n}\nversionCheck(expected) {\n@@ -798,6 +800,12 @@ class UserConfig {\nthis.precompiledCollections = collections;\n}\n+ // \"passthrough\" is the default, no other value is explicitly required in code\n+ // but opt-out via \"copy\" is suggested\n+ setServerPassthroughCopyBehavior(behavior) {\n+ this.serverPassthroughCopyBehavior = behavior;\n+ }\n+\ngetMergingConfigObject() {\nreturn {\ntemplateFormats: this.templateFormats,\n@@ -851,6 +859,7 @@ class UserConfig {\nprecompiledCollections: this.precompiledCollections,\ndataFilterSelectors: this.dataFilterSelectors,\nlibraryAmendments: this.libraryAmendments,\n+ serverPassthroughCopyBehavior: this.serverPassthroughCopyBehavior,\n};\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds eleventyConfig.setServerPassthroughCopyBehavior("copy"); configuration API method to revert to previous passthrough copy file copy behavior for #2456
699
24.06.2022 16:16:33
18,000
b8076f3c877e5e31fedf027050f866fb29e773c3
Better fix for Fixes
[ { "change_type": "MODIFY", "old_path": "src/TemplatePassthrough.js", "new_path": "src/TemplatePassthrough.js", "diff": "@@ -67,10 +67,14 @@ class TemplatePassthrough {\nTemplatePath.join(outputDir, outputPath)\n);\n- if (this.isIncremental && TemplatePath.isDirectorySync(fullOutputPath)) {\n+ if (\n+ fs.existsSync(inputPath) &&\n+ !TemplatePath.isDirectorySync(inputPath) &&\n+ TemplatePath.isDirectorySync(fullOutputPath)\n+ ) {\nlet filename = path.parse(inputPath).base;\nreturn TemplatePath.normalize(\n- TemplatePath.join(outputDir, outputPath, filename)\n+ TemplatePath.join(fullOutputPath, filename)\n);\n}\n@@ -141,7 +145,7 @@ class TemplatePassthrough {\n*/\nasync copy(src, dest, copyOptions) {\nif (\n- !TemplatePath.stripLeadingDotSlash(dest).includes(\n+ !TemplatePath.stripLeadingDotSlash(dest).startsWith(\nTemplatePath.stripLeadingDotSlash(this.outputDir)\n)\n) {\n" }, { "change_type": "MODIFY", "old_path": "test/TemplatePassthroughTest.js", "new_path": "test/TemplatePassthroughTest.js", "diff": "@@ -299,12 +299,22 @@ test(\"Output paths match with different templatePassthrough methods\", async (t)\n// t.is(pass.getOutputPath(), \"_site/rename.js\");\n// });\n-test(\"Bug with incremental copying to a directory output, issue #2278\", async (t) => {\n+test(\"Bug with incremental file copying to a directory output, issue #2278 #1038\", async (t) => {\nlet pass1 = getTemplatePassthrough(\n- { inputPath: \"./public/test.css\", outputPath: \"/\" },\n+ { inputPath: \"./test/stubs/public/test.css\", outputPath: \"/\" },\n\"test/stubs\",\n\".\"\n);\n- pass1.setIsIncremental(true);\n+\nt.is(pass1.getOutputPath(), \"test/stubs/test.css\");\n});\n+\n+test(\"Bug with incremental dir copying to a directory output, issue #2278 #1038\", async (t) => {\n+ let pass1 = getTemplatePassthrough(\n+ { inputPath: \"./test/stubs/public/\", outputPath: \"/\" },\n+ \"test/stubs\",\n+ \".\"\n+ );\n+\n+ t.is(pass1.getOutputPath(), \"test/stubs\");\n+});\n" }, { "change_type": "ADD", "old_path": "test/stubs/public/test.css", "new_path": "test/stubs/public/test.css", "diff": "" } ]
JavaScript
MIT License
11ty/eleventy
Better fix for #2278. Fixes #1038
699
24.06.2022 17:03:18
18,000
631c881f8356a3e6665b6f5f91283ae5fb28f9f5
A few more style tweaks for
[ { "change_type": "MODIFY", "old_path": "src/TemplatePassthrough.js", "new_path": "src/TemplatePassthrough.js", "diff": "@@ -44,7 +44,7 @@ class TemplatePassthrough {\n}\ngetOutputPath(inputFileFromGlob) {\n- const { inputDir, outputDir, outputPath, inputPath } = this;\n+ let { inputDir, outputDir, outputPath, inputPath } = this;\nif (outputPath === true) {\nreturn TemplatePath.normalize(\n@@ -106,7 +106,7 @@ class TemplatePassthrough {\ndebug(\"Searching for: %o\", glob);\nlet b = this.benchmarks.aggregate.get(\"Searching the file system\");\nb.before();\n- const files = TemplatePath.addLeadingDotSlashArray(\n+ let files = TemplatePath.addLeadingDotSlashArray(\nawait fastglob(glob, {\ncaseSensitiveMatch: false,\ndot: true,\n@@ -193,7 +193,7 @@ class TemplatePassthrough {\n// default options for recursive-copy\n// see https://www.npmjs.com/package/recursive-copy#arguments\n- const copyOptionsDefault = {\n+ let copyOptionsDefault = {\noverwrite: true, // overwrite output. fails when input is directory (mkdir) and output is file\ndot: true, // copy dotfiles\njunk: false, // copy cache files like Thumbs.db\n@@ -206,7 +206,7 @@ class TemplatePassthrough {\n// e.g. `{ filePaths: [ './img/coolkid.jpg' ], relativePaths: [ '' ] }`\n};\n- const copyOptions = Object.assign(copyOptionsDefault, this.copyOptions);\n+ let copyOptions = Object.assign(copyOptionsDefault, this.copyOptions);\nlet promises = fileMap.map((entry) => {\n// For-free passthrough copy\n" }, { "change_type": "MODIFY", "old_path": "src/TemplatePassthroughManager.js", "new_path": "src/TemplatePassthroughManager.js", "diff": "@@ -75,10 +75,10 @@ class TemplatePassthroughManager {\n}\ngetConfigPaths() {\n- const paths = [];\n- const pathsRaw = this.config.passthroughCopies || {};\n+ let paths = [];\n+ let pathsRaw = this.config.passthroughCopies || {};\ndebug(\"`addPassthroughCopy` config API paths: %o\", pathsRaw);\n- for (const [inputPath, { outputPath, copyOptions }] of Object.entries(\n+ for (let [inputPath, { outputPath, copyOptions }] of Object.entries(\npathsRaw\n)) {\npaths.push(this._normalizePaths(inputPath, outputPath, copyOptions));\n" }, { "change_type": "MODIFY", "old_path": "test/TemplatePassthroughManagerTest.js", "new_path": "test/TemplatePassthroughManagerTest.js", "diff": "@@ -3,7 +3,6 @@ const fs = require(\"fs\");\nconst TemplatePassthroughManager = require(\"../src/TemplatePassthroughManager\");\nconst TemplateConfig = require(\"../src/TemplateConfig\");\nconst EleventyFiles = require(\"../src/EleventyFiles\");\n-const EleventyExtensionMap = require(\"../src/EleventyExtensionMap\");\ntest(\"Get paths from Config\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n" } ]
JavaScript
MIT License
11ty/eleventy
A few more style tweaks for #1686
699
29.06.2022 14:56:14
18,000
fc6fc96707ad9ca062622ea11e0c092b666372a9
Fixes addings `.git/**` to the default list of ignores.
[ { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -68,6 +68,7 @@ class UserConfig {\nthis.useGitIgnore = true;\nthis.ignores = new Set();\nthis.ignores.add(\"node_modules/**\");\n+ this.ignores.add(\".git/**\");\nthis.dataDeepMerge = true;\nthis.extensionMap = new Set();\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "new_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "diff": "@@ -20,6 +20,7 @@ test(\"Get ignores (no .eleventyignore no .gitignore)\", (t) => {\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore1/_site/**\",\n]);\n@@ -38,6 +39,7 @@ test(\"Get ignores (no .eleventyignore)\", (t) => {\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignorelocalrootgitignore/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/.git/**\",\n\"./test/stubs/ignorelocalrootgitignore/thisshouldnotexist12345\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n\"./test/stubs/ignore2/_site/**\",\n@@ -82,6 +84,7 @@ test(\"Get ignores (no .gitignore)\", (t) => {\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore3/ignoredFolder/**\",\n\"./test/stubs/ignore3/ignoredFolder/ignored.md\",\n@@ -102,6 +105,7 @@ test(\"Get ignores (project .eleventyignore and root .gitignore)\", (t) => {\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignorelocalrootgitignore/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/.git/**\",\n\"./test/stubs/ignorelocalrootgitignore/thisshouldnotexist12345\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n\"./test/stubs/ignore4/ignoredFolder/**\",\n@@ -151,6 +155,7 @@ test(\"Get ignores (no .eleventyignore .gitignore exists but empty)\", (t) => {\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore5/_site/**\",\n]);\n@@ -169,6 +174,7 @@ test(\"Get ignores (both .eleventyignore and .gitignore exists, but .gitignore is\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore6/ignoredFolder/**\",\n\"./test/stubs/ignore6/ignoredFolder/ignored.md\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Fixes #2394 addings `.git/**` to the default list of ignores.
684
30.06.2022 19:48:33
-7,200
5f721af395fd8c8af4aed86c6a674eb3498eb182
Rename data to messages
[ { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -14,8 +14,8 @@ module.exports = function (config) {\nlet pathPrefix = pathPrefixOverride || templateConfig.getPathPrefix();\nreturn urlFilter.call(this, url, pathPrefix);\n});\n- config.addFilter(\"log\", (input, ...data) => {\n- console.log(input, ...data);\n+ config.addFilter(\"log\", (input, ...messages) => {\n+ console.log(input, ...messages);\nreturn input;\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Rename data to messages
699
30.06.2022 15:44:11
18,000
36383ba28228a7b5fb96198ed65c5d0c9e5b8862
Tweak to for ci
[ { "change_type": "MODIFY", "old_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "new_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "diff": "@@ -326,7 +326,7 @@ test(\"De-duplicated ignores\", (t) => {\nt.deepEqual(evf.getIgnores(), [\n\"./test/stubs/ignore-dedupe/node_modules/**\",\n\"./test/stubs/ignore-dedupe/.git/**\",\n- \"./test/stubs/ignore-dedupe/ignoredFolder/**\",\n+ \"./test/stubs/ignore-dedupe/ignoredFolder\",\n\"./test/stubs/ignore-dedupe/_site/**\",\n]);\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Tweak to #2472 for ci
699
01.07.2022 11:03:09
18,000
6873099e537f04aa903a950ea903f046f8827697
Cleanup the static methods littered throughout
[ { "change_type": "MODIFY", "old_path": "test/TemplatePermalinkTest.js", "new_path": "test/TemplatePermalinkTest.js", "diff": "const test = require(\"ava\");\nconst TemplatePermalink = require(\"../src/TemplatePermalink\");\n+const { generate } = TemplatePermalink;\ntest(\"Simple straight permalink\", (t) => {\nt.is(\n@@ -75,67 +76,61 @@ test(\"Permalink with pagination subdir\", (t) => {\n});\ntest(\"Permalink generate\", (t) => {\n- let gen = TemplatePermalink.generate;\n-\n- t.is(gen(\"./\", \"index\").toOutputPath(), \"index.html\");\n- t.is(gen(\"./\", \"index\").toHref(), \"/\");\n- t.is(gen(\".\", \"index\").toOutputPath(), \"index.html\");\n- t.is(gen(\".\", \"index\").toHref(), \"/\");\n- t.is(gen(\".\", \"test\").toOutputPath(), \"test/index.html\");\n- t.is(gen(\".\", \"test\").toHref(), \"/test/\");\n- t.is(gen(\".\", \"test\", \"0/\").toOutputPath(), \"test/0/index.html\");\n- t.is(gen(\".\", \"test\", \"0/\").toHref(), \"/test/0/\");\n- t.is(gen(\".\", \"test\", \"1/\").toOutputPath(), \"test/1/index.html\");\n- t.is(gen(\".\", \"test\", \"1/\").toHref(), \"/test/1/\");\n+ t.is(generate(\"./\", \"index\").toOutputPath(), \"index.html\");\n+ t.is(generate(\"./\", \"index\").toHref(), \"/\");\n+ t.is(generate(\".\", \"index\").toOutputPath(), \"index.html\");\n+ t.is(generate(\".\", \"index\").toHref(), \"/\");\n+ t.is(generate(\".\", \"test\").toOutputPath(), \"test/index.html\");\n+ t.is(generate(\".\", \"test\").toHref(), \"/test/\");\n+ t.is(generate(\".\", \"test\", \"0/\").toOutputPath(), \"test/0/index.html\");\n+ t.is(generate(\".\", \"test\", \"0/\").toHref(), \"/test/0/\");\n+ t.is(generate(\".\", \"test\", \"1/\").toOutputPath(), \"test/1/index.html\");\n+ t.is(generate(\".\", \"test\", \"1/\").toHref(), \"/test/1/\");\n});\ntest(\"Permalink generate with suffix\", (t) => {\n- let gen = TemplatePermalink.generate;\n-\n- t.is(gen(\".\", \"test\", null, \"-o\").toOutputPath(), \"test/index-o.html\");\n- t.is(gen(\".\", \"test\", null, \"-o\").toHref(), \"/test/index-o.html\");\n- t.is(gen(\".\", \"test\", \"1/\", \"-o\").toOutputPath(), \"test/1/index-o.html\");\n- t.is(gen(\".\", \"test\", \"1/\", \"-o\").toHref(), \"/test/1/index-o.html\");\n+ t.is(generate(\".\", \"test\", null, \"-o\").toOutputPath(), \"test/index-o.html\");\n+ t.is(generate(\".\", \"test\", null, \"-o\").toHref(), \"/test/index-o.html\");\n+ t.is(generate(\".\", \"test\", \"1/\", \"-o\").toOutputPath(), \"test/1/index-o.html\");\n+ t.is(generate(\".\", \"test\", \"1/\", \"-o\").toHref(), \"/test/1/index-o.html\");\n});\ntest(\"Permalink generate with new extension\", (t) => {\n- let gen = TemplatePermalink.generate;\n-\n- t.is(gen(\".\", \"test\", null, null, \"css\").toOutputPath(), \"test.css\");\n- t.is(gen(\".\", \"test\", null, null, \"css\").toHref(), \"/test.css\");\n- t.is(gen(\".\", \"test\", \"1/\", null, \"css\").toOutputPath(), \"1/test.css\");\n- t.is(gen(\".\", \"test\", \"1/\", null, \"css\").toHref(), \"/1/test.css\");\n+ t.is(generate(\".\", \"test\", null, null, \"css\").toOutputPath(), \"test.css\");\n+ t.is(generate(\".\", \"test\", null, null, \"css\").toHref(), \"/test.css\");\n+ t.is(generate(\".\", \"test\", \"1/\", null, \"css\").toOutputPath(), \"1/test.css\");\n+ t.is(generate(\".\", \"test\", \"1/\", null, \"css\").toHref(), \"/1/test.css\");\n});\ntest(\"Permalink generate with subfolders\", (t) => {\n- let gen = TemplatePermalink.generate;\n-\nt.is(\n- gen(\"permalinksubfolder/\", \"index\").toOutputPath(),\n+ generate(\"permalinksubfolder/\", \"index\").toOutputPath(),\n\"permalinksubfolder/index.html\"\n);\nt.is(\n- gen(\"permalinksubfolder/\", \"test\").toOutputPath(),\n+ generate(\"permalinksubfolder/\", \"test\").toOutputPath(),\n\"permalinksubfolder/test/index.html\"\n);\nt.is(\n- gen(\"permalinksubfolder/\", \"test\", \"1/\", \"-o\").toOutputPath(),\n+ generate(\"permalinksubfolder/\", \"test\", \"1/\", \"-o\").toOutputPath(),\n\"permalinksubfolder/test/1/index-o.html\"\n);\n- t.is(gen(\"permalinksubfolder/\", \"index\").toHref(), \"/permalinksubfolder/\");\nt.is(\n- gen(\"permalinksubfolder/\", \"test\").toHref(),\n+ generate(\"permalinksubfolder/\", \"index\").toHref(),\n+ \"/permalinksubfolder/\"\n+ );\n+ t.is(\n+ generate(\"permalinksubfolder/\", \"test\").toHref(),\n\"/permalinksubfolder/test/\"\n);\nt.is(\n- gen(\"permalinksubfolder/\", \"test\", \"1/\", \"-o\").toHref(),\n+ generate(\"permalinksubfolder/\", \"test\", \"1/\", \"-o\").toHref(),\n\"/permalinksubfolder/test/1/index-o.html\"\n);\n});\ntest(\"Permalink matching folder and filename\", (t) => {\n- let gen = TemplatePermalink.generate;\nlet hasDupe = TemplatePermalink._hasDuplicateFolder;\nt.is(hasDupe(\"subfolder\", \"component\"), false);\nt.is(hasDupe(\"subfolder/\", \"component\"), false);\n@@ -144,8 +139,11 @@ test(\"Permalink matching folder and filename\", (t) => {\nt.is(hasDupe(\"component\", \"component\"), true);\nt.is(hasDupe(\"component/\", \"component\"), true);\n- t.is(gen(\"component/\", \"component\").toOutputPath(), \"component/index.html\");\n- t.is(gen(\"component/\", \"component\").toHref(), \"/component/\");\n+ t.is(\n+ generate(\"component/\", \"component\").toOutputPath(),\n+ \"component/index.html\"\n+ );\n+ t.is(generate(\"component/\", \"component\").toHref(), \"/component/\");\n});\ntest(\"Permalink Object, just build\", (t) => {\n" } ]
JavaScript
MIT License
11ty/eleventy
Cleanup the static methods littered throughout
699
01.07.2022 11:58:05
18,000
93f690c1a4bb3238b03dfde0b2c67c2211959803
Duplicates should be tied to output paths not urls
[ { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -632,8 +632,8 @@ class TemplateMap {\nfor (let page of entry._pages) {\nif (page.outputPath === false || page.url === false) {\n// do nothing (also serverless)\n- } else if (!permalinks[page.url]) {\n- permalinks[page.url] = [entry.inputPath];\n+ } else if (!permalinks[page.outputPath]) {\n+ permalinks[page.outputPath] = [entry.inputPath];\n} else {\nwarnings[\npage.outputPath\n@@ -641,14 +641,14 @@ class TemplateMap {\npage.outputPath\n}\\`. Use distinct \\`permalink\\` values to resolve this conflict.\n1. ${entry.inputPath}\n-${permalinks[page.url]\n+${permalinks[page.outputPath]\n.map(function (inputPath, index) {\nreturn ` ${index + 2}. ${inputPath}\\n`;\n})\n.join(\"\")}\n`;\n- permalinks[page.url].push(entry.inputPath);\n+ permalinks[page.outputPath].push(entry.inputPath);\n}\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Duplicates should be tied to output paths not urls
699
01.07.2022 16:49:34
18,000
22e8a02744a6e874802fc02b0336a2b2dcc4910f
Fix with great analysis and assist from
[ { "change_type": "MODIFY", "old_path": "src/Engines/Nunjucks.js", "new_path": "src/Engines/Nunjucks.js", "diff": "@@ -190,7 +190,10 @@ class Nunjucks extends TemplateEngine {\nshortcodeFn\n.call(Nunjucks._normalizeShortcodeContext(context), ...argArray)\n.then(function (returnValue) {\n- resolve(null, new NunjucksLib.runtime.SafeString(returnValue));\n+ resolve(\n+ null,\n+ new NunjucksLib.runtime.SafeString(\"\" + returnValue)\n+ );\n})\n.catch(function (e) {\nresolve(\n@@ -204,12 +207,11 @@ class Nunjucks extends TemplateEngine {\n});\n} else {\ntry {\n- return new NunjucksLib.runtime.SafeString(\n- shortcodeFn.call(\n+ let ret = shortcodeFn.call(\nNunjucks._normalizeShortcodeContext(context),\n...argArray\n- )\n);\n+ return new NunjucksLib.runtime.SafeString(\"\" + ret);\n} catch (e) {\nthrow new EleventyShortcodeError(\n`Error with Nunjucks shortcode \\`${shortcodeName}\\`${EleventyErrorUtil.convertErrorToString(\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateRenderNunjucksTest.js", "new_path": "test/TemplateRenderNunjucksTest.js", "diff": "@@ -489,6 +489,15 @@ test(\"Nunjucks Shortcode Safe Output\", async (t) => {\n);\n});\n+test(\"Nunjucks Shortcode return non-string value\", async (t) => {\n+ let tr = getNewTemplateRender(\"njk\", \"./test/stubs/\");\n+ tr.engine.addShortcode(\"getYear\", function () {\n+ return 2022;\n+ });\n+\n+ t.is(await tr._testRender(\"{% getYear %}\"), \"2022\");\n+});\n+\ntest(\"Nunjucks Paired Shortcode\", async (t) => {\nt.plan(2);\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix #856 with great analysis and assist from @KyleMit!
699
01.07.2022 17:46:03
18,000
dc7993958779850b720c42bc1ae424974177fabf
Add url transforms feature for
[ { "change_type": "MODIFY", "old_path": "src/Template.js", "new_path": "src/Template.js", "diff": "@@ -171,6 +171,8 @@ class Template extends TemplateContent {\npermalinkValue,\nthis.extraOutputSubdirectory\n);\n+ perm.setUrlTransforms(this.config.urlTransforms);\n+\nif (this.templateData) {\nperm.setServerlessPathData(this.templateData.getServerlessPathData());\n}\n@@ -274,13 +276,15 @@ class Template extends TemplateContent {\n}\n// No `permalink` specified in data cascade, do the default\n- return TemplatePermalink.generate(\n+ let p = TemplatePermalink.generate(\nthis.getTemplateSubfolder(),\nthis.baseFile,\nthis.extraOutputSubdirectory,\nthis.htmlIOException ? this.config.htmlOutputSuffix : \"\",\nthis.engine.defaultTemplateFileExtension\n);\n+ p.setUrlTransforms(this.config.urlTransforms);\n+ return p;\n}\nasync usePermalinkRoot() {\n" }, { "change_type": "MODIFY", "old_path": "src/TemplatePermalink.js", "new_path": "src/TemplatePermalink.js", "diff": "@@ -66,6 +66,14 @@ class TemplatePermalink {\nthis.extraPaginationSubdir = extraSubdir || \"\";\n}\n+ setUrlTransforms(transforms) {\n+ this._urlTransforms = transforms;\n+ }\n+\n+ get urlTransforms() {\n+ return this._urlTransforms || [];\n+ }\n+\nsetServerlessPathData(data) {\nthis.serverlessPathData = data;\n}\n@@ -131,12 +139,25 @@ class TemplatePermalink {\nlet transformedLink = this.toOutputPath();\nlet original =\n(transformedLink.charAt(0) !== \"/\" ? \"/\" : \"\") + transformedLink;\n- let needle = \"/index.html\";\n- if (original === needle) {\n- return \"/\";\n- } else if (original.slice(-1 * needle.length) === needle) {\n- return original.slice(0, original.length - needle.length) + \"/\";\n+\n+ for (let transform of this.urlTransforms) {\n+ original = transform({ outputPath: original }) ?? original;\n+ }\n+\n+ let needleHtml = \"/index.html\";\n+ let needleBare = \"/index\";\n+ let needleBareTrailingSlash = \"/index/\";\n+ if (original.endsWith(needleHtml)) {\n+ return original.slice(0, original.length - needleHtml.length) + \"/\";\n+ } else if (original.endsWith(needleBare)) {\n+ return original.slice(0, original.length - needleBare.length) + \"/\";\n+ } else if (original.endsWith(needleBareTrailingSlash)) {\n+ return (\n+ original.slice(0, original.length - needleBareTrailingSlash.length) +\n+ \"/\"\n+ );\n}\n+\nreturn original;\n}\n@@ -183,12 +204,13 @@ class TemplatePermalink {\nsuffix,\nfileExtension = \"html\"\n) {\n+ let path;\n+ if (fileExtension === \"html\") {\nlet hasDupeFolder = TemplatePermalink._hasDuplicateFolder(\ndir,\nfilenameNoExt\n);\n- let path;\n- if (fileExtension === \"html\") {\n+\npath =\n(dir ? dir + \"/\" : \"\") +\n(filenameNoExt !== \"index\" && !hasDupeFolder\n" }, { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -91,8 +91,8 @@ class UserConfig {\nthis.dataFilterSelectors = new Set();\nthis.libraryAmendments = {};\n-\nthis.serverPassthroughCopyBehavior = \"passthrough\";\n+ this.urlTransforms = [];\n}\nversionCheck(expected) {\n@@ -812,6 +812,10 @@ class UserConfig {\nthis.serverPassthroughCopyBehavior = behavior;\n}\n+ addUrlTransform(callback) {\n+ this.urlTransforms.push(callback);\n+ }\n+\ngetMergingConfigObject() {\nreturn {\ntemplateFormats: this.templateFormats,\n@@ -866,6 +870,7 @@ class UserConfig {\ndataFilterSelectors: this.dataFilterSelectors,\nlibraryAmendments: this.libraryAmendments,\nserverPassthroughCopyBehavior: this.serverPassthroughCopyBehavior,\n+ urlTransforms: this.urlTransforms,\n};\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "test/TemplatePermalinkTest.js", "new_path": "test/TemplatePermalinkTest.js", "diff": "@@ -265,3 +265,231 @@ test(\"Permalink Object, serverless with path params\", (t) => {\n});\nt.is(perm.toHref(), \"/serverless/yeearg/\");\n});\n+\n+test(\"Permalink generate apache content negotiation #761\", (t) => {\n+ let tp = new TemplatePermalink(\"index.es.html\");\n+ tp.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/\";\n+ },\n+ ]);\n+\n+ t.is(tp.toHref(), \"/\");\n+ t.is(tp.toOutputPath(), \"index.es.html\");\n+\n+ // Note that generate does some preprocessing to the raw permalink value (compared to `new TemplatePermalink`)\n+ let tp1 = TemplatePermalink.generate(\"\", \"index.es\");\n+ tp1.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/\";\n+ },\n+ ]);\n+ t.is(tp1.toHref(), \"/\");\n+ // best paired with https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem for index.es.html\n+ t.is(tp1.toOutputPath(), \"index.es/index.html\");\n+});\n+\n+test(\"Permalink generate apache content negotiation with subdirectory #761\", (t) => {\n+ let tp = new TemplatePermalink(\"test/index.es.html\");\n+ tp.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/test/\";\n+ },\n+ ]);\n+\n+ t.is(tp.toHref(), \"/test/\");\n+ t.is(tp.toOutputPath(), \"test/index.es.html\");\n+\n+ // Note that generate does some preprocessing to the raw permalink value (compared to `new TemplatePermalink`)\n+ let tp1 = TemplatePermalink.generate(\"test\", \"index.es\");\n+ tp1.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/test/\";\n+ },\n+ ]);\n+\n+ t.is(tp1.toHref(), \"/test/\");\n+ // best paired with https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem for test/index.es.html\n+ t.is(tp1.toOutputPath(), \"test/index.es/index.html\");\n+});\n+\n+test(\"Permalink generate apache content negotiation non-index file name #761\", (t) => {\n+ // Note that generate does some preprocessing to the raw permalink value (compared to `new TemplatePermalink`)\n+ let tp = TemplatePermalink.generate(\"permalinksubfolder\", \"about.es\");\n+\n+ t.is(tp.toHref(), \"/permalinksubfolder/about.es/\");\n+ t.is(tp.toOutputPath(), \"permalinksubfolder/about.es/index.html\");\n+});\n+\n+test(\"Permalink generate with urlTransforms #761\", (t) => {\n+ // Note that TemplatePermalink.generate is used by Template and different from new TemplatePermalink\n+ let tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\n+\n+ tp.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/permalinksubfolder/\";\n+ },\n+ ]);\n+\n+ t.is(tp.toHref(), \"/permalinksubfolder/\");\n+ // best paired with https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem for permalinksubfolder/index.es.html\n+ t.is(tp.toOutputPath(), \"permalinksubfolder/index.es/index.html\");\n+});\n+\n+test(\"Permalink generate with urlTransforms (skip via undefined) #761\", (t) => {\n+ // Note that TemplatePermalink.generate is used by Template and different from new TemplatePermalink\n+ let tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\n+\n+ tp.setUrlTransforms([\n+ function ({ outputPath }) {\n+ // return nothing\n+ },\n+ ]);\n+\n+ t.is(tp.toHref(), \"/permalinksubfolder/index.es/\");\n+ // best paired with https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem for permalinksubfolder/index.es.html\n+ t.is(tp.toOutputPath(), \"permalinksubfolder/index.es/index.html\");\n+});\n+\n+test(\"Permalink generate with 2 urlTransforms #761\", (t) => {\n+ // Note that TemplatePermalink.generate is used by Template and different from new TemplatePermalink\n+ let tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\n+ tp.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/abc/\";\n+ },\n+ function ({ outputPath }) {\n+ return \"/def/\";\n+ },\n+ ]);\n+\n+ t.is(tp.toHref(), \"/def/\");\n+ // best paired with https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem for permalinksubfolder/index.es.html\n+ t.is(tp.toOutputPath(), \"permalinksubfolder/index.es/index.html\");\n+});\n+\n+test(\"Permalink generate with urlTransforms returns index.html #761\", (t) => {\n+ // Note that TemplatePermalink.generate is used by Template and different from new TemplatePermalink\n+ let tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\n+ tp.setUrlTransforms([\n+ function ({ outputPath }) {\n+ return \"/abc/index.html\";\n+ },\n+ ]);\n+\n+ t.is(tp.toHref(), \"/abc/\");\n+ // best paired with https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem for permalinksubfolder/index.es.html\n+ t.is(tp.toOutputPath(), \"permalinksubfolder/index.es/index.html\");\n+});\n+\n+test(\"Permalink generate with urlTransforms code (index file) #761\", (t) => {\n+ let tp1 = new TemplatePermalink(\"index.es.html\");\n+\n+ tp1.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp1.toHref(), \"/\");\n+\n+ let tp2 = new TemplatePermalink(\"index.es.html\");\n+\n+ tp2.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // no trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length);\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp2.toHref(), \"/\");\n+});\n+\n+test(\"Permalink generate with urlTransforms code (not index file) #761\", (t) => {\n+ let tp1 = new TemplatePermalink(\"about.es.html\");\n+\n+ tp1.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp1.toHref(), \"/about/\");\n+\n+ let tp2 = new TemplatePermalink(\"about.es.html\");\n+\n+ tp2.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // no trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length);\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp2.toHref(), \"/about\");\n+});\n+\n+test(\"Permalink generate with urlTransforms code (index file with subdir) #761\", (t) => {\n+ let tp1 = new TemplatePermalink(\"subdir/index.es.html\");\n+\n+ tp1.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp1.toHref(), \"/subdir/\");\n+\n+ let tp2 = new TemplatePermalink(\"subdir/index.es.html\");\n+\n+ tp2.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // no trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length);\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp2.toHref(), \"/subdir/\");\n+});\n+\n+test(\"Permalink generate with urlTransforms code (not-index file with subdir) #761\", (t) => {\n+ let tp1 = new TemplatePermalink(\"subdir/about.es.html\");\n+\n+ tp1.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp1.toHref(), \"/subdir/about/\");\n+\n+ let tp2 = new TemplatePermalink(\"subdir/about.es.html\");\n+\n+ tp2.setUrlTransforms([\n+ function ({ outputPath }) {\n+ if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ // no trailing slash\n+ return outputPath.slice(0, -1 * \".en.html\".length);\n+ }\n+ },\n+ ]);\n+\n+ t.is(tp2.toHref(), \"/subdir/about\");\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
Add url transforms feature for https://github.com/11ty/eleventy/issues/761
681
03.07.2022 00:52:15
-19,080
d6b5af189cd10148ce01ddef4cb6bf6004c7e251
ci: use node matrix
[ { "change_type": "MODIFY", "old_path": ".github/workflows/ci.yml", "new_path": ".github/workflows/ci.yml", "diff": "@@ -15,7 +15,7 @@ jobs:\n- name: Setup node\nuses: actions/setup-node@v3\nwith:\n- node-version: '16.x'\n+ node-version: ${{ matrix.node }}\n# cache: npm\n- run: npm install\n- run: npm test\n" } ]
JavaScript
MIT License
11ty/eleventy
ci: use node matrix
699
08.07.2022 17:19:54
18,000
333279db9ca8376b1614119b5c40affedd136be4
Initial commit of the i18n plugin (utils for i18n permalinks and urls)
[ { "change_type": "MODIFY", "old_path": "src/Eleventy.js", "new_path": "src/Eleventy.js", "diff": "@@ -1162,3 +1162,4 @@ module.exports.EleventyServerless = require(\"./Serverless\");\nmodule.exports.EleventyServerlessBundlerPlugin = require(\"./Plugins/ServerlessBundlerPlugin\");\nmodule.exports.EleventyRenderPlugin = require(\"./Plugins/RenderPlugin\");\nmodule.exports.EleventyEdgePlugin = require(\"./Plugins/EdgePlugin\");\n+module.exports.EleventyI18nPlugin = require(\"./Plugins/I18nPlugin\");\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -360,6 +360,11 @@ class TemplateMap {\n}.bind(this)\n);\n+ await this.config.events.emit(\"eleventy.contentMap\", {\n+ inputPathToUrl: this.generateContentMap(orderedMap),\n+ urlToInputPath: this.generateUrlMap(orderedMap),\n+ });\n+\nawait this.populateContentDataInMap(orderedMap);\nthis.populateCollectionsWithContent();\n@@ -373,6 +378,27 @@ class TemplateMap {\n);\n}\n+ generateContentMap(orderedMap) {\n+ let entries = {};\n+ for (let entry of orderedMap) {\n+ entries[entry.inputPath] = entry._pages.map((entry) => entry.url);\n+ }\n+ return entries;\n+ }\n+\n+ generateUrlMap(orderedMap) {\n+ let entries = {};\n+ for (let entry of orderedMap) {\n+ for (let page of entry._pages) {\n+ if (!entries[page.url]) {\n+ entries[page.url] = [];\n+ }\n+ entries[page.url].push(entry.inputPath);\n+ }\n+ }\n+ return entries;\n+ }\n+\ngenerateServerlessUrlMap(orderedMap) {\nlet entries = [];\nfor (let entry of orderedMap) {\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/I18nPluginTest.js", "diff": "+const test = require(\"ava\");\n+const { Comparator } = require(\"../src/Plugins/I18nPlugin\");\n+\n+test(\"Comparator.isLangCode\", (t) => {\n+ t.is(Comparator.isLangCode(\"en\"), true);\n+ t.is(Comparator.isLangCode(\"en-us\"), true);\n+ t.is(Comparator.isLangCode(\"en_us\"), true);\n+\n+ t.is(Comparator.isLangCode(\"d\"), false);\n+ t.is(Comparator.isLangCode(\"dee\"), false);\n+ t.is(Comparator.isLangCode(\"deed\"), false);\n+ t.is(Comparator.isLangCode(\"deede\"), false);\n+ t.is(Comparator.isLangCode(\"deedee\"), false);\n+});\n+\n+test(\"Comparator.matchLanguageFolder\", (t) => {\n+ // Note that template extensions are removed upstream by the plugin\n+ t.is(Comparator.matchLanguageFolder(\"/en/test.hbs\", \"/es/test.hbs\"), true);\n+ t.is(Comparator.matchLanguageFolder(\"/en/test\", \"/es/test\"), true);\n+ t.is(Comparator.matchLanguageFolder(\"/en_us/test\", \"/es/test\"), true);\n+ t.is(Comparator.matchLanguageFolder(\"/es_mx/test\", \"/en-us/test\"), true);\n+\n+ // invalid first\n+ t.is(Comparator.matchLanguageFolder(\"/e/test.hbs\", \"/es/test.hbs\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/n/test\", \"/es/test\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/eus/test\", \"/es/test\"), false);\n+\n+ // invalid second\n+ t.is(Comparator.matchLanguageFolder(\"/en/test.hbs\", \"/e/test.hbs\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/en/test\", \"/e/test\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/en_us/test\", \"/s/test\"), false);\n+\n+ // both invalid\n+ t.is(Comparator.matchLanguageFolder(\"/esx/test\", \"/ens/test\"), false);\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
Initial commit of the i18n plugin (utils for i18n permalinks and urls)
699
11.07.2022 12:13:23
18,000
39a19c385d7244bf0c2ddd16c82846348005a843
Use `url` and `urlStem` for url transforms, not output path.
[ { "change_type": "MODIFY", "old_path": "src/TemplatePermalink.js", "new_path": "src/TemplatePermalink.js", "diff": "@@ -102,6 +102,34 @@ class TemplatePermalink {\n);\n}\n+ // Used in url transforms feature\n+ static getUrlStem(original) {\n+ let subject = original;\n+ if (original.endsWith(\".html\")) {\n+ subject = original.slice(0, -1 * \".html\".length);\n+ }\n+ return TemplatePermalink.normalizePathToUrl(subject);\n+ }\n+\n+ static normalizePathToUrl(original) {\n+ let compare = original || \"\";\n+\n+ let needleHtml = \"/index.html\";\n+ let needleBareTrailingSlash = \"/index/\";\n+ let needleBare = \"/index\";\n+ if (compare.endsWith(needleHtml)) {\n+ return compare.slice(0, compare.length - needleHtml.length) + \"/\";\n+ } else if (compare.endsWith(needleBareTrailingSlash)) {\n+ return (\n+ compare.slice(0, compare.length - needleBareTrailingSlash.length) + \"/\"\n+ );\n+ } else if (compare.endsWith(needleBare)) {\n+ return compare.slice(0, compare.length - needleBare.length) + \"/\";\n+ }\n+\n+ return original;\n+ }\n+\n// This method is used to generate the `page.url` variable.\n// Note that in serverless mode this should still exist to generate the content map\n@@ -140,25 +168,16 @@ class TemplatePermalink {\nlet original =\n(transformedLink.charAt(0) !== \"/\" ? \"/\" : \"\") + transformedLink;\n+ let normalized = TemplatePermalink.normalizePathToUrl(original) || \"\";\nfor (let transform of this.urlTransforms) {\n- original = transform({ outputPath: original }) ?? original;\n+ original =\n+ transform({\n+ url: normalized,\n+ urlStem: TemplatePermalink.getUrlStem(original),\n+ }) ?? original;\n}\n- let needleHtml = \"/index.html\";\n- let needleBare = \"/index\";\n- let needleBareTrailingSlash = \"/index/\";\n- if (original.endsWith(needleHtml)) {\n- return original.slice(0, original.length - needleHtml.length) + \"/\";\n- } else if (original.endsWith(needleBare)) {\n- return original.slice(0, original.length - needleBare.length) + \"/\";\n- } else if (original.endsWith(needleBareTrailingSlash)) {\n- return (\n- original.slice(0, original.length - needleBareTrailingSlash.length) +\n- \"/\"\n- );\n- }\n-\n- return original;\n+ return TemplatePermalink.normalizePathToUrl(original);\n}\ntoPath(outputDir) {\n" }, { "change_type": "MODIFY", "old_path": "test/TemplatePermalinkTest.js", "new_path": "test/TemplatePermalinkTest.js", "diff": "@@ -269,7 +269,7 @@ test(\"Permalink Object, serverless with path params\", (t) => {\ntest(\"Permalink generate apache content negotiation #761\", (t) => {\nlet tp = new TemplatePermalink(\"index.es.html\");\ntp.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/\";\n},\n]);\n@@ -280,7 +280,7 @@ test(\"Permalink generate apache content negotiation #761\", (t) => {\n// Note that generate does some preprocessing to the raw permalink value (compared to `new TemplatePermalink`)\nlet tp1 = TemplatePermalink.generate(\"\", \"index.es\");\ntp1.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/\";\n},\n]);\n@@ -292,7 +292,7 @@ test(\"Permalink generate apache content negotiation #761\", (t) => {\ntest(\"Permalink generate apache content negotiation with subdirectory #761\", (t) => {\nlet tp = new TemplatePermalink(\"test/index.es.html\");\ntp.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/test/\";\n},\n]);\n@@ -303,7 +303,7 @@ test(\"Permalink generate apache content negotiation with subdirectory #761\", (t)\n// Note that generate does some preprocessing to the raw permalink value (compared to `new TemplatePermalink`)\nlet tp1 = TemplatePermalink.generate(\"test\", \"index.es\");\ntp1.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/test/\";\n},\n]);\n@@ -326,7 +326,7 @@ test(\"Permalink generate with urlTransforms #761\", (t) => {\nlet tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\ntp.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/permalinksubfolder/\";\n},\n]);\n@@ -341,7 +341,7 @@ test(\"Permalink generate with urlTransforms (skip via undefined) #761\", (t) => {\nlet tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\ntp.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\n// return nothing\n},\n]);\n@@ -355,10 +355,10 @@ test(\"Permalink generate with 2 urlTransforms #761\", (t) => {\n// Note that TemplatePermalink.generate is used by Template and different from new TemplatePermalink\nlet tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\ntp.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/abc/\";\n},\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/def/\";\n},\n]);\n@@ -372,7 +372,7 @@ test(\"Permalink generate with urlTransforms returns index.html #761\", (t) => {\n// Note that TemplatePermalink.generate is used by Template and different from new TemplatePermalink\nlet tp = TemplatePermalink.generate(\"permalinksubfolder\", \"index.es\");\ntp.setUrlTransforms([\n- function ({ outputPath }) {\n+ function ({ url }) {\nreturn \"/abc/index.html\";\n},\n]);\n@@ -386,10 +386,13 @@ test(\"Permalink generate with urlTransforms code (index file) #761\", (t) => {\nlet tp1 = new TemplatePermalink(\"index.es.html\");\ntp1.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ t.is(url, \"/index.es.html\");\n+ t.is(urlStem, \"/index.es\");\n+\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ return url.slice(0, -1 * \".en.html\".length) + \"/\";\n}\n},\n]);\n@@ -399,10 +402,13 @@ test(\"Permalink generate with urlTransforms code (index file) #761\", (t) => {\nlet tp2 = new TemplatePermalink(\"index.es.html\");\ntp2.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ t.is(url, \"/index.es.html\");\n+ t.is(urlStem, \"/index.es\");\n+\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// no trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length);\n+ return url.slice(0, -1 * \".en.html\".length);\n}\n},\n]);\n@@ -414,10 +420,13 @@ test(\"Permalink generate with urlTransforms code (not index file) #761\", (t) =>\nlet tp1 = new TemplatePermalink(\"about.es.html\");\ntp1.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ t.is(url, \"/about.es.html\");\n+ t.is(urlStem, \"/about.es\");\n+\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ return url.slice(0, -1 * \".en.html\".length) + \"/\";\n}\n},\n]);\n@@ -427,10 +436,10 @@ test(\"Permalink generate with urlTransforms code (not index file) #761\", (t) =>\nlet tp2 = new TemplatePermalink(\"about.es.html\");\ntp2.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url }) {\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// no trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length);\n+ return url.slice(0, -1 * \".en.html\".length);\n}\n},\n]);\n@@ -442,10 +451,13 @@ test(\"Permalink generate with urlTransforms code (index file with subdir) #761\",\nlet tp1 = new TemplatePermalink(\"subdir/index.es.html\");\ntp1.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ t.is(url, \"/subdir/index.es.html\");\n+ t.is(urlStem, \"/subdir/index.es\");\n+\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ return url.slice(0, -1 * \".en.html\".length) + \"/\";\n}\n},\n]);\n@@ -455,10 +467,13 @@ test(\"Permalink generate with urlTransforms code (index file with subdir) #761\",\nlet tp2 = new TemplatePermalink(\"subdir/index.es.html\");\ntp2.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ t.is(url, \"/subdir/index.es.html\");\n+ t.is(urlStem, \"/subdir/index.es\");\n+\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// no trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length);\n+ return url.slice(0, -1 * \".en.html\".length);\n}\n},\n]);\n@@ -470,10 +485,13 @@ test(\"Permalink generate with urlTransforms code (not-index file with subdir) #7\nlet tp1 = new TemplatePermalink(\"subdir/about.es.html\");\ntp1.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n+ t.is(url, \"/subdir/about.es.html\");\n+ t.is(urlStem, \"/subdir/about.es\");\n+\n// trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length) + \"/\";\n+ return url.slice(0, -1 * \".en.html\".length) + \"/\";\n}\n},\n]);\n@@ -483,10 +501,13 @@ test(\"Permalink generate with urlTransforms code (not-index file with subdir) #7\nlet tp2 = new TemplatePermalink(\"subdir/about.es.html\");\ntp2.setUrlTransforms([\n- function ({ outputPath }) {\n- if ((outputPath || \"\").match(new RegExp(\".[a-z]{2}.html$\", \"i\"))) {\n+ function ({ url, urlStem }) {\n+ t.is(url, \"/subdir/about.es.html\");\n+ t.is(urlStem, \"/subdir/about.es\");\n+\n+ if (url.match(/\\.[a-z]{2}\\.html$/i)) {\n// no trailing slash\n- return outputPath.slice(0, -1 * \".en.html\".length);\n+ return url.slice(0, -1 * \".en.html\".length);\n}\n},\n]);\n" } ]
JavaScript
MIT License
11ty/eleventy
Use `url` and `urlStem` for url transforms, not output path.
699
11.07.2022 12:13:52
18,000
3ec9fd062efead936e35af9328ca5a5dc9ace269
More tests for i18n plugin
[ { "change_type": "MODIFY", "old_path": "src/Filters/Url.js", "new_path": "src/Filters/Url.js", "diff": "@@ -15,7 +15,7 @@ module.exports = function (url, pathPrefix) {\n// work with undefined\nurl = url || \"\";\n- if (isValidUrl(url) || (url.indexOf(\"//\") === 0 && url !== \"//\")) {\n+ if (isValidUrl(url) || (url.startsWith(\"//\") && url !== \"//\")) {\nreturn url;\n}\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyTest.js", "new_path": "test/EleventyTest.js", "diff": "@@ -408,7 +408,6 @@ test(\"Eleventy addGlobalData should run once\", async (t) => {\n});\ntest(\"Eleventy addGlobalData can feed layouts to populate data cascade with layout data, issue #1245\", async (t) => {\n- let count = 0;\nlet elev = new Eleventy(\"./test/stubs-2145/\", \"./test/stubs-2145/_site\", {\nconfig: function (eleventyConfig) {\neleventyConfig.addGlobalData(\"layout\", () => \"layout.njk\");\n@@ -450,6 +449,7 @@ test(\"DateGitLastUpdated returns undefined on nonexistent path\", (t) => {\nt.is(DateGitLastUpdated(\"./test/invalid.invalid\"), undefined);\n});\n+/* This test writes to the console */\ntest(\"#2167: Pagination with permalink: false\", async (t) => {\nlet elev = new Eleventy(\"./test/stubs-2167/\", \"./test/stubs-2167/_site\");\nelev.setDryRun(true);\n@@ -568,3 +568,17 @@ test(\"#2224: date 'git created' populates page.date\", async (t) => {\ntest(\"DateGitFirstAdded returns undefined on nonexistent path\", async (t) => {\nt.is(DateGitFirstAdded(\"./test/invalid.invalid\"), undefined);\n});\n+\n+test(\"Does pathPrefix affect page URLs\", async (t) => {\n+ let elev = new Eleventy(\"./README.md\", \"./_site\", {\n+ config: function (eleventyConfig) {\n+ return {\n+ pathPrefix: \"/testdirectory/\",\n+ };\n+ },\n+ });\n+\n+ let results = await elev.toJSON();\n+ let [result] = results;\n+ t.is(result.url, \"/README/\");\n+});\n" }, { "change_type": "MODIFY", "old_path": "test/I18nPluginTest.js", "new_path": "test/I18nPluginTest.js", "diff": "const test = require(\"ava\");\n-const { Comparator } = require(\"../src/Plugins/I18nPlugin\");\n+const I18nPlugin = require(\"../src/Plugins/I18nPlugin\");\n+const { Comparator } = I18nPlugin;\n+const Eleventy = require(\"../src/Eleventy\");\n+const normalizeNewLines = require(\"./Util/normalizeNewLines\");\ntest(\"Comparator.isLangCode\", (t) => {\nt.is(Comparator.isLangCode(\"en\"), true);\n@@ -33,3 +36,72 @@ test(\"Comparator.matchLanguageFolder\", (t) => {\n// both invalid\nt.is(Comparator.matchLanguageFolder(\"/esx/test\", \"/ens/test\"), false);\n});\n+\n+test(\"contentMap Event from Eleventy\", async (t) => {\n+ t.plan(3);\n+ let elev = new Eleventy(\"./test/stubs-i18n/\", \"./test/stubs-i18n/_site\", {\n+ config: function (eleventyConfig) {\n+ eleventyConfig.addPlugin(I18nPlugin);\n+\n+ eleventyConfig.on(\"eleventy.contentMap\", (maps) => {\n+ t.truthy(maps);\n+ t.deepEqual(maps.urlToInputPath, {\n+ \"/en/\": [\"./test/stubs-i18n/en/index.liquid\"],\n+ \"/en_us/\": [\"./test/stubs-i18n/en_us/index.11ty.js\"],\n+ \"/es/\": [\"./test/stubs-i18n/es/index.njk\"],\n+ \"/non-lang-file/\": [\"./test/stubs-i18n/non-lang-file.njk\"],\n+ });\n+ t.deepEqual(maps.inputPathToUrl, {\n+ \"./test/stubs-i18n/en/index.liquid\": [\"/en/\"],\n+ \"./test/stubs-i18n/en_us/index.11ty.js\": [\"/en_us/\"],\n+ \"./test/stubs-i18n/es/index.njk\": [\"/es/\"],\n+ \"./test/stubs-i18n/non-lang-file.njk\": [\"/non-lang-file/\"],\n+ });\n+ });\n+ },\n+ });\n+\n+ let results = await elev.toJSON();\n+});\n+\n+function getContentFor(results, filename) {\n+ let content = results.filter((entry) => entry.inputPath.endsWith(filename))[0]\n+ .content;\n+ return normalizeNewLines(content.trim());\n+}\n+\n+test(\"locale_url and locale_links Filters\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-i18n/\", \"./test/stubs-i18n/_site\", {\n+ config: function (eleventyConfig) {\n+ eleventyConfig.addPlugin(I18nPlugin);\n+ },\n+ });\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/non-lang-file.njk\"),\n+ `/en/\n+/non-lang-file/`\n+ );\n+\n+ t.is(\n+ getContentFor(results, \"/es/index.njk\"),\n+ `/es/\n+/non-lang-file/\n+/en_us/,/en/`\n+ );\n+\n+ t.is(\n+ getContentFor(results, \"/en/index.liquid\"),\n+ `/en/\n+/non-lang-file/\n+/en_us//es/`\n+ );\n+\n+ t.is(\n+ getContentFor(results, \"/en_us/index.11ty.js\"),\n+ `/en_us/\n+/non-lang-file/\n+/en/,/es/`\n+ );\n+});\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-i18n/en/index.liquid", "diff": "+{{ \"/\" | locale_url }}\n+{{ \"/non-lang-file/\" | locale_url }}\n+{{ page.inputPath | locale_links }}\n\\ No newline at end of file\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-i18n/en_us/index.11ty.js", "diff": "+module.exports = function (data) {\n+ return `${this.locale_url(\"/\")}\n+${this.locale_url(\"/non-lang-file/\")}\n+${this.locale_links(data.page.inputPath).sort()}`;\n+};\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-i18n/es/index.njk", "diff": "+{{ \"/\" | locale_url }}\n+{{ \"/non-lang-file/\" | locale_url }}\n+{{ page.inputPath | locale_links }}\n\\ No newline at end of file\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-i18n/non-lang-file.njk", "diff": "+{{ \"/\" | locale_url }}\n+{{ \"/non-lang-file/\" | locale_url }}\n+{{ page.inputPath | locale_links }}\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
More tests for i18n plugin
699
11.07.2022 15:08:16
18,000
384960320be77d934c35d109c44b11b8dbc2b589
Standardize on BCP47 and ISO 639 language codes
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"@11ty/eleventy-utils\": \"^1.0.1\",\n\"@iarna/toml\": \"^2.2.5\",\n\"@sindresorhus/slugify\": \"^1.1.2\",\n+ \"bcp-47-normalize\": \"^1.1.1\",\n\"chokidar\": \"^3.5.3\",\n\"cross-spawn\": \"^7.0.3\",\n\"debug\": \"^4.3.4\",\n" }, { "change_type": "MODIFY", "old_path": "test/I18nPluginTest.js", "new_path": "test/I18nPluginTest.js", "diff": "@@ -5,12 +5,15 @@ const Eleventy = require(\"../src/Eleventy\");\nconst normalizeNewLines = require(\"./Util/normalizeNewLines\");\ntest(\"Comparator.isLangCode\", (t) => {\n+ t.is(Comparator.isLangCode(null), false);\n+ t.is(Comparator.isLangCode(undefined), false);\n+\nt.is(Comparator.isLangCode(\"en\"), true);\nt.is(Comparator.isLangCode(\"en-us\"), true);\n- t.is(Comparator.isLangCode(\"en_us\"), true);\n+ t.is(Comparator.isLangCode(\"dee\"), true);\n+ t.is(Comparator.isLangCode(\"en_us\"), false);\nt.is(Comparator.isLangCode(\"d\"), false);\n- t.is(Comparator.isLangCode(\"dee\"), false);\nt.is(Comparator.isLangCode(\"deed\"), false);\nt.is(Comparator.isLangCode(\"deede\"), false);\nt.is(Comparator.isLangCode(\"deedee\"), false);\n@@ -20,21 +23,21 @@ test(\"Comparator.matchLanguageFolder\", (t) => {\n// Note that template extensions are removed upstream by the plugin\nt.is(Comparator.matchLanguageFolder(\"/en/test.hbs\", \"/es/test.hbs\"), true);\nt.is(Comparator.matchLanguageFolder(\"/en/test\", \"/es/test\"), true);\n- t.is(Comparator.matchLanguageFolder(\"/en_us/test\", \"/es/test\"), true);\n- t.is(Comparator.matchLanguageFolder(\"/es_mx/test\", \"/en-us/test\"), true);\n+ t.is(Comparator.matchLanguageFolder(\"/en-us/test\", \"/es/test\"), true);\n+ t.is(Comparator.matchLanguageFolder(\"/es-mx/test\", \"/en-us/test\"), true);\n// invalid first\nt.is(Comparator.matchLanguageFolder(\"/e/test.hbs\", \"/es/test.hbs\"), false);\nt.is(Comparator.matchLanguageFolder(\"/n/test\", \"/es/test\"), false);\n- t.is(Comparator.matchLanguageFolder(\"/eus/test\", \"/es/test\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/eus/test\", \"/es/test\"), true);\n// invalid second\nt.is(Comparator.matchLanguageFolder(\"/en/test.hbs\", \"/e/test.hbs\"), false);\nt.is(Comparator.matchLanguageFolder(\"/en/test\", \"/e/test\"), false);\n- t.is(Comparator.matchLanguageFolder(\"/en_us/test\", \"/s/test\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/en-us/test\", \"/s/test\"), false);\n// both invalid\n- t.is(Comparator.matchLanguageFolder(\"/esx/test\", \"/ens/test\"), false);\n+ t.is(Comparator.matchLanguageFolder(\"/esx/test\", \"/ens/test\"), true);\n});\ntest(\"contentMap Event from Eleventy\", async (t) => {\n@@ -47,13 +50,13 @@ test(\"contentMap Event from Eleventy\", async (t) => {\nt.truthy(maps);\nt.deepEqual(maps.urlToInputPath, {\n\"/en/\": [\"./test/stubs-i18n/en/index.liquid\"],\n- \"/en_us/\": [\"./test/stubs-i18n/en_us/index.11ty.js\"],\n+ \"/en-us/\": [\"./test/stubs-i18n/en-us/index.11ty.js\"],\n\"/es/\": [\"./test/stubs-i18n/es/index.njk\"],\n\"/non-lang-file/\": [\"./test/stubs-i18n/non-lang-file.njk\"],\n});\nt.deepEqual(maps.inputPathToUrl, {\n\"./test/stubs-i18n/en/index.liquid\": [\"/en/\"],\n- \"./test/stubs-i18n/en_us/index.11ty.js\": [\"/en_us/\"],\n+ \"./test/stubs-i18n/en-us/index.11ty.js\": [\"/en-us/\"],\n\"./test/stubs-i18n/es/index.njk\": [\"/es/\"],\n\"./test/stubs-i18n/non-lang-file.njk\": [\"/non-lang-file/\"],\n});\n@@ -88,19 +91,19 @@ test(\"locale_url and locale_links Filters\", async (t) => {\ngetContentFor(results, \"/es/index.njk\"),\n`/es/\n/non-lang-file/\n-/en_us/,/en/`\n+/en-us/,/en/`\n);\nt.is(\ngetContentFor(results, \"/en/index.liquid\"),\n`/en/\n/non-lang-file/\n-/en_us//es/`\n+/en-us//es/`\n);\nt.is(\n- getContentFor(results, \"/en_us/index.11ty.js\"),\n- `/en_us/\n+ getContentFor(results, \"/en-us/index.11ty.js\"),\n+ `/en-us/\n/non-lang-file/\n/en/,/es/`\n);\n" }, { "change_type": "RENAME", "old_path": "test/stubs-i18n/en_us/index.11ty.js", "new_path": "test/stubs-i18n/en-us/index.11ty.js", "diff": "" } ]
JavaScript
MIT License
11ty/eleventy
Standardize on BCP47 and ISO 639 language codes
699
11.07.2022 15:09:01
18,000
b251f4685039ad4cd4cb0259dced514bb3804e01
Switch to ava 4, works fine with Node 18 (I had problems on my machine with Node 16)
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"@11ty/eleventy-plugin-syntaxhighlight\": \"^4.0.0\",\n\"@11ty/eleventy-plugin-vue\": \"1.0.0-canary.8\",\n\"@vue/server-renderer\": \"^3.2.33\",\n- \"ava\": \"^3.15.0\",\n+ \"ava\": \"^4.3.1\",\n\"husky\": \"^8.0.1\",\n\"js-yaml\": \"^4.1.0\",\n\"lint-staged\": \"^12.4.1\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Switch to ava 4, works fine with Node 18 (I had problems on my machine with Node 16)
723
12.07.2022 13:58:36
-7,200
8d60d170e86bada0366e7149adf878900f91e38a
Ignore nested node modules by default
[ { "change_type": "MODIFY", "old_path": "src/EleventyFiles.js", "new_path": "src/EleventyFiles.js", "diff": "@@ -118,7 +118,7 @@ class EleventyFiles {\n_setConfig(config) {\nif (!config.ignores) {\nconfig.ignores = new Set();\n- config.ignores.add(\"node_modules/**\");\n+ config.ignores.add(\"**/node_modules/**\");\n}\nthis.config = config;\nthis.initConfig();\n" }, { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -67,7 +67,7 @@ class UserConfig {\nthis.useGitIgnore = true;\nthis.ignores = new Set();\n- this.ignores.add(\"node_modules/**\");\n+ this.ignores.add(\"**/node_modules/**\");\nthis.ignores.add(\".git/**\");\nthis.dataDeepMerge = true;\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "new_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "diff": "@@ -19,7 +19,7 @@ test(\"Get ignores (no .eleventyignore no .gitignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n\"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore1/_site/**\",\n@@ -38,7 +38,7 @@ test(\"Get ignores (no .eleventyignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalrootgitignore\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalrootgitignore/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n\"./test/stubs/ignorelocalrootgitignore/.git/**\",\n\"./test/stubs/ignorelocalrootgitignore/thisshouldnotexist12345\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n@@ -65,7 +65,7 @@ test(\"Get ignores (no .eleventyignore, using setUseGitIgnore(false))\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore2/_site/**\",\n]);\n@@ -83,7 +83,7 @@ test(\"Get ignores (no .gitignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n\"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore3/ignoredFolder/**\",\n@@ -104,7 +104,7 @@ test(\"Get ignores (project .eleventyignore and root .gitignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalrootgitignore\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalrootgitignore/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n\"./test/stubs/ignorelocalrootgitignore/.git/**\",\n\"./test/stubs/ignorelocalrootgitignore/thisshouldnotexist12345\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n@@ -133,7 +133,7 @@ test(\"Get ignores (project .eleventyignore and root .gitignore, using setUseGitI\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalrootgitignore\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalrootgitignore/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n\"./test/stubs/ignore4/ignoredFolder/**\",\n\"./test/stubs/ignore4/ignoredFolder/ignored.md\",\n@@ -154,7 +154,7 @@ test(\"Get ignores (no .eleventyignore .gitignore exists but empty)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n\"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore5/_site/**\",\n@@ -173,7 +173,7 @@ test(\"Get ignores (both .eleventyignore and .gitignore exists, but .gitignore is\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n\"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore6/ignoredFolder/**\",\n@@ -324,7 +324,7 @@ test(\"De-duplicated ignores\", (t) => {\n]);\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignore-dedupe/node_modules/**\",\n+ \"./test/stubs/ignore-dedupe/**/node_modules/**\",\n\"./test/stubs/ignore-dedupe/.git/**\",\n\"./test/stubs/ignore-dedupe/ignoredFolder\",\n\"./test/stubs/ignore-dedupe/_site/**\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Ignore nested node modules by default
699
13.07.2022 12:41:10
18,000
bef78010c37cce6219d940acf4446ddd95ffbe40
Major changes to the i18n plugin. Better validation, no default language (must be specified), more robust code for our two filters.
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"hamljs\": \"^0.6.2\",\n\"handlebars\": \"^4.7.7\",\n\"is-glob\": \"^4.0.3\",\n+ \"iso-639-1\": \"^2.1.15\",\n\"kleur\": \"^4.1.4 \",\n\"liquidjs\": \"^9.37.0\",\n\"lodash\": \"^4.17.21\",\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/en-us/index.11ty.js", "new_path": "test/stubs-i18n/en-us/index.11ty.js", "diff": "module.exports = function (data) {\nreturn `${this.locale_url(\"/\")}\n+${this.locale_url(\"/\", \"es\")}\n${this.locale_url(\"/non-lang-file/\")}\n-${this.locale_links(data.page.inputPath).sort()}`;\n+${JSON.stringify(this.locale_links(data.page.inputPath).sort())}\n+${JSON.stringify(this.locale_links().sort())}`;\n};\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/en/index.liquid", "new_path": "test/stubs-i18n/en/index.liquid", "diff": "{{ \"/\" | locale_url }}\n+{{ \"/\" | locale_url: \"en-us\" }}\n{{ \"/non-lang-file/\" | locale_url }}\n-{{ page.inputPath | locale_links }}\n\\ No newline at end of file\n+{{ page.inputPath | locale_links | json }}\n+{{ \"\" | locale_links | json }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/es/index.njk", "new_path": "test/stubs-i18n/es/index.njk", "diff": "{{ \"/\" | locale_url }}\n+{{ \"/\" | locale_url(\"en-us\") }}\n{{ \"/non-lang-file/\" | locale_url }}\n-{{ page.inputPath | locale_links }}\n\\ No newline at end of file\n+{{ page.inputPath | locale_links | dump | safe }}\n+{{ \"\" | locale_links | dump | safe }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/non-lang-file.njk", "new_path": "test/stubs-i18n/non-lang-file.njk", "diff": "{{ \"/\" | locale_url }}\n+{{ \"/\" | locale_url(\"en-us\") }}\n{{ \"/non-lang-file/\" | locale_url }}\n-{{ page.inputPath | locale_links }}\n\\ No newline at end of file\n+{{ page.inputPath | locale_links | dump | safe }}\n+{{ \"\" | locale_links | dump | safe }}\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
Major changes to the i18n plugin. Better validation, no default language (must be specified), more robust code for our two filters.
699
13.07.2022 15:40:15
18,000
91cd7514c9c73fc1e7f04bb6573d68ea3e677de3
Adds `11ty.i18n.getLocaleRootPage` internal filter to make get*CollectionItem filters work automatically with the i18n plugin.
[ { "change_type": "MODIFY", "old_path": "src/Plugins/I18nPlugin.js", "new_path": "src/Plugins/I18nPlugin.js", "diff": "@@ -11,6 +11,24 @@ const bcp47Normalize = require(\"bcp-47-normalize\");\nconst iso639 = require(\"iso-639-1\");\nclass Comparator {\n+ static swapLanguageCode(str, langCode) {\n+ if (!Comparator.isLangCode(langCode)) {\n+ return str;\n+ }\n+\n+ let found = false;\n+ return str\n+ .split(\"/\")\n+ .map((entry) => {\n+ if (!found && Comparator.isLangCode(entry)) {\n+ found = true;\n+ return langCode;\n+ }\n+ return entry;\n+ })\n+ .join(\"/\");\n+ }\n+\n// https://en.wikipedia.org/wiki/IETF_language_tag#Relation_to_other_standards\n// Requires a ISO-639-1 language code at the start (2 characters before the first -)\nstatic isLangCode(code) {\n@@ -83,8 +101,9 @@ function EleventyPlugin(eleventyConfig, opts = {}) {\nlet contentMaps = {};\neleventyConfig.on(\n\"eleventy.contentMap\",\n- function ({ urlToInputPath, inputPathToUrl }) {\n+ function ({ urlToInputPath, inputPathToUrl, inputPathToOutputPath }) {\ncontentMaps.urls = urlToInputPath;\n+ contentMaps.inputOutput = inputPathToOutputPath;\n// map of input paths => array of localized urls\nlet localeMap = {};\n@@ -199,6 +218,56 @@ function EleventyPlugin(eleventyConfig, opts = {}) {\nreturn contentMaps.localeLinksMap[inputPath] || [];\n});\n+\n+ // If paginated, returns first result only\n+ eleventyConfig.addFilter(\n+ \"11ty.i18n.getLocaleRootPage\",\n+ function (pageOverride) {\n+ let page =\n+ pageOverride ||\n+ this.page ||\n+ this.ctx?.page ||\n+ this.context?.environments?.page;\n+\n+ let url;\n+ if (contentMaps.localeLinksMap[page.inputPath]) {\n+ for (let entry of contentMaps.localeLinksMap[page.inputPath]) {\n+ if (entry.lang === options.defaultLanguage) {\n+ url = entry.url;\n+ }\n+ }\n+ }\n+\n+ let inputPath = Comparator.swapLanguageCode(\n+ page.inputPath,\n+ options.defaultLanguage\n+ );\n+\n+ if (\n+ !url ||\n+ !Array.isArray(contentMaps.inputOutput[inputPath]) ||\n+ contentMaps.inputOutput[inputPath].length === 0\n+ ) {\n+ // not found\n+ return page;\n+ }\n+\n+ let result = {\n+ url,\n+ inputPath,\n+ filePathStem: Comparator.swapLanguageCode(\n+ page.filePathStem,\n+ options.defaultLanguage\n+ ),\n+\n+ // note that the permalink/slug may be different for the localized file!\n+ // /es/cuatro/\n+ // /en/four/\n+ outputPath: contentMaps.inputOutput[inputPath][0],\n+ };\n+ return result;\n+ }\n+ );\n}\nmodule.exports = EleventyPlugin;\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -361,7 +361,8 @@ class TemplateMap {\n);\nawait this.config.events.emit(\"eleventy.contentMap\", {\n- inputPathToUrl: this.generateContentMap(orderedMap),\n+ inputPathToOutputPath: this.generateInputOutputContentMap(orderedMap),\n+ inputPathToUrl: this.generateInputUrlContentMap(orderedMap),\nurlToInputPath: this.generateUrlMap(orderedMap),\n});\n@@ -378,7 +379,15 @@ class TemplateMap {\n);\n}\n- generateContentMap(orderedMap) {\n+ generateInputOutputContentMap(orderedMap) {\n+ let entries = {};\n+ for (let entry of orderedMap) {\n+ entries[entry.inputPath] = entry._pages.map((entry) => entry.outputPath);\n+ }\n+ return entries;\n+ }\n+\n+ generateInputUrlContentMap(orderedMap) {\nlet entries = {};\nfor (let entry of orderedMap) {\nentries[entry.inputPath] = entry._pages.map((entry) => entry.url);\n" }, { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -4,6 +4,19 @@ const slugFilter = require(\"./Filters/Slug\");\nconst slugifyFilter = require(\"./Filters/Slugify\");\nconst getCollectionItem = require(\"./Filters/GetCollectionItem\");\n+function getPageInFilter(context, config) {\n+ // Work with src/Plugins/I18nPlugin.js to retrieve root pages (not i18n pages)\n+ let localeFilter = config.getFilter(\"11ty.i18n.getLocaleRootPage\");\n+ if (localeFilter && typeof localeFilter === \"function\") {\n+ return localeFilter.call(context);\n+ }\n+\n+ let page =\n+ context.page || context.ctx?.page || context.context?.environments?.page;\n+\n+ return page;\n+}\n+\nmodule.exports = function (config) {\nlet templateConfig = this;\n@@ -21,14 +34,23 @@ module.exports = function (config) {\nconfig.addFilter(\"serverlessUrl\", serverlessUrlFilter);\n- config.addFilter(\"getCollectionItem\", (collection, page) =>\n- getCollectionItem(collection, page)\n- );\n- config.addFilter(\"getPreviousCollectionItem\", (collection, page) =>\n- getCollectionItem(collection, page, -1)\n+ config.addFilter(\"getCollectionItem\", function (collection, pageOverride) {\n+ let page = pageOverride || getPageInFilter(this, config);\n+ return getCollectionItem(collection, page);\n+ });\n+ config.addFilter(\n+ \"getPreviousCollectionItem\",\n+ function (collection, pageOverride) {\n+ let page = pageOverride || getPageInFilter(this, config);\n+ return getCollectionItem(collection, page, -1);\n+ }\n);\n- config.addFilter(\"getNextCollectionItem\", (collection, page) =>\n- getCollectionItem(collection, page, 1)\n+ config.addFilter(\n+ \"getNextCollectionItem\",\n+ function (collection, pageOverride) {\n+ let page = pageOverride || getPageInFilter(this, config);\n+ return getCollectionItem(collection, page, 1);\n+ }\n);\nreturn {\n" }, { "change_type": "MODIFY", "old_path": "test/I18nPluginTest.js", "new_path": "test/I18nPluginTest.js", "diff": "@@ -19,6 +19,15 @@ test(\"Comparator.isLangCode\", (t) => {\nt.is(Comparator.isLangCode(\"deedee\"), false);\n});\n+test(\"Comparator.swapLanguageCode\", (t) => {\n+ t.is(Comparator.swapLanguageCode(\"/\"), \"/\"); // skip\n+ t.is(Comparator.swapLanguageCode(\"/\", \"en\"), \"/\"); // skip\n+ t.is(Comparator.swapLanguageCode(\"/es/\", \"en\"), \"/en/\");\n+ t.is(Comparator.swapLanguageCode(\"/es/\", \"not\"), \"/es/\"); // skip\n+ t.is(Comparator.swapLanguageCode(\"/not-a-lang/\", \"en\"), \"/not-a-lang/\"); // skip\n+ t.is(Comparator.swapLanguageCode(\"/es/es/es/\", \"en\"), \"/en/es/es/\"); // first only\n+});\n+\ntest(\"Comparator.matchLanguageFolder\", (t) => {\nt.deepEqual(Comparator.matchLanguageFolder(\"/en/test.hbs\", \"/es/test.hbs\"), [\n\"en\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds `11ty.i18n.getLocaleRootPage` internal filter to make get*CollectionItem filters work automatically with the i18n plugin.
699
13.07.2022 17:23:42
18,000
186a9e3527605c2fdf7781e8eec3cc814b8c7974
Another i18n plugin refactor. Adds `locale_url` feature to support mismatched urls via permalink customization and support urls where the language code is already added.
[ { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -399,10 +399,8 @@ class TemplateMap {\nlet entries = {};\nfor (let entry of orderedMap) {\nfor (let page of entry._pages) {\n- if (!entries[page.url]) {\n- entries[page.url] = [];\n- }\n- entries[page.url].push(entry.inputPath);\n+ // duplicate urls throw an error, so we can return non array here\n+ entries[page.url] = entry.inputPath;\n}\n}\nreturn entries;\n" }, { "change_type": "MODIFY", "old_path": "test/I18nPluginTest.js", "new_path": "test/I18nPluginTest.js", "diff": "const test = require(\"ava\");\nconst I18nPlugin = require(\"../src/Plugins/I18nPlugin\");\n-const { Comparator } = I18nPlugin;\n+const { Comparator, LangUtils } = I18nPlugin;\nconst Eleventy = require(\"../src/Eleventy\");\nconst normalizeNewLines = require(\"./Util/normalizeNewLines\");\n@@ -19,13 +19,13 @@ test(\"Comparator.isLangCode\", (t) => {\nt.is(Comparator.isLangCode(\"deedee\"), false);\n});\n-test(\"Comparator.swapLanguageCode\", (t) => {\n- t.is(Comparator.swapLanguageCode(\"/\"), \"/\"); // skip\n- t.is(Comparator.swapLanguageCode(\"/\", \"en\"), \"/\"); // skip\n- t.is(Comparator.swapLanguageCode(\"/es/\", \"en\"), \"/en/\");\n- t.is(Comparator.swapLanguageCode(\"/es/\", \"not\"), \"/es/\"); // skip\n- t.is(Comparator.swapLanguageCode(\"/not-a-lang/\", \"en\"), \"/not-a-lang/\"); // skip\n- t.is(Comparator.swapLanguageCode(\"/es/es/es/\", \"en\"), \"/en/es/es/\"); // first only\n+test(\"LangUtils.swapLanguageCode\", (t) => {\n+ t.is(LangUtils.swapLanguageCode(\"/\"), \"/\"); // skip\n+ t.is(LangUtils.swapLanguageCode(\"/\", \"en\"), \"/\"); // skip\n+ t.is(LangUtils.swapLanguageCode(\"/es/\", \"en\"), \"/en/\");\n+ t.is(LangUtils.swapLanguageCode(\"/es/\", \"not\"), \"/es/\"); // skip\n+ t.is(LangUtils.swapLanguageCode(\"/not-a-lang/\", \"en\"), \"/not-a-lang/\"); // skip\n+ t.is(LangUtils.swapLanguageCode(\"/es/es/es/\", \"en\"), \"/en/es/es/\"); // first only\n});\ntest(\"Comparator.matchLanguageFolder\", (t) => {\n@@ -86,11 +86,12 @@ test(\"contentMap Event from Eleventy\", async (t) => {\neleventyConfig.on(\"eleventy.contentMap\", (maps) => {\nt.truthy(maps);\nt.deepEqual(maps.urlToInputPath, {\n- \"/en/\": [\"./test/stubs-i18n/en/index.liquid\"],\n- \"/en-us/\": [\"./test/stubs-i18n/en-us/index.11ty.js\"],\n- \"/es/\": [\"./test/stubs-i18n/es/index.njk\"],\n- \"/non-lang-file/\": [\"./test/stubs-i18n/non-lang-file.njk\"],\n+ \"/en/\": \"./test/stubs-i18n/en/index.liquid\",\n+ \"/en-us/\": \"./test/stubs-i18n/en-us/index.11ty.js\",\n+ \"/es/\": \"./test/stubs-i18n/es/index.njk\",\n+ \"/non-lang-file/\": \"./test/stubs-i18n/non-lang-file.njk\",\n});\n+\nt.deepEqual(maps.inputPathToUrl, {\n\"./test/stubs-i18n/en/index.liquid\": [\"/en/\"],\n\"./test/stubs-i18n/en-us/index.11ty.js\": [\"/en-us/\"],\n@@ -123,7 +124,7 @@ test(\"errorMode default\", async (t) => {\nelev.disableLogger();\nawait t.throwsAsync(async () => {\n- let results = await elev.toJSON();\n+ await elev.toJSON();\n});\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Another i18n plugin refactor. Adds `locale_url` feature to support mismatched urls via permalink customization and support urls where the language code is already added.
699
14.07.2022 09:26:46
18,000
6394d1db7ae2c62624d0a145abd5cfe50dc45307
More i18n plugin refactors (status commit)
[ { "change_type": "MODIFY", "old_path": "src/Filters/GetCollectionItem.js", "new_path": "src/Filters/GetCollectionItem.js", "diff": "@@ -4,7 +4,7 @@ module.exports = function getCollectionItem(collection, page, modifier = 0) {\nfor (let item of collection) {\nif (\nitem.inputPath === page.inputPath &&\n- item.outputPath === page.outputPath\n+ (item.outputPath === page.outputPath || item.url === page.url)\n) {\nindex = j;\nbreak;\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -361,7 +361,6 @@ class TemplateMap {\n);\nawait this.config.events.emit(\"eleventy.contentMap\", {\n- inputPathToOutputPath: this.generateInputOutputContentMap(orderedMap),\ninputPathToUrl: this.generateInputUrlContentMap(orderedMap),\nurlToInputPath: this.generateUrlMap(orderedMap),\n});\n@@ -379,14 +378,6 @@ class TemplateMap {\n);\n}\n- generateInputOutputContentMap(orderedMap) {\n- let entries = {};\n- for (let entry of orderedMap) {\n- entries[entry.inputPath] = entry._pages.map((entry) => entry.outputPath);\n- }\n- return entries;\n- }\n-\ngenerateInputUrlContentMap(orderedMap) {\nlet entries = {};\nfor (let entry of orderedMap) {\n" }, { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -5,8 +5,8 @@ const slugifyFilter = require(\"./Filters/Slugify\");\nconst getCollectionItem = require(\"./Filters/GetCollectionItem\");\nfunction getPageInFilter(context, config) {\n- // Work with src/Plugins/I18nPlugin.js to retrieve root pages (not i18n pages)\n- let localeFilter = config.getFilter(\"11ty.i18n.getLocaleRootPage\");\n+ // Work with I18n Plugin src/Plugins/I18nPlugin.js to retrieve root pages (not i18n pages)\n+ let localeFilter = config.getFilter(\"locale_page\");\nif (localeFilter && typeof localeFilter === \"function\") {\nreturn localeFilter.call(context);\n}\n" }, { "change_type": "MODIFY", "old_path": "test/I18nPluginTest.js", "new_path": "test/I18nPluginTest.js", "diff": "@@ -75,7 +75,7 @@ test(\"Comparator.matchLanguageFolder\", (t) => {\n});\ntest(\"contentMap Event from Eleventy\", async (t) => {\n- t.plan(3);\n+ t.plan(4);\nlet elev = new Eleventy(\"./test/stubs-i18n/\", \"./test/stubs-i18n/_site\", {\nconfig: function (eleventyConfig) {\neleventyConfig.addPlugin(I18nPlugin, {\n@@ -85,6 +85,9 @@ test(\"contentMap Event from Eleventy\", async (t) => {\neleventyConfig.on(\"eleventy.contentMap\", (maps) => {\nt.truthy(maps);\n+\n+ // if future maps are added, they should be tested here\n+ t.is(Object.keys(maps).length, 2);\nt.deepEqual(maps.urlToInputPath, {\n\"/en/\": \"./test/stubs-i18n/en/index.liquid\",\n\"/en-us/\": \"./test/stubs-i18n/en-us/index.11ty.js\",\n" } ]
JavaScript
MIT License
11ty/eleventy
More i18n plugin refactors (status commit)
699
14.07.2022 09:46:40
18,000
3c51e90c8dd97b8a11b29115c1529696239f98e3
i18n plugin: Pass url (not input path) to locale_links allows us to delete a bunch of code
[ { "change_type": "MODIFY", "old_path": "test/stubs-i18n/en-us/index.11ty.js", "new_path": "test/stubs-i18n/en-us/index.11ty.js", "diff": "module.exports = function (data) {\nreturn `${this.locale_url(\"/\")}\n+${this.locale_url(\"/en-us/\")}\n+${this.locale_url(\"/es/\")}\n${this.locale_url(\"/\", \"es\")}\n${this.locale_url(\"/non-lang-file/\")}\n-${JSON.stringify(this.locale_links(data.page.inputPath).sort())}\n+${JSON.stringify(this.locale_links(data.page.url).sort())}\n${JSON.stringify(this.locale_links().sort())}`;\n};\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/en/index.liquid", "new_path": "test/stubs-i18n/en/index.liquid", "diff": "{{ \"/\" | locale_url }}\n+{{ \"/en-us/\" | locale_url }}\n+{{ \"/es/\" | locale_url }}\n{{ \"/\" | locale_url: \"en-us\" }}\n{{ \"/non-lang-file/\" | locale_url }}\n-{{ page.inputPath | locale_links | json }}\n+{{ page.url | locale_links | json }}\n{{ \"\" | locale_links | json }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/es/index.njk", "new_path": "test/stubs-i18n/es/index.njk", "diff": "{{ \"/\" | locale_url }}\n+{{ \"/en-us/\" | locale_url }}\n+{{ \"/es/\" | locale_url }}\n{{ \"/\" | locale_url(\"en-us\") }}\n{{ \"/non-lang-file/\" | locale_url }}\n-{{ page.inputPath | locale_links | dump | safe }}\n+{{ page.url | locale_links | dump | safe }}\n{{ \"\" | locale_links | dump | safe }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/non-lang-file.njk", "new_path": "test/stubs-i18n/non-lang-file.njk", "diff": "{{ \"/\" | locale_url }}\n{{ \"/\" | locale_url(\"en-us\") }}\n{{ \"/non-lang-file/\" | locale_url }}\n-{{ page.inputPath | locale_links | dump | safe }}\n+{{ page.url | locale_links | dump | safe }}\n{{ \"\" | locale_links | dump | safe }}\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
i18n plugin: Pass url (not input path) to locale_links allows us to delete a bunch of code
699
14.07.2022 16:25:20
18,000
664d2aecf3db0c7a037cc588734a5582c6b0e44f
Eleventy core fix for
[ { "change_type": "MODIFY", "old_path": "src/EleventyServe.js", "new_path": "src/EleventyServe.js", "diff": "@@ -22,6 +22,7 @@ class EleventyServe {\nconstructor() {\nthis.logger = new ConsoleLogger(true);\nthis._initOptionsFetched = false;\n+ this._pendingAliases = {};\n}\nget config() {\n@@ -39,6 +40,16 @@ class EleventyServe {\nthis._config = config;\n}\n+ initAliases(aliases) {\n+ if (this._server) {\n+ if (\"setAliases\" in this._server) {\n+ this._server.setAliases(aliases);\n+ }\n+ } else {\n+ this._pendingAliases = aliases;\n+ }\n+ }\n+\nget eleventyConfig() {\nif (!this._eleventyConfig) {\nthrow new EleventyServeConfigError(\n@@ -58,9 +69,7 @@ class EleventyServe {\n\"eleventy.passthrough\",\n({ map }) => {\n// for-free passthrough copy\n- if (\"setAliases\" in this.server) {\n- this.server.setAliases(map);\n- }\n+ this.initAliases(map);\n}\n);\n}\n@@ -145,6 +154,7 @@ class EleventyServe {\n// TODO improve by sorting keys here\nthis._savedConfigOptions = JSON.stringify(this.config.serverOptions);\n+\nif (!this._initOptionsFetched && this.getSetupCallback()) {\nthrow new Error(\n\"Init options have not yet been fetched in the setup callback. This probably means that `init()` has not yet been called.\"\n@@ -168,6 +178,11 @@ class EleventyServe {\nthis.options\n);\n+ if (Object.keys(this._pendingAliases).length) {\n+ this.initAliases(this._pendingAliases);\n+ this._pendingAliases = {};\n+ }\n+\nreturn this._server;\n}\n@@ -183,25 +198,30 @@ class EleventyServe {\n}\nasync init() {\n- if (!this._initOptionsFetched) {\n- this._initOptionsFetched = true;\n-\n+ if (!this._initPromise) {\n+ this._initPromise = new Promise(async (resolve) => {\nlet setupCallback = this.getSetupCallback();\nif (setupCallback) {\nlet opts = await setupCallback();\n+ this._initOptionsFetched = true;\n+\nif (opts) {\nmerge(this.options, opts);\n}\n}\n+\n+ resolve();\n+ });\n}\n+\n+ return this._initPromise;\n}\n// Port comes in here from --port on the command line\nasync serve(port) {\nthis._commandLinePort = port;\n- if (!this._initOptionsFetched) {\n+\nawait this.init();\n- }\nthis.server.serve(port || this.options.port);\n}\n@@ -209,6 +229,7 @@ class EleventyServe {\nasync close() {\nif (this._server) {\nawait this.server.close();\n+\nthis.server = undefined;\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Eleventy core fix for https://github.com/11ty/eleventy-plugin-vite/issues/8
699
15.07.2022 10:24:33
18,000
d9b5db53c4c4b4868dc0d87f7f317f8792a6a718
Update deps for 2.0.0-canary.13
[ { "change_type": "MODIFY", "old_path": "docs/release-instructions.md", "new_path": "docs/release-instructions.md", "diff": "- `@sindresorhus/slugify` ESM at 2.x\n- `multimatch` is ESM at 6\n+- `bcp-47-normalize` at 1.x\n# Canary Release Procedure\n" }, { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "]\n},\n\"devDependencies\": {\n- \"@11ty/eleventy-plugin-syntaxhighlight\": \"^4.0.0\",\n+ \"@11ty/eleventy-plugin-syntaxhighlight\": \"^4.1.0\",\n\"@11ty/eleventy-plugin-vue\": \"1.0.0-canary.8\",\n- \"@vue/server-renderer\": \"^3.2.33\",\n+ \"@vue/server-renderer\": \"^3.2.37\",\n\"ava\": \"^4.3.1\",\n\"husky\": \"^8.0.1\",\n\"js-yaml\": \"^4.1.0\",\n- \"lint-staged\": \"^12.4.1\",\n+ \"lint-staged\": \"^13.0.3\",\n\"markdown-it-emoji\": \"^2.0.2\",\n- \"marked\": \"^4.0.15\",\n+ \"marked\": \"^4.0.18\",\n\"nyc\": \"^15.1.0\",\n- \"prettier\": \"^2.6.2\",\n+ \"prettier\": \"^2.7.1\",\n\"pretty\": \"^2.0.0\",\n\"rimraf\": \"^3.0.2\",\n- \"sass\": \"^1.51.0\",\n+ \"sass\": \"^1.53.0\",\n\"toml\": \"^3.0.0\",\n- \"vue\": \"^3.2.33\"\n+ \"vue\": \"^3.2.37\"\n},\n\"dependencies\": {\n\"@11ty/dependency-tree\": \"^2.0.1\",\n\"handlebars\": \"^4.7.7\",\n\"is-glob\": \"^4.0.3\",\n\"iso-639-1\": \"^2.1.15\",\n- \"kleur\": \"^4.1.4 \",\n- \"liquidjs\": \"^9.37.0\",\n+ \"kleur\": \"^4.1.5\",\n+ \"liquidjs\": \"^9.39.1\",\n\"lodash\": \"^4.17.21\",\n- \"luxon\": \"^2.4.0\",\n+ \"luxon\": \"^3.0.1\",\n\"markdown-it\": \"^13.0.1\",\n\"minimist\": \"^1.2.6\",\n\"moo\": \"^0.5.1\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Update deps for 2.0.0-canary.13
699
15.07.2022 17:06:56
18,000
91724d180f2c524e5c089d0e249f6347abcceaaf
Superfluous require
[ { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -2,7 +2,6 @@ const urlFilter = require(\"./Filters/Url\");\nconst serverlessUrlFilter = require(\"./Filters/ServerlessUrl\");\nconst slugFilter = require(\"./Filters/Slug\");\nconst slugifyFilter = require(\"./Filters/Slugify\");\n-const getCollectionItem = require(\"./Filters/GetCollectionItem\");\nconst getLocaleCollectionItem = require(\"./Filters/GetLocaleCollectionItem\");\nmodule.exports = function (config) {\n" } ]
JavaScript
MIT License
11ty/eleventy
Superfluous require
699
27.07.2022 11:08:53
18,000
dc2226d64a47a4d32de1adbe8b67933b0d4eb731
Bad order of operations.
[ { "change_type": "MODIFY", "old_path": "src/Filters/GetLocaleCollectionItem.js", "new_path": "src/Filters/GetLocaleCollectionItem.js", "diff": "@@ -42,7 +42,7 @@ function getLocaleCollectionItem(\nlangCode\n);\n// already localized (or default language)\n- if (!\"__locale_page_resolved\" in modifiedLocalePage) {\n+ if (!(\"__locale_page_resolved\" in modifiedLocalePage)) {\nreturn modifiedRootItem;\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Bad order of operations.
699
27.07.2022 14:19:44
18,000
513e253e325db575b1fe7121f4ee8a4e518e5515
Adds `page.lang` when using i18n plugin! Fixes prerequisite of eleventy-base-blog
[ { "change_type": "MODIFY", "old_path": "test/stubs-i18n/en-us/index.11ty.js", "new_path": "test/stubs-i18n/en-us/index.11ty.js", "diff": "@@ -5,5 +5,6 @@ ${this.locale_url(\"/es/\")}\n${this.locale_url(\"/\", \"es\")}\n${this.locale_url(\"/non-lang-file/\")}\n${JSON.stringify(this.locale_links(data.page.url).sort())}\n-${JSON.stringify(this.locale_links().sort())}`;\n+${JSON.stringify(this.locale_links().sort())}\n+${data.page.lang}`;\n};\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/en/index.liquid", "new_path": "test/stubs-i18n/en/index.liquid", "diff": "{{ \"/non-lang-file/\" | locale_url }}\n{{ page.url | locale_links | json }}\n{{ \"\" | locale_links | json }}\n+{{ page.lang }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/es/index.njk", "new_path": "test/stubs-i18n/es/index.njk", "diff": "{{ \"/non-lang-file/\" | locale_url }}\n{{ page.url | locale_links | dump | safe }}\n{{ \"\" | locale_links | dump | safe }}\n+{{ page.lang }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-i18n/non-lang-file.njk", "new_path": "test/stubs-i18n/non-lang-file.njk", "diff": "{{ \"/non-lang-file/\" | locale_url }}\n{{ page.url | locale_links | dump | safe }}\n{{ \"\" | locale_links | dump | safe }}\n+{{ page.lang }}\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds `page.lang` when using i18n plugin! Fixes #2501 prerequisite of #243 eleventy-base-blog
699
27.07.2022 16:21:48
18,000
2bfeed79c98b4f189e9a5ae263cad63adb4a5616
Removes superflouous extra filters, adds support for page.lang in get*CollectionItem filters
[ { "change_type": "MODIFY", "old_path": "src/Filters/GetLocaleCollectionItem.js", "new_path": "src/Filters/GetLocaleCollectionItem.js", "diff": "const getCollectionItem = require(\"./GetCollectionItem\");\n-function getPageInFilter() {\n- return this.page || this.ctx?.page || this.context?.environments?.page;\n-}\n-\n-function resolveRootPage(config, pageOverride, languageCode) {\n// Work with I18n Plugin src/Plugins/I18nPlugin.js to retrieve root pages (not i18n pages)\n+function resolveRootPage(config, pageOverride, languageCode) {\nlet localeFilter = config.getFilter(\"locale_page\");\nif (!localeFilter || typeof localeFilter !== \"function\") {\nreturn pageOverride;\n@@ -22,9 +18,14 @@ function getLocaleCollectionItem(\nlangCode,\nindexModifier = 0\n) {\n+ let page = this.page || this.ctx?.page || this.context?.environments?.page;\nif (!langCode) {\n- let page = pageOverride || getPageInFilter.call(this);\n- return getCollectionItem(collection, page, indexModifier);\n+ // if page.lang exists (2.0.0-canary.14 and i18n plugin added, use page language)\n+ if (page.lang) {\n+ langCode = page.lang;\n+ } else {\n+ return getCollectionItem(collection, pageOverride || page, indexModifier);\n+ }\n}\nlet rootPage = resolveRootPage.call(this, config, pageOverride); // implied current page, default language\n@@ -34,7 +35,7 @@ function getLocaleCollectionItem(\n}\n// Resolve modified root `page` back to locale `page`\n- // This will return a non localized version of the content as a fallback\n+ // This will return a non localized version of the page as a fallback\nlet modifiedLocalePage = resolveRootPage.call(\nthis,\nconfig,\n@@ -50,9 +51,9 @@ function getLocaleCollectionItem(\nlet all =\nthis.collections?.all ||\nthis.ctx?.collections?.all ||\n- this.context?.environments?.collections?.all;\n- let modifiedLocaleItem = getCollectionItem(all, modifiedLocalePage, 0);\n- return modifiedLocaleItem;\n+ this.context?.environments?.collections?.all ||\n+ [];\n+ return getCollectionItem(all, modifiedLocalePage, 0);\n}\nmodule.exports = getLocaleCollectionItem;\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/I18nPlugin.js", "new_path": "src/Plugins/I18nPlugin.js", "diff": "@@ -280,6 +280,7 @@ function EleventyPlugin(eleventyConfig, opts = {}) {\neleventyConfig.addFilter(\n\"locale_page\", // This is not exposed in `options` because it is an Eleventy internals filter (used in get*CollectionItem filters)\nfunction (pageOverride, languageCode) {\n+ // both args here are optional\nif (!languageCode) {\nlanguageCode = options.defaultLanguage;\n}\n" }, { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -21,34 +21,6 @@ module.exports = function (config) {\nconfig.addFilter(\"serverlessUrl\", serverlessUrlFilter);\n- config.addFilter(\n- \"getPreviousCollectionItemForCurrentPage\",\n- function (collection, langCode) {\n- return getLocaleCollectionItem.call(\n- this,\n- config,\n- collection,\n- null,\n- langCode,\n- -1\n- );\n- }\n- );\n-\n- config.addFilter(\n- \"getNextCollectionItemForCurrentPage\",\n- function (collection, langCode) {\n- return getLocaleCollectionItem.call(\n- this,\n- config,\n- collection,\n- null,\n- langCode,\n- 1\n- );\n- }\n- );\n-\nconfig.addFilter(\n\"getCollectionItem\",\nfunction (collection, pageOverride, langCode) {\n" } ]
JavaScript
MIT License
11ty/eleventy
Removes superflouous extra filters, adds support for page.lang in get*CollectionItem filters https://github.com/11ty/eleventy/issues/2501
699
27.07.2022 16:35:57
18,000
bd3e4a4a7482c3a306654ed83727a782a4180d4c
Test moving from toml package in skipped test to already in-use
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"prettier\": \"^2.7.1\",\n\"pretty\": \"^2.0.0\",\n\"rimraf\": \"^3.0.2\",\n- \"sass\": \"^1.53.0\",\n- \"toml\": \"^3.0.0\",\n+ \"sass\": \"^1.54.0\",\n\"vue\": \"^3.2.37\"\n},\n\"dependencies\": {\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateTest.js", "new_path": "test/TemplateTest.js", "diff": "@@ -1756,9 +1756,9 @@ This is content.`\n);\n});\n-test.skip(\"Custom Front Matter Parsing Options (using TOML)\", async (t) => {\n+test(\"Custom Front Matter Parsing Options (using TOML)\", async (t) => {\n// Currently fails on Windows, needs https://github.com/jonschlinkert/gray-matter/issues/92\n- let toml = require(\"toml\");\n+ const TOML = require(\"@iarna/toml\");\nlet tmpl = getNewTemplate(\n\"./test/stubs/custom-frontmatter/template-toml.njk\",\n@@ -1767,7 +1767,7 @@ test.skip(\"Custom Front Matter Parsing Options (using TOML)\", async (t) => {\n);\ntmpl.config.frontMatterParsingOptions = {\nengines: {\n- toml: toml.parse.bind(toml),\n+ toml: TOML.parse.bind(TOML),\n},\n};\n" } ]
JavaScript
MIT License
11ty/eleventy
Test moving from toml package in skipped test to already in-use @iarna/toml
699
10.08.2022 17:04:07
18,000
0bbc16dfc03eb773de33488dd1c7b1bb37f701be
Make `pathPrefix` available to plugins as `eleventyConfig.pathPrefix` Fixes
[ { "change_type": "MODIFY", "old_path": "cmd.js", "new_path": "cmd.js", "diff": "@@ -68,10 +68,11 @@ try {\nconsole.log(Eleventy.getHelp());\n} else {\nlet elev = new Eleventy(argv.input, argv.output, {\n+ source: \"cli\",\n// --quiet and --quiet=true both resolve to true\nquietMode: argv.quiet,\nconfigPath: argv.config,\n- source: \"cli\",\n+ pathPrefix: argv.pathprefix,\n});\n// reuse ErrorHandler instance in Eleventy\n@@ -82,7 +83,6 @@ try {\nelev.setIsVerbose(false);\n}\n- elev.setPathPrefix(argv.pathprefix);\nelev.setDryRun(argv.dryrun);\nelev.setIncrementalBuild(argv.incremental);\nelev.setPassthroughAll(argv.passthroughall);\n" }, { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "},\n\"dependencies\": {\n\"@11ty/dependency-tree\": \"^2.0.1\",\n- \"@11ty/eleventy-dev-server\": \"^1.0.0-canary.13\",\n+ \"@11ty/eleventy-dev-server\": \"^1.0.0-canary.14\",\n\"@11ty/eleventy-utils\": \"^1.0.1\",\n\"@iarna/toml\": \"^2.2.5\",\n\"@sindresorhus/slugify\": \"^1.1.2\",\n" }, { "change_type": "MODIFY", "old_path": "src/Filters/Url.js", "new_path": "src/Filters/Url.js", "diff": "@@ -21,7 +21,7 @@ module.exports = function (url, pathPrefix) {\nif (pathPrefix === undefined || typeof pathPrefix !== \"string\") {\n// When you retrieve this with config.getFilter(\"url\") it\n- // grabs the pathPrefix argument from your config for you.\n+ // grabs the pathPrefix argument from your config for you (see defaultConfig.js)\nthrow new Error(\"pathPrefix (String) is required in the `url` filter.\");\n}\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateConfigTest.js", "new_path": "test/TemplateConfigTest.js", "diff": "@@ -545,3 +545,26 @@ test(\"Nested .addPlugin calls. More complex order\", (t) => {\ntemplateCfg.getConfig();\n});\n+\n+test(\".addPlugin has access to pathPrefix\", (t) => {\n+ t.plan(1);\n+ let templateCfg = new TemplateConfig();\n+\n+ templateCfg.userConfig.addPlugin(function (eleventyConfig) {\n+ t.is(eleventyConfig.pathPrefix, \"/\");\n+ });\n+\n+ templateCfg.getConfig();\n+});\n+\n+test(\".addPlugin has access to pathPrefix (override method)\", (t) => {\n+ t.plan(1);\n+ let templateCfg = new TemplateConfig();\n+ templateCfg.setPathPrefix(\"/test/\");\n+\n+ templateCfg.userConfig.addPlugin(function (eleventyConfig) {\n+ t.is(eleventyConfig.pathPrefix, \"/test/\");\n+ });\n+\n+ templateCfg.getConfig();\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
Make `pathPrefix` available to plugins as `eleventyConfig.pathPrefix` Fixes https://github.com/11ty/eleventy/issues/2526
673
12.08.2022 00:30:16
-7,200
88cf1f3eb668c38d9296fef27112d49f13e1464a
Update `possible-bug.yml`
[ { "change_type": "MODIFY", "old_path": ".github/ISSUE_TEMPLATE/possible-bug.yml", "new_path": ".github/ISSUE_TEMPLATE/possible-bug.yml", "diff": "@@ -52,12 +52,12 @@ body:\nid: repro-url\nattributes:\nlabel: Reproduction URL\n- description: If applicable, please provide a URL to a reproduction.\n- placeholder: github.com/11ty/reproduction\n+ description: \"Optional: The URL to the **public** repository for the reproduction. _[parser:url]_\"\n+ placeholder: e.g. https://github.com/zachleat/zachleat.com\nvalidations:\nrequired: false\n- type: textarea\nid: screenshots\nattributes:\nlabel: Screenshots\n- description: If applicable, add screenshots to help explain your problem.\n+ description: \"Optional: If applicable, add screenshots to help explain your problem.\"\n" } ]
JavaScript
MIT License
11ty/eleventy
Update `possible-bug.yml`
684
16.08.2022 17:25:20
-7,200
51a04081a58e0ba8dfac47cdbf7acb9208049673
Remove "custom" labels.
[ { "change_type": "MODIFY", "old_path": "src/TemplateRender.js", "new_path": "src/TemplateRender.js", "diff": "@@ -163,12 +163,8 @@ class TemplateRender {\ngetReadableEnginesListDifferingFromFileExtension() {\nlet keyFromFilename = this.extensionMap.getKey(this.engineNameOrPath);\nif (this.engine instanceof CustomEngine) {\n- if (this.engine.entry && keyFromFilename !== this.engine.entry.name) {\n- if (this.engine.entry.name) {\n- return `custom/${this.engine.entry.name}`;\n- } else {\n- return \"custom\";\n- }\n+ if (this.engine.entry && this.engine.entry.name && keyFromFilename !== this.engine.entry.name) {\n+ return this.engine.entry.name;\n} else {\nreturn undefined;\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Remove "custom" labels.
699
16.08.2022 10:49:59
18,000
19e36261f3ce67f7a8ca8a9c57e0cb648f52f4de
Fix windows test for i18n speed regression fix
[ { "change_type": "MODIFY", "old_path": "src/Plugins/I18nPlugin.js", "new_path": "src/Plugins/I18nPlugin.js", "diff": "@@ -13,9 +13,9 @@ const bcp47Normalize = require(\"bcp-47-normalize\");\nconst iso639 = require(\"iso-639-1\");\nclass LangUtils {\n- static getLanguageCodeFromFilePath(filepath) {\n+ static getLanguageCodeFromInputPath(filepath) {\nreturn (filepath || \"\")\n- .split(path.sep)\n+ .split(\"/\")\n.find((entry) => Comparator.isLangCode(entry));\n}\n@@ -139,7 +139,7 @@ function getLocaleUrlsMap(urlToInputPath, extensionMap) {\nfilemap[replaced] = [];\n}\n- let langCode = LangUtils.getLanguageCodeFromFilePath(originalFilepath);\n+ let langCode = LangUtils.getLanguageCodeFromInputPath(originalFilepath);\nif (langCode) {\nfilemap[replaced].push({\nurl,\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix windows test for i18n speed regression fix
699
16.08.2022 11:21:47
18,000
ae2b6fa9681dae1e57b58d2d9961d2250d16ac5a
Prefer .js config files over .cjs by default
[ { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -55,8 +55,8 @@ class TemplateConfig {\n*/\nthis.projectConfigPaths = [\n\".eleventy.js\",\n- \".eleventy.cjs\",\n\"eleventy.config.js\",\n+ \".eleventy.cjs\",\n\"eleventy.config.cjs\",\n];\nif (projectConfigPath !== undefined) {\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyTest.js", "new_path": "test/EleventyTest.js", "diff": "@@ -72,8 +72,8 @@ test(\"Eleventy file watching\", async (t) => {\n\"./test/stubs/_includes/**\",\n\"./test/stubs/_data/**\",\n\"./.eleventy.js\",\n- \"./.eleventy.cjs\",\n\"./eleventy.config.js\",\n+ \"./.eleventy.cjs\",\n\"./eleventy.config.cjs\",\n\"./test/stubs/**/*.json\",\n\"./test/stubs/**/*.11tydata.cjs\",\n@@ -111,8 +111,8 @@ test(\"Eleventy file watching (no JS dependencies)\", async (t) => {\n\"./test/stubs/_includes/**\",\n\"./test/stubs/_data/**\",\n\"./.eleventy.js\",\n- \"./.eleventy.cjs\",\n\"./eleventy.config.js\",\n+ \"./.eleventy.cjs\",\n\"./eleventy.config.cjs\",\n\"./test/stubs/**/*.json\",\n\"./test/stubs/**/*.11tydata.cjs\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Prefer .js config files over .cjs by default #2464
699
16.08.2022 11:25:27
18,000
c1ed616d7fdb51338aa8e5805279a987a8b05e1a
Changed my mind about If you want .cjs use `eleventy.config.cjs` instead.
[ { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -56,7 +56,6 @@ class TemplateConfig {\nthis.projectConfigPaths = [\n\".eleventy.js\",\n\"eleventy.config.js\",\n- \".eleventy.cjs\",\n\"eleventy.config.cjs\",\n];\nif (projectConfigPath !== undefined) {\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyTest.js", "new_path": "test/EleventyTest.js", "diff": "@@ -73,7 +73,6 @@ test(\"Eleventy file watching\", async (t) => {\n\"./test/stubs/_data/**\",\n\"./.eleventy.js\",\n\"./eleventy.config.js\",\n- \"./.eleventy.cjs\",\n\"./eleventy.config.cjs\",\n\"./test/stubs/**/*.json\",\n\"./test/stubs/**/*.11tydata.cjs\",\n@@ -112,7 +111,6 @@ test(\"Eleventy file watching (no JS dependencies)\", async (t) => {\n\"./test/stubs/_data/**\",\n\"./.eleventy.js\",\n\"./eleventy.config.js\",\n- \"./.eleventy.cjs\",\n\"./eleventy.config.cjs\",\n\"./test/stubs/**/*.json\",\n\"./test/stubs/**/*.11tydata.cjs\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Changed my mind about #1028. If you want .cjs use `eleventy.config.cjs` instead.
699
16.08.2022 14:36:06
18,000
689abd0fab807bf287785e148ca6d125ed21a125
Adds require util to normalize removal from the require cache before requiring
[ { "change_type": "MODIFY", "old_path": "src/Eleventy.js", "new_path": "src/Eleventy.js", "diff": "@@ -276,7 +276,7 @@ class Eleventy {\n// reload package.json values (if applicable)\n// TODO only reset this if it changed\n- deleteRequireCache(TemplatePath.absolutePath(\"package.json\"));\n+ deleteRequireCache(\"package.json\");\nawait this.init();\n}\n@@ -675,7 +675,7 @@ Arguments:\nfor (let dep of configFileDependencies) {\nif (this.watchManager.hasQueuedFile(dep)) {\n// Delete from require cache so that updates to the module are re-required\n- deleteRequireCache(TemplatePath.absolutePath(dep));\n+ deleteRequireCache(dep);\nreturn true;\n}\n" }, { "change_type": "MODIFY", "old_path": "src/EleventyWatchTargets.js", "new_path": "src/EleventyWatchTargets.js", "diff": "@@ -119,7 +119,7 @@ class EleventyWatchTargets {\nclearDependencyRequireCache() {\nfor (let path of this.dependencies) {\n- deleteRequireCache(TemplatePath.absolutePath(path));\n+ deleteRequireCache(path);\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/JavaScript.js", "new_path": "src/Engines/JavaScript.js", "diff": "@@ -82,10 +82,7 @@ class JavaScript extends TemplateEngine {\n// only remove from cache once on startup (if it already exists)\ninitRequireCache(inputPath) {\n- let requirePath = TemplatePath.absolutePath(inputPath);\n- if (requirePath) {\n- deleteRequireCache(requirePath);\n- }\n+ deleteRequireCache(inputPath);\nif (inputPath in this.instances) {\ndelete this.instances[inputPath];\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/ServerlessBundlerPlugin.js", "new_path": "src/Plugins/ServerlessBundlerPlugin.js", "diff": "@@ -7,7 +7,7 @@ const querystring = require(\"querystring\");\nconst { TemplatePath } = require(\"@11ty/eleventy-utils\");\nconst NetlifyRedirects = require(\"./Serverless/NetlifyRedirects\");\n-const deleteRequireCache = require(\"../Util/DeleteRequireCache\");\n+const { EleventyRequire } = require(\"../Util/Require\");\nconst JavaScriptDependencies = require(\"../Util/JavaScriptDependencies\");\nconst debug = require(\"debug\")(\"Eleventy:Serverless\");\n@@ -166,10 +166,9 @@ class BundlerHelper {\nlet serverlessFilepath = TemplatePath.addLeadingDotSlash(\npath.join(TemplatePath.getWorkingDir(), this.dir, \"index\")\n);\n- deleteRequireCache(TemplatePath.absolutePath(serverlessFilepath));\nreturn async function EleventyServerlessMiddleware(req, res, next) {\n- let serverlessFunction = require(serverlessFilepath);\n+ let serverlessFunction = EleventyRequire(serverlessFilepath);\nlet url = new URL(req.url, \"http://localhost/\"); // any domain will do here, we just want the searchParams\nlet start = new Date();\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -3,12 +3,13 @@ const chalk = require(\"kleur\");\nconst lodashUniq = require(\"lodash/uniq\");\nconst lodashMerge = require(\"lodash/merge\");\nconst { TemplatePath } = require(\"@11ty/eleventy-utils\");\n-const EleventyBaseError = require(\"./EleventyBaseError\");\n-const UserConfig = require(\"./UserConfig\");\n+const EleventyBaseError = require(\"./EleventyBaseError.js\");\n+const UserConfig = require(\"./UserConfig.js\");\n+const { EleventyRequire } = require(\"./Util/Require.js\");\n+const eventBus = require(\"./EventBus.js\");\n+\nconst debug = require(\"debug\")(\"Eleventy:TemplateConfig\");\nconst debugDev = require(\"debug\")(\"Dev:Eleventy:TemplateConfig\");\n-const deleteRequireCache = require(\"./Util/DeleteRequireCache\");\n-const eventBus = require(\"./EventBus\");\n/**\n* @module 11ty/eleventy/TemplateConfig\n@@ -272,17 +273,13 @@ class TemplateConfig {\nlet localConfig = {};\nlet path = this.projectConfigPaths\n.filter((path) => path)\n- .map((path) => TemplatePath.absolutePath(path))\n.find((path) => fs.existsSync(path));\ndebug(`Merging config with ${path}`);\nif (path) {\ntry {\n- // remove from require cache so it will grab a fresh copy\n- deleteRequireCache(path);\n-\n- localConfig = require(path);\n+ localConfig = EleventyRequire(path);\n// debug( \"localConfig require return value: %o\", localConfig );\nif (typeof localConfig === \"function\") {\nlocalConfig = localConfig(this.userConfig);\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateData.js", "new_path": "src/TemplateData.js", "diff": "@@ -12,11 +12,11 @@ const TemplateGlob = require(\"./TemplateGlob\");\nconst EleventyExtensionMap = require(\"./EleventyExtensionMap\");\nconst EleventyBaseError = require(\"./EleventyBaseError\");\nconst TemplateDataInitialGlobalData = require(\"./TemplateDataInitialGlobalData\");\n+const { EleventyRequire } = require(\"./Util/Require\");\nconst debugWarn = require(\"debug\")(\"Eleventy:Warnings\");\nconst debug = require(\"debug\")(\"Eleventy:TemplateData\");\nconst debugDev = require(\"debug\")(\"Dev:Eleventy:TemplateData\");\n-const deleteRequireCache = require(\"./Util/DeleteRequireCache\");\nclass FSExistsCache {\nconstructor() {\n@@ -502,9 +502,8 @@ class TemplateData {\naggregateDataBench.before();\nlet dataBench = this.benchmarks.data.get(`\\`${path}\\``);\ndataBench.before();\n- deleteRequireCache(localPath);\n- let returnValue = require(localPath);\n+ let returnValue = EleventyRequire(localPath);\n// TODO special exception for Global data `permalink.js`\n// module.exports = (data) => `${data.page.filePathStem}/`; // Does not work\n// module.exports = () => ((data) => `${data.page.filePathStem}/`); // Works\n" }, { "change_type": "MODIFY", "old_path": "src/Util/DeleteRequireCache.js", "new_path": "src/Util/DeleteRequireCache.js", "diff": "const path = require(\"path\");\n+const { TemplatePath } = require(\"@11ty/eleventy-utils\");\n/**\n* Removes a nodejs module from the cache.\n* The keys of the nodejs require cache are file paths based on the current operating system.\n- * @param {string} absoluteModulePath An absolute POSIX path to the module.\n+ * @param {string} absolutePath An absolute POSIX path to the file.\n*/\n-module.exports = function deleteRequireCache(absoluteModulePath) {\n- const normalizedPath = path.normalize(absoluteModulePath);\n+function deleteRequireCacheAbsolute(absolutePath) {\n+ const normalizedPath = path.normalize(absolutePath);\ndelete require.cache[normalizedPath];\n-};\n+}\n+\n+function deleteRequireCache(localPath) {\n+ let absolutePath = TemplatePath.absolutePath(localPath);\n+ deleteRequireCacheAbsolute(absolutePath);\n+}\n+\n+module.exports = deleteRequireCache; // local paths\n+module.exports.deleteRequireCacheAbsolute = deleteRequireCacheAbsolute;\n" }, { "change_type": "ADD", "old_path": null, "new_path": "src/Util/Require.js", "diff": "+const { TemplatePath } = require(\"@11ty/eleventy-utils\");\n+const { deleteRequireCacheAbsolute } = require(\"./DeleteRequireCache\");\n+\n+function requireLocal(path) {\n+ let absolutePath = TemplatePath.absolutePath(path);\n+\n+ return requireAbsolute(absolutePath);\n+}\n+\n+function requireAbsolute(absolutePath) {\n+ // remove from require cache so it will grab a fresh copy\n+ deleteRequireCacheAbsolute(absolutePath);\n+\n+ return require(absolutePath);\n+}\n+\n+module.exports.EleventyRequire = requireLocal;\n+module.exports.EleventyRequireAbsolute = requireAbsolute;\n" }, { "change_type": "MODIFY", "old_path": "test/DeleteRequireCacheTest.js", "new_path": "test/DeleteRequireCacheTest.js", "diff": "const test = require(\"ava\");\nconst path = require(\"path\");\n-const deleteRequireCache = require(\"../src/Util/DeleteRequireCache\");\n+const {\n+ deleteRequireCacheAbsolute,\n+} = require(\"../src/Util/DeleteRequireCache\");\nconst template = require(\"./stubs/function.11ty\");\ntest(\"deleteRequireCache\", (t) => {\n@@ -10,7 +12,7 @@ test(\"deleteRequireCache\", (t) => {\nconst posixModulePath = useForwardSlashes(modulePath);\nconst windowsModulePath = useBackwardSlashes(modulePath);\n- deleteRequireCache(posixModulePath);\n+ deleteRequireCacheAbsolute(posixModulePath);\nt.is(require.cache[windowsModulePath], undefined);\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds require util to normalize removal from the require cache before requiring
699
17.08.2022 10:05:57
18,000
821faedd33a9677a2ee1ca37e9408ea67c789a15
If user config returns a falsy pathPrefix, fall back to the default value
[ { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -196,7 +196,7 @@ class TemplateConfig {\n* @returns {String} - The path prefix string\n*/\ngetPathPrefix() {\n- if (this.overrides.pathPrefix || this.overrides.pathPrefix === \"\") {\n+ if (this.overrides.pathPrefix) {\nreturn this.overrides.pathPrefix;\n}\n@@ -335,9 +335,13 @@ class TemplateConfig {\nmergedConfig.templateFormats = templateFormats;\n// Setup pathPrefix set via command line for plugin consumption\n- if (this.overrides.pathPrefix || this.overrides.pathPrefix === \"\") {\n+ if (this.overrides.pathPrefix) {\nmergedConfig.pathPrefix = this.overrides.pathPrefix;\n}\n+ // Returning a falsy value (e.g. \"\") from user config should reset to the default value.\n+ if (!mergedConfig.pathPrefix) {\n+ mergedConfig.pathPrefix = this.rootConfig.pathPrefix;\n+ }\nthis.processPlugins(mergedConfig);\ndelete mergedConfig.templateFormats;\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateConfigTest.js", "new_path": "test/TemplateConfigTest.js", "diff": "@@ -568,3 +568,17 @@ test(\".addPlugin has access to pathPrefix (override method)\", (t) => {\ntemplateCfg.getConfig();\n});\n+\n+test(\"falsy pathPrefix should fall back to default\", (t) => {\n+ t.plan(1);\n+ let templateCfg = new TemplateConfig(\n+ require(\"../src/defaultConfig.js\"),\n+ \"./test/stubs/config-empty-pathprefix.js\"\n+ );\n+\n+ templateCfg.userConfig.addPlugin(function (eleventyConfig) {\n+ t.is(eleventyConfig.pathPrefix, \"/\");\n+ });\n+\n+ templateCfg.getConfig();\n+});\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs/config-empty-pathprefix.js", "diff": "+module.exports = function (config) {\n+ return {\n+ pathPrefix: \"\",\n+ };\n+};\n" } ]
JavaScript
MIT License
11ty/eleventy
If user config returns a falsy pathPrefix, fall back to the default value
699
17.08.2022 10:57:26
18,000
9bbdcd72c9d7cb1e5858d83ad6bba86e06ce2c07
Improvements to Async Filters in Nunjucks 1. Adds a new `addAsyncFilter` configuration API method 2. Adds support for `async function` on standard `addFilter` method in Nunjucks 3. Throws an error if you return a promise from a `function` when using `addFilter` with Nunjucks Fixes Fixes Fixes
[ { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -10,6 +10,8 @@ const pkg = require(\"../package.json\");\nclass UserConfigError extends EleventyBaseError {}\n+const ComparisonAsyncFunction = (async () => {}).constructor;\n+\n// API to expose configuration options in config file\nclass UserConfig {\nconstructor() {\n@@ -236,12 +238,42 @@ class UserConfig {\n// namespacing happens downstream\nthis.addLiquidFilter(name, callback);\n- this.addNunjucksFilter(name, callback);\nthis.addJavaScriptFunction(name, callback);\n+ // This method *requires* `async function` and will not work with `function` that returns a promise\n+ if (callback instanceof ComparisonAsyncFunction) {\n+ this.addNunjucksAsyncFilter(name, async function (value, cb) {\n+ let ret = await callback(value);\n+ cb(null, ret);\n+ });\n+ } else {\n+ this.addNunjucksFilter(name, function (value) {\n+ let ret = callback(value);\n+ if (ret instanceof Promise) {\n+ throw new Error(\n+ `Nunjucks *is* async-friendly with \\`addFilter(\"${name}\", async function() {})\\` but you need to supply an \\`async function\\`. You returned a promise from \\`addFilter(\"${name}\", function() {})\\`. Alternatively, use the \\`addAsyncFilter(\"${name}\")\\` configuration API method.`\n+ );\n+ }\n+ return ret;\n+ });\n+\n// TODO remove Handlebars helpers in Universal Filters. Use shortcodes instead (the Handlebars template syntax is the same).\nthis.addHandlebarsHelper(name, callback);\n}\n+ }\n+\n+ // Liquid, Nunjucks, and JS only\n+ addAsyncFilter(name, callback) {\n+ debug(\"Adding universal async filter %o\", this.getNamespacedName(name));\n+\n+ // namespacing happens downstream\n+ this.addLiquidFilter(name, callback);\n+ this.addJavaScriptFunction(name, callback);\n+ this.addNunjucksAsyncFilter(name, async function (value, cb) {\n+ let ret = await callback(value);\n+ cb(null, ret);\n+ });\n+ }\ngetFilter(name) {\nreturn (\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateRenderNunjucksTest.js", "new_path": "test/TemplateRenderNunjucksTest.js", "diff": "@@ -1070,3 +1070,41 @@ test(\"Use a precompiled Nunjucks template\", async (t) => {\n34`\n);\n});\n+\n+test(\"Make sure addFilter is async-friendly for Nunjucks\", async (t) => {\n+ let templateConfig = new TemplateConfig();\n+ // requires async function\n+ templateConfig.userConfig.addFilter(\"fortytwo\", async function () {\n+ return getPromise(42);\n+ });\n+\n+ let tr = getNewTemplateRender(\"njk\", null, templateConfig);\n+\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 'hi' | fortytwo }}</p>\");\n+ t.is(await fn(), \"<p>42</p>\");\n+});\n+\n+test(\"Throw an error when you return a promise in addFilter for Nunjucks\", async (t) => {\n+ let templateConfig = new TemplateConfig();\n+ // requires async function\n+ templateConfig.userConfig.addFilter(\"fortytwo\", function () {\n+ return getPromise(42);\n+ });\n+\n+ let tr = getNewTemplateRender(\"njk\", null, templateConfig);\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 'hi' | fortytwo }}</p>\");\n+ await t.throwsAsync(fn);\n+});\n+\n+test(\"addAsyncFilter for Nunjucks\", async (t) => {\n+ let templateConfig = new TemplateConfig();\n+ // works without async function (can return promise)\n+ templateConfig.userConfig.addAsyncFilter(\"fortytwo\", function () {\n+ return getPromise(42);\n+ });\n+\n+ let tr = getNewTemplateRender(\"njk\", null, templateConfig);\n+\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 'hi' | fortytwo }}</p>\");\n+ t.is(await fn(), \"<p>42</p>\");\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
Improvements to Async Filters in Nunjucks 1. Adds a new `addAsyncFilter` configuration API method 2. Adds support for `async function` on standard `addFilter` method in Nunjucks 3. Throws an error if you return a promise from a `function` when using `addFilter` with Nunjucks Fixes #1382 Fixes #2536 Fixes #2254
699
17.08.2022 11:35:39
18,000
972e9fbbf27a86ac919f33759190407f9a69732f
Fix for to allow multiple arguments
[ { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -242,13 +242,14 @@ class UserConfig {\n// This method *requires* `async function` and will not work with `function` that returns a promise\nif (callback instanceof ComparisonAsyncFunction) {\n- this.addNunjucksAsyncFilter(name, async function (value, cb) {\n- let ret = await callback(value);\n+ this.addNunjucksAsyncFilter(name, async function (...args) {\n+ let cb = args.pop();\n+ let ret = await callback.call(this, ...args);\ncb(null, ret);\n});\n} else {\n- this.addNunjucksFilter(name, function (value) {\n- let ret = callback(value);\n+ this.addNunjucksFilter(name, function (...args) {\n+ let ret = callback.call(this, ...args);\nif (ret instanceof Promise) {\nthrow new Error(\n`Nunjucks *is* async-friendly with \\`addFilter(\"${name}\", async function() {})\\` but you need to supply an \\`async function\\`. You returned a promise from \\`addFilter(\"${name}\", function() {})\\`. Alternatively, use the \\`addAsyncFilter(\"${name}\")\\` configuration API method.`\n@@ -269,8 +270,9 @@ class UserConfig {\n// namespacing happens downstream\nthis.addLiquidFilter(name, callback);\nthis.addJavaScriptFunction(name, callback);\n- this.addNunjucksAsyncFilter(name, async function (value, cb) {\n- let ret = await callback(value);\n+ this.addNunjucksAsyncFilter(name, async function (...args) {\n+ let cb = args.pop();\n+ let ret = await callback.call(this, ...args);\ncb(null, ret);\n});\n}\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateRenderNunjucksTest.js", "new_path": "test/TemplateRenderNunjucksTest.js", "diff": "@@ -1074,14 +1074,14 @@ test(\"Use a precompiled Nunjucks template\", async (t) => {\ntest(\"Make sure addFilter is async-friendly for Nunjucks\", async (t) => {\nlet templateConfig = new TemplateConfig();\n// requires async function\n- templateConfig.userConfig.addFilter(\"fortytwo\", async function () {\n- return getPromise(42);\n+ templateConfig.userConfig.addFilter(\"fortytwo\", async function (val, val2) {\n+ return getPromise(val + val2);\n});\nlet tr = getNewTemplateRender(\"njk\", null, templateConfig);\n- let fn = await tr.getCompiledTemplate(\"<p>{{ 'hi' | fortytwo }}</p>\");\n- t.is(await fn(), \"<p>42</p>\");\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 10 | fortytwo(2) }}</p>\");\n+ t.is(await fn(), \"<p>12</p>\");\n});\ntest(\"Throw an error when you return a promise in addFilter for Nunjucks\", async (t) => {\n@@ -1099,12 +1099,12 @@ test(\"Throw an error when you return a promise in addFilter for Nunjucks\", async\ntest(\"addAsyncFilter for Nunjucks\", async (t) => {\nlet templateConfig = new TemplateConfig();\n// works without async function (can return promise)\n- templateConfig.userConfig.addAsyncFilter(\"fortytwo\", function () {\n- return getPromise(42);\n+ templateConfig.userConfig.addAsyncFilter(\"fortytwo\", function (val, val2) {\n+ return getPromise(val + val2);\n});\nlet tr = getNewTemplateRender(\"njk\", null, templateConfig);\n- let fn = await tr.getCompiledTemplate(\"<p>{{ 'hi' | fortytwo }}</p>\");\n- t.is(await fn(), \"<p>42</p>\");\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 10 | fortytwo(2) }}</p>\");\n+ t.is(await fn(), \"<p>12</p>\");\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix for #2536 to allow multiple arguments
699
18.08.2022 15:39:19
18,000
5e36ca3c71f4c952ac567961493122e6feb8da84
Fix to i18n plugin to handle pagination templates Match only one entry per language per pagination template
[ { "change_type": "MODIFY", "old_path": "src/Plugins/I18nPlugin.js", "new_path": "src/Plugins/I18nPlugin.js", "diff": "@@ -129,6 +129,7 @@ function normalizeInputPath(inputPath, extensionMap) {\n*/\nfunction getLocaleUrlsMap(urlToInputPath, extensionMap) {\nlet filemap = {};\n+ let paginationTemplateCheck = {};\nfor (let url in urlToInputPath) {\nlet originalFilepath = urlToInputPath[url];\nlet filepath = normalizeInputPath(originalFilepath, extensionMap);\n@@ -138,6 +139,10 @@ function getLocaleUrlsMap(urlToInputPath, extensionMap) {\n}\nlet langCode = LangUtils.getLanguageCodeFromInputPath(originalFilepath);\n+ let paginationCheckKey = `${originalFilepath}__${langCode}`;\n+\n+ // pagination templates should only match once per language\n+ if (!paginationTemplateCheck[paginationCheckKey]) {\nif (langCode) {\nfilemap[replaced].push({\nurl,\n@@ -147,6 +152,8 @@ function getLocaleUrlsMap(urlToInputPath, extensionMap) {\n} else {\nfilemap[replaced].push({ url });\n}\n+ paginationTemplateCheck[paginationCheckKey] = true;\n+ }\n}\n// Default sorted by lang code\n@@ -168,7 +175,9 @@ function getLocaleUrlsMap(urlToInputPath, extensionMap) {\nfor (let entry of filemap[filepath]) {\nlet url = entry.url;\nif (!urlMap[url]) {\n- urlMap[url] = filemap[filepath].filter((entry) => entry.url !== url);\n+ urlMap[url] = filemap[filepath].filter((entry) => {\n+ return entry.url !== url;\n+ });\n}\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix to i18n plugin to handle pagination templates Match only one entry per language per pagination template
699
18.08.2022 15:40:05
18,000
216beab159beff6bda35704ec581698e75a7b06c
Add `this.url` to linters and transforms
[ { "change_type": "MODIFY", "old_path": "src/Template.js", "new_path": "src/Template.js", "diff": "@@ -479,13 +479,15 @@ class Template extends TemplateContent {\nthis.linters.push(callback);\n}\n- async runLinters(str, inputPath, outputPath) {\n+ async runLinters(str, page) {\n+ let { inputPath, outputPath, url } = page;\nfor (let linter of this.linters) {\n// these can be asynchronous but no guarantee of order when they run\nlinter.call(\n{\ninputPath,\noutputPath,\n+ url,\n},\nstr,\ninputPath,\n@@ -501,7 +503,8 @@ class Template extends TemplateContent {\n});\n}\n- async runTransforms(str, inputPath, outputPath) {\n+ async runTransforms(str, page) {\n+ let { inputPath, outputPath, url } = page;\nfor (let { callback, name } of this.transforms) {\ntry {\nlet hadStrBefore = !!str;\n@@ -509,6 +512,7 @@ class Template extends TemplateContent {\n{\ninputPath,\noutputPath,\n+ url,\n},\nstr,\noutputPath\n@@ -788,12 +792,8 @@ class Template extends TemplateContent {\ncontent = page.templateContent;\n}\n- await this.runLinters(content, page.inputPath, page.outputPath);\n- content = await this.runTransforms(\n- content,\n- page.inputPath,\n- page.outputPath\n- );\n+ await this.runLinters(content, page);\n+ content = await this.runTransforms(content, page);\nreturn content;\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Add `this.url` to linters and transforms
699
18.08.2022 15:42:58
18,000
8dd2a1012de92c5ee1eab7c37e6bf1b36183927e
New HTML <base> plugin Adds filter to modify URLs directly (or URLs in arbitrary HTML) for arbitrary <base> preprocessing, pathPrefix, or absolute URL conversion for RSS/Atom/JSON feeds. Adds transform to apply pathPrefix automatically to any .html output (if pathPrefix is used)
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"nunjucks\": \"^3.2.3\",\n\"path-to-regexp\": \"^6.2.1\",\n\"please-upgrade-node\": \"^3.2.0\",\n+ \"posthtml\": \"^0.16.6\",\n+ \"posthtml-urls\": \"^1.0.0\",\n\"pug\": \"^3.0.2\",\n\"recursive-copy\": \"^2.0.14\",\n\"semver\": \"^7.3.7\",\n" }, { "change_type": "MODIFY", "old_path": "src/Filters/Url.js", "new_path": "src/Filters/Url.js", "diff": "@@ -10,7 +10,7 @@ function isValidUrl(url) {\n}\n}\n-// This is also used in the Eleventy Navigation plugin\n+// Note: This filter is used in the Eleventy Navigation plugin in versions prior to 0.3.4\nmodule.exports = function (url, pathPrefix) {\n// work with undefined\nurl = url || \"\";\n" }, { "change_type": "ADD", "old_path": null, "new_path": "src/Plugins/HtmlBasePlugin.js", "diff": "+const posthtml = require(\"posthtml\");\n+const urls = require(\"posthtml-urls\");\n+const urlFilter = require(\"../Filters/Url.js\");\n+const PathPrefixer = require(\"../Util/PathPrefixer.js\");\n+const { DeepCopy } = require(\"../Util/Merge\");\n+\n+function isValidUrl(url) {\n+ try {\n+ new URL(url);\n+ return true;\n+ } catch (e) {\n+ return false;\n+ }\n+}\n+\n+function addPathPrefixToUrl(url, pathPrefix, base) {\n+ let u;\n+ if (base) {\n+ u = new URL(url, base);\n+ } else {\n+ u = new URL(url);\n+ }\n+\n+ // Add pathPrefix **after** url is transformed using base\n+ if (pathPrefix) {\n+ u.pathname = PathPrefixer.joinUrlParts(pathPrefix, u.pathname);\n+ }\n+ return u.toString();\n+}\n+\n+// pathprefix is only used when overrideBase is a full URL\n+function transformUrl(url, base, opts = {}) {\n+ let { pathPrefix, pageUrl } = opts;\n+\n+ // full URL, return as-is\n+ if (isValidUrl(url)) {\n+ return url;\n+ }\n+\n+ // Not a full URL, but with a full base URL\n+ // e.g. relative urls like \"subdir/\", \"../subdir\", \"./subdir\"\n+ if (isValidUrl(base)) {\n+ // convert relative paths to absolute path first using pageUrl\n+ if (pageUrl && !url.startsWith(\"/\")) {\n+ url = new URL(url, `http://example.com${pageUrl}`).pathname;\n+ }\n+\n+ return addPathPrefixToUrl(url, pathPrefix, base);\n+ }\n+\n+ // Not a full URL, nor a full base URL (call the built-in `url` filter)\n+ return urlFilter.call(this, url, base);\n+}\n+\n+async function addToAllHtmlUrls(htmlContent, callback, processOptions = {}) {\n+ let modifier = posthtml().use(\n+ urls({\n+ eachURL: function (url) {\n+ return callback(url);\n+ },\n+ })\n+ );\n+\n+ let result = await modifier.process(htmlContent, processOptions);\n+ return result.html;\n+}\n+\n+module.exports = function (eleventyConfig, defaultOptions = {}) {\n+ let opts = DeepCopy(\n+ {\n+ // eleventyConfig.pathPrefix is new in Eleventy 2.0.0-canary.15\n+ // `base` can be a directory (for path prefix transformations)\n+ // OR a full URL with origin and pathname\n+ base: eleventyConfig.pathPrefix,\n+\n+ extensions: \"html\",\n+\n+ name: \"eleventy-htmlBaseWithPathPrefix\",\n+ filters: {\n+ base: \"htmlBaseUrl\",\n+ html: \"transformWithHtmlBase\",\n+ pathPrefix: \"addPathPrefixToUrl\",\n+ },\n+ },\n+ defaultOptions\n+ );\n+\n+ if (opts.base === undefined) {\n+ throw new Error(\n+ \"The `base` option is required in the Eleventy HTML Base plugin.\"\n+ );\n+ }\n+\n+ eleventyConfig.addFilter(opts.filters.pathPrefix, function (url) {\n+ return addPathPrefixToUrl(url, eleventyConfig.pathPrefix);\n+ });\n+\n+ eleventyConfig.addFilter(\n+ opts.filters.base,\n+ function (url, baseOverride, pageUrlOverride) {\n+ let base = baseOverride || opts.base;\n+\n+ // Do nothing with a default base\n+ if (base === \"/\") {\n+ return url;\n+ }\n+\n+ return transformUrl.call(this, url, base, {\n+ pathPrefix: eleventyConfig.pathPrefix,\n+ pageUrl:\n+ pageUrlOverride ||\n+ this.page?.url ||\n+ this.ctx?.page?.url ||\n+ this.context?.environments?.page?.url,\n+ });\n+ }\n+ );\n+\n+ eleventyConfig.addAsyncFilter(\n+ opts.filters.html,\n+ function (content, baseOverride, pageUrlOverride) {\n+ let base = baseOverride || opts.base;\n+\n+ // Do nothing with a default base\n+ if (base === \"/\") {\n+ return content;\n+ }\n+\n+ let fallbackPageUrl =\n+ this.page?.url ||\n+ this.ctx?.page?.url ||\n+ this.context?.environments?.page?.url;\n+ return addToAllHtmlUrls(content, (url) => {\n+ return transformUrl.call(this, url.trim(), base, {\n+ pathPrefix: eleventyConfig.pathPrefix,\n+ pageUrl: pageUrlOverride || fallbackPageUrl,\n+ });\n+ });\n+ }\n+ );\n+\n+ // Skip the transform with a default base\n+ if (opts.base !== \"/\") {\n+ let extensionMap = {};\n+ for (let ext of opts.extensions.split(\",\")) {\n+ extensionMap[ext] = true;\n+ }\n+\n+ eleventyConfig.addTransform(opts.name, function (content) {\n+ let ext = this.outputPath?.split(\".\").pop();\n+ if (extensionMap[ext]) {\n+ return addToAllHtmlUrls(content, (url) => {\n+ return transformUrl.call(this, url.trim(), opts.base, {\n+ pathPrefix: eleventyConfig.pathPrefix,\n+ pageUrl: this.url,\n+ });\n+ });\n+ }\n+\n+ return content;\n+ });\n+ }\n+};\n+\n+module.exports.applyBaseToUrl = transformUrl;\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -54,13 +54,19 @@ class TemplateConfig {\n* @member {String} - Path to local project config.\n* @default .eleventy.js\n*/\n+ if (projectConfigPath !== undefined) {\n+ if (!projectConfigPath) {\n+ // falsy skips config files\n+ this.projectConfigPaths = [];\n+ } else {\n+ this.projectConfigPaths = [projectConfigPath];\n+ }\n+ } else {\nthis.projectConfigPaths = [\n\".eleventy.js\",\n\"eleventy.config.js\",\n\"eleventy.config.cjs\",\n];\n- if (projectConfigPath !== undefined) {\n- this.projectConfigPaths = [projectConfigPath];\n}\nif (customRootConfig) {\n" }, { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -10,10 +10,12 @@ module.exports = function (config) {\nconfig.addFilter(\"slug\", slugFilter);\nconfig.addFilter(\"slugify\", slugifyFilter);\n- config.addFilter(\"url\", function (url, pathPrefixOverride) {\n+ // Add pathPrefix manually to a URL\n+ config.addFilter(\"url\", function addPathPrefix(url, pathPrefixOverride) {\nlet pathPrefix = pathPrefixOverride || templateConfig.getPathPrefix();\nreturn urlFilter.call(this, url, pathPrefix);\n});\n+\nconfig.addFilter(\"log\", (input, ...messages) => {\nconsole.log(input, ...messages);\nreturn input;\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/HtmlBasePluginTest.js", "diff": "+const test = require(\"ava\");\n+const HtmlBasePlugin = require(\"../src/Plugins/HtmlBasePlugin\");\n+const Eleventy = require(\"../src/Eleventy\");\n+const normalizeNewLines = require(\"./Util/normalizeNewLines\");\n+\n+function getContentFor(results, filename) {\n+ let content = results.filter((entry) =>\n+ entry.outputPath.endsWith(filename)\n+ )[0].content;\n+ return normalizeNewLines(content.trim());\n+}\n+\n+test(\"Using the filter directly\", async (t) => {\n+ let { applyBaseToUrl } = HtmlBasePlugin;\n+ // url, base, pathprefix\n+\n+ // default pathprefix\n+ t.is(applyBaseToUrl(\"/\", \"/\"), \"/\");\n+ t.is(applyBaseToUrl(\"/test/\", \"/\"), \"/test/\");\n+ t.is(applyBaseToUrl(\"subdir/\", \"/\"), \"subdir/\");\n+ t.is(applyBaseToUrl(\"../subdir/\", \"/\"), \"../subdir/\");\n+ t.is(applyBaseToUrl(\"./subdir/\", \"/\"), \"subdir/\");\n+ t.is(applyBaseToUrl(\"http://example.com/\", \"/\"), \"http://example.com/\");\n+ t.is(\n+ applyBaseToUrl(\"http://example.com/test/\", \"/\"),\n+ \"http://example.com/test/\"\n+ );\n+\n+ // with a pathprefix\n+ t.is(applyBaseToUrl(\"/\", \"/pathprefix/\"), \"/pathprefix/\");\n+ t.is(applyBaseToUrl(\"/test/\", \"/pathprefix/\"), \"/pathprefix/test/\");\n+ t.is(applyBaseToUrl(\"subdir/\", \"/pathprefix/\"), \"subdir/\");\n+ t.is(applyBaseToUrl(\"../subdir/\", \"/pathprefix/\"), \"../subdir/\");\n+ t.is(applyBaseToUrl(\"./subdir/\", \"/pathprefix/\"), \"subdir/\");\n+ t.is(applyBaseToUrl(\"http://url.com/\", \"/pathprefix/\"), \"http://url.com/\");\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"/pathprefix/\"),\n+ \"http://url.com/test/\"\n+ );\n+\n+ // with a URL base\n+ t.is(applyBaseToUrl(\"/\", \"http://example.com/\"), \"http://example.com/\");\n+ t.is(\n+ applyBaseToUrl(\"/test/\", \"http://example.com/\"),\n+ \"http://example.com/test/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"subdir/\", \"http://example.com/\"),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"../subdir/\", \"http://example.com/\"),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"./subdir/\", \"http://example.com/\"),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/\", \"http://example.com/\"),\n+ \"http://url.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"http://example.com/\"),\n+ \"http://url.com/test/\"\n+ );\n+\n+ // with a URL base with extra subdirectory\n+ t.is(\n+ applyBaseToUrl(\"/\", \"http://example.com/ignored/\"),\n+ \"http://example.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"/test/\", \"http://example.com/ignored/\"),\n+ \"http://example.com/test/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"subdir/\", \"http://example.com/deep/\"),\n+ \"http://example.com/deep/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"../subdir/\", \"http://example.com/deep/\"),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"./subdir/\", \"http://example.com/deep/\"),\n+ \"http://example.com/deep/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/\", \"http://example.com/ignored/\"),\n+ \"http://url.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"http://example.com/ignored/\"),\n+ \"http://url.com/test/\"\n+ );\n+\n+ // with a URL base and root pathprefix\n+ t.is(\n+ applyBaseToUrl(\"/\", \"http://example.com/\", { pathPrefix: \"/\" }),\n+ \"http://example.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"/test/\", \"http://example.com/\", { pathPrefix: \"/\" }),\n+ \"http://example.com/test/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"subdir/\", \"http://example.com/\", { pathPrefix: \"/\" }),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"../subdir/\", \"http://example.com/\", { pathPrefix: \"/\" }),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"./subdir/\", \"http://example.com/\", { pathPrefix: \"/\" }),\n+ \"http://example.com/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/\", \"http://example.com/\", {\n+ pathPrefix: \"/\",\n+ }),\n+ \"http://url.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"http://example.com/\", {\n+ pathPrefix: \"/\",\n+ }),\n+ \"http://url.com/test/\"\n+ );\n+\n+ // with a base and pathprefix\n+ t.is(\n+ applyBaseToUrl(\"/\", \"http://example.com/\", { pathPrefix: \"/pathprefix/\" }),\n+ \"http://example.com/pathprefix/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"/test/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ }),\n+ \"http://example.com/pathprefix/test/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"subdir/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ }),\n+ \"http://example.com/pathprefix/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"../subdir/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ }),\n+ \"http://example.com/pathprefix/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"./subdir/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ }),\n+ \"http://example.com/pathprefix/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ }),\n+ \"http://url.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ }),\n+ \"http://url.com/test/\"\n+ );\n+\n+ // with a base and pathprefix and page url (for relative path urls)\n+ t.is(\n+ applyBaseToUrl(\"/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"/test/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/test/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"subdir/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/deep/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"../subdir/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"./subdir/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/deep/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://url.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"http://example.com/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://url.com/test/\"\n+ );\n+\n+ // with a base (with extra subdir) and pathprefix and page url (for relative path urls)\n+ // Note: Extra subdir is ignored when pageUrl is in play\n+ t.is(\n+ applyBaseToUrl(\"/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"/test/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/test/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"subdir/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/deep/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"../subdir/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"./subdir/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://example.com/pathprefix/deep/subdir/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://url.com/\"\n+ );\n+ t.is(\n+ applyBaseToUrl(\"http://url.com/test/\", \"http://example.com/ignored/\", {\n+ pathPrefix: \"/pathprefix/\",\n+ pageUrl: \"/deep/\",\n+ }),\n+ \"http://url.com/test/\"\n+ );\n+});\n+\n+test(\"Using the HTML base plugin (default values)\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-base/\", \"./test/stubs-base/_site\", {\n+ configPath: false,\n+ config: function (eleventyConfig) {\n+ eleventyConfig.setUseTemplateCache(false);\n+ eleventyConfig.addPlugin(HtmlBasePlugin);\n+ },\n+ });\n+ elev.setIsVerbose(false);\n+ elev.disableLogger();\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/deep/index.html\"),\n+ `<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url(/test.jpg); }</style>\n+<link rel=\"stylesheet\" href=\"/test.css\">\n+<script src=\"/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"/\">Home</a>\n+<a href=\"subdir/\">Test</a>\n+<a href=\"../subdir/\">Test</a>\n+</body>\n+</html>`\n+ );\n+});\n+\n+test(\"Using the HTML base plugin with pathPrefix: /test/\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-base/\", \"./test/stubs-base/_site\", {\n+ pathPrefix: \"/test/\",\n+\n+ configPath: false,\n+ config: function (eleventyConfig) {\n+ eleventyConfig.setUseTemplateCache(false);\n+ eleventyConfig.addPlugin(HtmlBasePlugin);\n+ },\n+ });\n+ elev.setIsVerbose(false);\n+ elev.disableLogger();\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/deep/index.html\"),\n+ `<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url(/test/test.jpg); }</style>\n+<link rel=\"stylesheet\" href=\"/test/test.css\">\n+<script src=\"/test/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"/test/\">Home</a>\n+<a href=\"subdir/\">Test</a>\n+<a href=\"../subdir/\">Test</a>\n+</body>\n+</html>`\n+ );\n+});\n+\n+test(\"Using the HTML base plugin with pathPrefix: /test/ and base: http://example.com/\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-base/\", \"./test/stubs-base/_site\", {\n+ pathPrefix: \"/test/\",\n+\n+ configPath: false,\n+ config: function (eleventyConfig) {\n+ eleventyConfig.setUseTemplateCache(false);\n+ eleventyConfig.addPlugin(HtmlBasePlugin, {\n+ base: \"http://example.com/\",\n+ });\n+ },\n+ });\n+\n+ elev.setIsVerbose(false);\n+ elev.disableLogger();\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/deep/index.html\"),\n+ `<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url(http://example.com/test/test.jpg); }</style>\n+<link rel=\"stylesheet\" href=\"http://example.com/test/test.css\">\n+<script src=\"http://example.com/test/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"http://example.com/test/\">Home</a>\n+<a href=\"http://example.com/test/deep/subdir/\">Test</a>\n+<a href=\"http://example.com/test/subdir/\">Test</a>\n+</body>\n+</html>`\n+ );\n+});\n+\n+test(\"Using the HTML base plugin strips extra path in full URL base (default pathPrefix)\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-base/\", \"./test/stubs-base/_site\", {\n+ configPath: false,\n+ config: function (eleventyConfig) {\n+ eleventyConfig.setUseTemplateCache(false);\n+ eleventyConfig.addPlugin(HtmlBasePlugin, {\n+ base: \"http://example.com/hello/\", // extra path will be stripped\n+ });\n+ },\n+ });\n+\n+ elev.setIsVerbose(false);\n+ elev.disableLogger();\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/deep/index.html\"),\n+ `<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url(http://example.com/test.jpg); }</style>\n+<link rel=\"stylesheet\" href=\"http://example.com/test.css\">\n+<script src=\"http://example.com/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"http://example.com/\">Home</a>\n+<a href=\"http://example.com/deep/subdir/\">Test</a>\n+<a href=\"http://example.com/subdir/\">Test</a>\n+</body>\n+</html>`\n+ );\n+});\n+\n+test(\"Using the HTML base plugin strips extra path in full URL base (pathPrefix: /test/)\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-base/\", \"./test/stubs-base/_site\", {\n+ pathPrefix: \"/test/\",\n+\n+ configPath: false,\n+ config: function (eleventyConfig) {\n+ eleventyConfig.setUseTemplateCache(false);\n+ eleventyConfig.addPlugin(HtmlBasePlugin, {\n+ base: \"http://example.com/hello/\", // extra path will be stripped\n+ });\n+ },\n+ });\n+\n+ elev.setIsVerbose(false);\n+ elev.disableLogger();\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/deep/index.html\"),\n+ `<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url(http://example.com/test/test.jpg); }</style>\n+<link rel=\"stylesheet\" href=\"http://example.com/test/test.css\">\n+<script src=\"http://example.com/test/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"http://example.com/test/\">Home</a>\n+<a href=\"http://example.com/test/deep/subdir/\">Test</a>\n+<a href=\"http://example.com/test/subdir/\">Test</a>\n+</body>\n+</html>`\n+ );\n+});\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-base/index.njk", "diff": "+---\n+permalink: /deep/\n+---\n+<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url({{ \"/test.jpg\" | htmlBaseUrl }}); }</style>\n+<link rel=\"stylesheet\" href=\"/test.css\">\n+<script src=\"/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"/\">Home</a>\n+<a href=\"subdir/\">Test</a>\n+<a href=\"../subdir/\">Test</a>\n+</body>\n+</html>\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
New HTML <base> plugin Adds filter to modify URLs directly (or URLs in arbitrary HTML) for arbitrary <base> preprocessing, pathPrefix, or absolute URL conversion for RSS/Atom/JSON feeds. Adds transform to apply pathPrefix automatically to any .html output (if pathPrefix is used)
699
18.08.2022 16:32:17
18,000
a9e7cb7587f960b38e8d65dc7d180b0c7f9c5765
Minor option rename for base html plugin
[ { "change_type": "MODIFY", "old_path": "src/Plugins/HtmlBasePlugin.js", "new_path": "src/Plugins/HtmlBasePlugin.js", "diff": "@@ -71,7 +71,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\n// eleventyConfig.pathPrefix is new in Eleventy 2.0.0-canary.15\n// `base` can be a directory (for path prefix transformations)\n// OR a full URL with origin and pathname\n- base: eleventyConfig.pathPrefix,\n+ baseHref: eleventyConfig.pathPrefix,\nextensions: \"html\",\n@@ -85,7 +85,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\ndefaultOptions\n);\n- if (opts.base === undefined) {\n+ if (opts.baseHref === undefined) {\nthrow new Error(\n\"The `base` option is required in the Eleventy HTML Base plugin.\"\n);\n@@ -98,7 +98,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\neleventyConfig.addFilter(\nopts.filters.base,\nfunction (url, baseOverride, pageUrlOverride) {\n- let base = baseOverride || opts.base;\n+ let base = baseOverride || opts.baseHref;\n// Do nothing with a default base\nif (base === \"/\") {\n@@ -119,7 +119,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\neleventyConfig.addAsyncFilter(\nopts.filters.html,\nfunction (content, baseOverride, pageUrlOverride) {\n- let base = baseOverride || opts.base;\n+ let base = baseOverride || opts.baseHref;\n// Do nothing with a default base\nif (base === \"/\") {\n@@ -140,7 +140,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\n);\n// Skip the transform with a default base\n- if (opts.base !== \"/\") {\n+ if (opts.baseHref !== \"/\") {\nlet extensionMap = {};\nfor (let ext of opts.extensions.split(\",\")) {\nextensionMap[ext] = true;\n@@ -150,7 +150,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\nlet ext = this.outputPath?.split(\".\").pop();\nif (extensionMap[ext]) {\nreturn addToAllHtmlUrls(content, (url) => {\n- return transformUrl.call(this, url.trim(), opts.base, {\n+ return transformUrl.call(this, url.trim(), opts.baseHref, {\npathPrefix: eleventyConfig.pathPrefix,\npageUrl: this.url,\n});\n" }, { "change_type": "MODIFY", "old_path": "test/HtmlBasePluginTest.js", "new_path": "test/HtmlBasePluginTest.js", "diff": "@@ -355,7 +355,7 @@ test(\"Using the HTML base plugin with pathPrefix: /test/ and base: http://exampl\nconfig: function (eleventyConfig) {\neleventyConfig.setUseTemplateCache(false);\neleventyConfig.addPlugin(HtmlBasePlugin, {\n- base: \"http://example.com/\",\n+ baseHref: \"http://example.com/\",\n});\n},\n});\n@@ -393,7 +393,7 @@ test(\"Using the HTML base plugin strips extra path in full URL base (default pat\nconfig: function (eleventyConfig) {\neleventyConfig.setUseTemplateCache(false);\neleventyConfig.addPlugin(HtmlBasePlugin, {\n- base: \"http://example.com/hello/\", // extra path will be stripped\n+ baseHref: \"http://example.com/hello/\", // extra path will be stripped\n});\n},\n});\n@@ -433,7 +433,7 @@ test(\"Using the HTML base plugin strips extra path in full URL base (pathPrefix:\nconfig: function (eleventyConfig) {\neleventyConfig.setUseTemplateCache(false);\neleventyConfig.addPlugin(HtmlBasePlugin, {\n- base: \"http://example.com/hello/\", // extra path will be stripped\n+ baseHref: \"http://example.com/hello/\", // extra path will be stripped\n});\n},\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Minor option rename for base html plugin
699
19.08.2022 10:43:05
18,000
dc8417d6eb558c6b20e830a7274b39fbd585a1f0
Base plugin tweaks, allow opt-out of transform using falsy extensions
[ { "change_type": "MODIFY", "old_path": "src/Plugins/HtmlBasePlugin.js", "new_path": "src/Plugins/HtmlBasePlugin.js", "diff": "@@ -75,11 +75,11 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\nextensions: \"html\",\n- name: \"eleventy-htmlBaseWithPathPrefix\",\n+ name: \"htmlBaseWithPathPrefix\",\nfilters: {\nbase: \"htmlBaseUrl\",\nhtml: \"transformWithHtmlBase\",\n- pathPrefix: \"addPathPrefixToUrl\",\n+ pathPrefix: \"addPathPrefixToFullUrl\",\n},\n},\ndefaultOptions\n@@ -142,10 +142,12 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\n// Skip the transform with a default base\nif (opts.baseHref !== \"/\") {\nlet extensionMap = {};\n- for (let ext of opts.extensions.split(\",\")) {\n+ for (let ext of (opts.extensions || \"\").split(\",\")) {\nextensionMap[ext] = true;\n}\n+ // Skip the transform if no extensions are specified\n+ if (Object.keys(extensionMap).length > 0) {\neleventyConfig.addTransform(opts.name, function (content) {\nlet ext = this.outputPath?.split(\".\").pop();\nif (extensionMap[ext]) {\n@@ -160,6 +162,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\nreturn content;\n});\n}\n+ }\n};\nmodule.exports.applyBaseToUrl = transformUrl;\n" }, { "change_type": "MODIFY", "old_path": "test/HtmlBasePluginTest.js", "new_path": "test/HtmlBasePluginTest.js", "diff": "@@ -26,6 +26,18 @@ test(\"Using the filter directly\", async (t) => {\n\"http://example.com/test/\"\n);\n+ // relative url pathprefix is ignored\n+ t.is(applyBaseToUrl(\"/\", \"../\"), \"/\");\n+ t.is(applyBaseToUrl(\"/test/\", \"../\"), \"/test/\");\n+ t.is(applyBaseToUrl(\"subdir/\", \"../\"), \"subdir/\");\n+ t.is(applyBaseToUrl(\"../subdir/\", \"../\"), \"../subdir/\");\n+ t.is(applyBaseToUrl(\"./subdir/\", \"../\"), \"subdir/\");\n+ t.is(applyBaseToUrl(\"http://example.com/\", \"../\"), \"http://example.com/\");\n+ t.is(\n+ applyBaseToUrl(\"http://example.com/test/\", \"../\"),\n+ \"http://example.com/test/\"\n+ );\n+\n// with a pathprefix\nt.is(applyBaseToUrl(\"/\", \"/pathprefix/\"), \"/pathprefix/\");\nt.is(applyBaseToUrl(\"/test/\", \"/pathprefix/\"), \"/pathprefix/test/\");\n@@ -464,3 +476,43 @@ test(\"Using the HTML base plugin strips extra path in full URL base (pathPrefix:\n</html>`\n);\n});\n+\n+test(\"Opt out of the transform with falsy extensions list\", async (t) => {\n+ let elev = new Eleventy(\"./test/stubs-base/\", \"./test/stubs-base/_site\", {\n+ pathPrefix: \"/test/\",\n+\n+ configPath: false,\n+ config: function (eleventyConfig) {\n+ eleventyConfig.setUseTemplateCache(false);\n+ eleventyConfig.addPlugin(HtmlBasePlugin, {\n+ extensions: false,\n+ });\n+ },\n+ });\n+\n+ elev.setIsVerbose(false);\n+ elev.disableLogger();\n+\n+ let results = await elev.toJSON();\n+ t.is(\n+ getContentFor(results, \"/deep/index.html\"),\n+ `<!doctype html>\n+<html lang=\"en\">\n+<head>\n+<meta charset=\"utf-8\">\n+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n+<meta name=\"description\" content=\"\">\n+<title></title>\n+<style>div { background-image: url(test.jpg); }</style>\n+<style>div { background-image: url(/test/test.jpg); }</style>\n+<link rel=\"stylesheet\" href=\"/test.css\">\n+<script src=\"/test.js\"></script>\n+</head>\n+<body>\n+<a href=\"/\">Home</a>\n+<a href=\"subdir/\">Test</a>\n+<a href=\"../subdir/\">Test</a>\n+</body>\n+</html>`\n+ );\n+});\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateRenderHandlebarsTest.js", "new_path": "test/TemplateRenderHandlebarsTest.js", "diff": "@@ -123,6 +123,20 @@ test(\"Handlebars Render Helper (uses argument)\", async (t) => {\nt.is(await fn({ name: \"Zach\" }), \"<p>This is a Zach.</p>\");\n});\n+test(\"Handlebars Render Helper (uses string argument)\", async (t) => {\n+ let tr = getNewTemplateRender(\"hbs\");\n+ tr.engine.addHelpers({\n+ helpername2: function (name) {\n+ return name;\n+ },\n+ });\n+\n+ let fn = await tr.getCompiledTemplate(\n+ `<p>This is a {{helpername2 \"Zach\"}}.</p>`\n+ );\n+ t.is(await fn({ name: \"Zach\" }), \"<p>This is a Zach.</p>\");\n+});\n+\ntest(\"Handlebars Render Shortcode\", async (t) => {\nt.plan(3);\nlet tr = getNewTemplateRender(\"hbs\");\n" } ]
JavaScript
MIT License
11ty/eleventy
Base plugin tweaks, allow opt-out of transform using falsy extensions
699
22.08.2022 11:47:44
18,000
a315cb538b94753cce6a3ec971c55ac06db9f781
Testing async filters on nunjucks
[ { "change_type": "MODIFY", "old_path": "test/TemplateRenderNunjucksTest.js", "new_path": "test/TemplateRenderNunjucksTest.js", "diff": "@@ -1108,3 +1108,40 @@ test(\"addAsyncFilter for Nunjucks\", async (t) => {\nlet fn = await tr.getCompiledTemplate(\"<p>{{ 10 | fortytwo(2) }}</p>\");\nt.is(await fn(), \"<p>12</p>\");\n});\n+\n+test(\"Asynchronous filters (via addNunjucksFilter) for Nunjucks\", async (t) => {\n+ let templateConfig = new TemplateConfig();\n+ // works without async function (can return promise)\n+ templateConfig.userConfig.addNunjucksFilter(\n+ \"fortytwo\",\n+ function (value1, value2, callback) {\n+ setTimeout(function () {\n+ callback(null, value1 + value2);\n+ }, 100);\n+ },\n+ true\n+ );\n+\n+ let tr = getNewTemplateRender(\"njk\", null, templateConfig);\n+\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 10 | fortytwo(2) }}</p>\");\n+ t.is(await fn(), \"<p>12</p>\");\n+});\n+\n+test(\"Asynchronous filters (via addNunjucksAsyncFilter) for Nunjucks\", async (t) => {\n+ let templateConfig = new TemplateConfig();\n+ // works without async function (can return promise)\n+ templateConfig.userConfig.addNunjucksAsyncFilter(\n+ \"fortytwo\",\n+ function (value1, value2, callback) {\n+ setTimeout(function () {\n+ callback(null, value1 + value2);\n+ }, 100);\n+ }\n+ );\n+\n+ let tr = getNewTemplateRender(\"njk\", null, templateConfig);\n+\n+ let fn = await tr.getCompiledTemplate(\"<p>{{ 10 | fortytwo(2) }}</p>\");\n+ t.is(await fn(), \"<p>12</p>\");\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
Testing #1913 async filters on nunjucks
699
22.09.2022 11:37:28
18,000
9bc7cf091001b7d833e2cd0be775aa086629db8a
Pin liquidjs for
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"is-glob\": \"^4.0.3\",\n\"iso-639-1\": \"^2.1.15\",\n\"kleur\": \"^4.1.5\",\n- \"liquidjs\": \"^9.40.0\",\n+ \"liquidjs\": \"9.41.0\",\n\"lodash\": \"^4.17.21\",\n\"luxon\": \"^3.0.1\",\n\"markdown-it\": \"^13.0.1\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Pin liquidjs for #2571
699
22.09.2022 11:37:56
18,000
ea7414069ca0afd44271c48d9e6b0487dbf7ff52
Changing to more specific default cache key for custom templates.
[ { "change_type": "MODIFY", "old_path": "src/Engines/TemplateEngine.js", "new_path": "src/Engines/TemplateEngine.js", "diff": "@@ -191,7 +191,9 @@ class TemplateEngine {\n}\ngetCompileCacheKey(str, inputPath) {\n- return str;\n+ // Changing to use inputPath and contents, this created weird bugs when two identical files had different file paths\n+ // TODO update docs\n+ return inputPath + str;\n}\nget defaultTemplateFileExtension() {\n" } ]
JavaScript
MIT License
11ty/eleventy
Changing to more specific default cache key for custom templates.
699
22.09.2022 11:53:07
18,000
70320958ca255467b458e3f4fb2bb911ec2a3cd3
Adds `eleventy.layouts` event. Also swaps a few events to use new `emitLazy` method.
[ { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -360,9 +360,11 @@ class TemplateMap {\n}.bind(this)\n);\n- await this.config.events.emit(\"eleventy.contentMap\", {\n+ await this.config.events.emitLazy(\"eleventy.contentMap\", () => {\n+ return {\ninputPathToUrl: this.generateInputUrlContentMap(orderedMap),\nurlToInputPath: this.generateUrlMap(orderedMap),\n+ };\n});\nawait this.populateContentDataInMap(orderedMap);\n@@ -372,8 +374,11 @@ class TemplateMap {\nthis.checkForDuplicatePermalinks();\n- await this.config.events.emit(\n- \"eleventy.serverlessUrlMap\",\n+ await this.config.events.emitLazy(\"eleventy.layouts\", () =>\n+ this.getListOfLayoutFiles()\n+ );\n+\n+ await this.config.events.emitLazy(\"eleventy.serverlessUrlMap\", () =>\nthis.generateServerlessUrlMap(orderedMap)\n);\n}\n@@ -649,6 +654,23 @@ class TemplateMap {\nreturn Promise.all(promises);\n}\n+ getListOfLayoutFiles() {\n+ let layouts = {};\n+\n+ for (let entry of this.map) {\n+ for (let page of entry._pages) {\n+ let tmpl = page.template;\n+ let layout = page.data[this.config.keys.layout];\n+ if (layout) {\n+ let layoutInstance = tmpl.getLayout(layout);\n+ layouts[layoutInstance.inputPath] = true;\n+ }\n+ }\n+ }\n+\n+ return Object.keys(layouts);\n+ }\n+\ncheckForDuplicatePermalinks() {\nlet permalinks = {};\nlet warnings = {};\n" }, { "change_type": "MODIFY", "old_path": "src/TemplatePassthroughManager.js", "new_path": "src/TemplatePassthroughManager.js", "diff": "@@ -303,9 +303,9 @@ class TemplatePassthroughManager {\nreturn Promise.all(\npassthroughs.map((pass) => this.copyPassthrough(pass))\n).then(async (result) => {\n- await this.config.events.emit(\"eleventy.passthrough\", {\n+ await this.config.events.emitLazy(\"eleventy.passthrough\", () => ({\nmap: this.getAliasesFromPassthroughResults(result),\n- });\n+ }));\ndebug(`TemplatePassthrough copy finished. Current count: ${this.count}`);\nreturn result;\n" }, { "change_type": "MODIFY", "old_path": "src/Util/AsyncEventEmitter.js", "new_path": "src/Util/AsyncEventEmitter.js", "diff": "@@ -18,6 +18,29 @@ class AsyncEventEmitter extends EventEmitter {\nreturn Promise.all(listeners.map((listener) => listener.apply(this, args)));\n}\n+\n+ /**\n+ * @param {string} type - The event name to emit.\n+ * @param {*[]} args - Additional lazy-executed function arguments that get passed to listeners.\n+ * @returns {Promise<*[]>} - Promise resolves once all listeners were invoked\n+ */\n+ async emitLazy(type, ...args) {\n+ let listeners = this.listeners(type);\n+ if (listeners.length === 0) {\n+ return [];\n+ }\n+\n+ return this.emit.call(\n+ this,\n+ type,\n+ ...args.map((arg) => {\n+ if (typeof arg === \"function\") {\n+ return arg();\n+ }\n+ return arg;\n+ })\n+ );\n+ }\n}\nmodule.exports = AsyncEventEmitter;\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateMapTest.js", "new_path": "test/TemplateMapTest.js", "diff": "@@ -1466,3 +1466,23 @@ test(\"serverlessUrlMap Event (empty pagination template with `serverless` should\nawait tm.add(tmpl);\nawait tm.cache();\n});\n+\n+test(\"eleventy.layouts Event\", async (t) => {\n+ t.plan(1);\n+\n+ let eleventyConfig = new TemplateConfig();\n+ eleventyConfig.userConfig.on(\"eleventy.layouts\", (layouts) => {\n+ t.deepEqual(layouts, [\"./test/stubs-layouts-event/_includes/first.liquid\"]);\n+ });\n+\n+ let tm = new TemplateMap(eleventyConfig);\n+ let tmpl = getNewTemplate(\n+ \"./test/stubs-layouts-event/page.md\",\n+ \"./test/stubs-layouts-event/\",\n+ \"./test/stubs-layouts-event/_site\",\n+ eleventyConfig\n+ );\n+\n+ await tm.add(tmpl);\n+ await tm.cache();\n+});\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-layouts-event/_includes/first.liquid", "diff": "+{{ content }}\n\\ No newline at end of file\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-layouts-event/page.md", "diff": "+---\n+layout: first\n+---\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds `eleventy.layouts` event. Also swaps a few events to use new `emitLazy` method.
699
22.09.2022 15:12:34
18,000
830573c790d220232b75950f9df8c6f13be88a1a
Swap `eleventy.layouts` event to return a layouts map of layouts in use
[ { "change_type": "MODIFY", "old_path": "src/TemplateMap.js", "new_path": "src/TemplateMap.js", "diff": "@@ -375,7 +375,7 @@ class TemplateMap {\nthis.checkForDuplicatePermalinks();\nawait this.config.events.emitLazy(\"eleventy.layouts\", () =>\n- this.getListOfLayoutFiles()\n+ this.generateLayoutsMap()\n);\nawait this.config.events.emitLazy(\"eleventy.serverlessUrlMap\", () =>\n@@ -654,7 +654,7 @@ class TemplateMap {\nreturn Promise.all(promises);\n}\n- getListOfLayoutFiles() {\n+ generateLayoutsMap() {\nlet layouts = {};\nfor (let entry of this.map) {\n@@ -662,13 +662,20 @@ class TemplateMap {\nlet tmpl = page.template;\nlet layout = page.data[this.config.keys.layout];\nif (layout) {\n- let layoutInstance = tmpl.getLayout(layout);\n- layouts[layoutInstance.inputPath] = true;\n+ let layoutFilePath = tmpl.getLayout(layout)?.inputPath;\n+ if (!layouts[layoutFilePath]) {\n+ layouts[layoutFilePath] = new Set();\n}\n+ layouts[layoutFilePath].add(page.inputPath);\n}\n}\n+ }\n+\n+ for (let key in layouts) {\n+ layouts[key] = Array.from(layouts[key]);\n+ }\n- return Object.keys(layouts);\n+ return layouts;\n}\ncheckForDuplicatePermalinks() {\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateMapTest.js", "new_path": "test/TemplateMapTest.js", "diff": "@@ -1471,8 +1471,12 @@ test(\"eleventy.layouts Event\", async (t) => {\nt.plan(1);\nlet eleventyConfig = new TemplateConfig();\n- eleventyConfig.userConfig.on(\"eleventy.layouts\", (layouts) => {\n- t.deepEqual(layouts, [\"./test/stubs-layouts-event/_includes/first.liquid\"]);\n+ eleventyConfig.userConfig.on(\"eleventy.layouts\", (layoutMap) => {\n+ t.deepEqual(layoutMap, {\n+ \"./test/stubs-layouts-event/_includes/first.liquid\": [\n+ \"./test/stubs-layouts-event/page.md\",\n+ ],\n+ });\n});\nlet tm = new TemplateMap(eleventyConfig);\n" } ]
JavaScript
MIT License
11ty/eleventy
Swap `eleventy.layouts` event to return a layouts map of layouts in use
699
16.11.2022 16:13:33
21,600
6710aaa00b83c09d09cdf714634cac1ec6b1a3fd
Render plugin was missing classes for error messaging
[ { "change_type": "MODIFY", "old_path": "src/Plugins/RenderPlugin.js", "new_path": "src/Plugins/RenderPlugin.js", "diff": "@@ -9,8 +9,12 @@ const { ProxyWrap } = require(\"../Util/ProxyWrap\");\nconst TemplateDataInitialGlobalData = require(\"../TemplateDataInitialGlobalData\");\nconst TemplateRender = require(\"../TemplateRender\");\nconst TemplateConfig = require(\"../TemplateConfig\");\n+const EleventyBaseError = require(\"../EleventyBaseError\");\n+const EleventyErrorUtil = require(\"../EleventyErrorUtil\");\nconst Liquid = require(\"../Engines/Liquid\");\n+class EleventyShortcodeError extends EleventyBaseError {}\n+\nasync function compile(\ncontent,\ntemplateLang,\n@@ -25,7 +29,12 @@ async function compile(\ntemplateLang = this.page.templateSyntax;\n}\n- let cfg = templateConfig.getConfig();\n+ let cfg = templateConfig;\n+ // templateConfig might already be a userconfig\n+ if (cfg instanceof TemplateConfig) {\n+ cfg = cfg.getConfig();\n+ }\n+\nlet tr = new TemplateRender(templateLang, cfg.dir.input, templateConfig);\ntr.extensionMap = extensionMap;\ntr.setEngineOverride(templateLang);\n@@ -253,7 +262,7 @@ function EleventyPlugin(eleventyConfig, options = {}) {\nif (e) {\nresolve(\nnew EleventyShortcodeError(\n- `Error with Nunjucks paired shortcode \\`${shortcodeName}\\`${EleventyErrorUtil.convertErrorToString(\n+ `Error with Nunjucks paired shortcode \\`${tagName}\\`${EleventyErrorUtil.convertErrorToString(\ne\n)}`\n)\n@@ -274,7 +283,7 @@ function EleventyPlugin(eleventyConfig, options = {}) {\n.catch(function (e) {\nresolve(\nnew EleventyShortcodeError(\n- `Error with Nunjucks paired shortcode \\`${shortcodeName}\\`${EleventyErrorUtil.convertErrorToString(\n+ `Error with Nunjucks paired shortcode \\`${tagName}\\`${EleventyErrorUtil.convertErrorToString(\ne\n)}`\n),\n" } ]
JavaScript
MIT License
11ty/eleventy
Render plugin was missing classes for error messaging
699
17.11.2022 14:24:42
21,600
eb856deff357490c52508001f0148af1bb390ecd
Update dependencies for 2.0.0-canary.17
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "]\n},\n\"devDependencies\": {\n- \"@11ty/eleventy-plugin-syntaxhighlight\": \"^4.1.0\",\n+ \"@11ty/eleventy-plugin-syntaxhighlight\": \"^4.2.0\",\n\"@11ty/eleventy-plugin-vue\": \"1.0.0-canary.8\",\n- \"@vue/server-renderer\": \"^3.2.39\",\n- \"ava\": \"^4.3.3\",\n- \"husky\": \"^8.0.1\",\n+ \"@vue/server-renderer\": \"^3.2.45\",\n+ \"ava\": \"^5.1.0\",\n+ \"husky\": \"^8.0.2\",\n\"js-yaml\": \"^4.1.0\",\n\"lint-staged\": \"^13.0.3\",\n\"markdown-it-emoji\": \"^2.0.2\",\n- \"marked\": \"^4.1.0\",\n+ \"marked\": \"^4.2.2\",\n\"nyc\": \"^15.1.0\",\n\"prettier\": \"^2.7.1\",\n\"pretty\": \"^2.0.0\",\n\"rimraf\": \"^3.0.2\",\n- \"sass\": \"^1.55.0\",\n- \"vue\": \"^3.2.39\"\n+ \"sass\": \"^1.56.1\",\n+ \"vue\": \"^3.2.45\"\n},\n\"dependencies\": {\n\"@11ty/dependency-tree\": \"^2.0.1\",\n\"is-glob\": \"^4.0.3\",\n\"iso-639-1\": \"^2.1.15\",\n\"kleur\": \"^4.1.5\",\n- \"liquidjs\": \"9.41.0\",\n+ \"liquidjs\": \"9.42.1\",\n\"lodash\": \"^4.17.21\",\n- \"luxon\": \"^3.0.3\",\n+ \"luxon\": \"^3.1.0\",\n\"markdown-it\": \"^13.0.1\",\n- \"minimist\": \"^1.2.6\",\n- \"moo\": \"^0.5.1\",\n+ \"minimist\": \"^1.2.7\",\n+ \"moo\": \"^0.5.2\",\n\"multimatch\": \"^5.0.0\",\n\"mustache\": \"^4.2.0\",\n\"normalize-path\": \"^3.0.0\",\n\"posthtml-urls\": \"^1.0.0\",\n\"pug\": \"^3.0.2\",\n\"recursive-copy\": \"^2.0.14\",\n- \"semver\": \"^7.3.7\",\n+ \"semver\": \"^7.3.8\",\n\"slugify\": \"^1.6.5\"\n}\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Update dependencies for 2.0.0-canary.17
699
17.11.2022 14:29:45
21,600
15a11a424ac78fe57080d40766d515b07ef6820d
Keep liquidjs pinned for
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"is-glob\": \"^4.0.3\",\n\"iso-639-1\": \"^2.1.15\",\n\"kleur\": \"^4.1.5\",\n- \"liquidjs\": \"9.42.1\",\n+ \"liquidjs\": \"9.41.0\",\n\"lodash\": \"^4.17.21\",\n\"luxon\": \"^3.1.0\",\n\"markdown-it\": \"^13.0.1\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Keep liquidjs pinned for #2571
699
17.11.2022 16:37:10
21,600
a689fa9e4d0abe50734e54973db07202966fbf8a
Docs pinned priority
[ { "change_type": "MODIFY", "old_path": "docs/release-instructions.md", "new_path": "docs/release-instructions.md", "diff": "## List of dependencies that went ESM\n+- `liquidjs` is pinned to 9.41.0 because of https://github.com/11ty/eleventy/issues/2571\n- `@sindresorhus/slugify` ESM at 2.x\n- `multimatch` is ESM at 6\n- `bcp-47-normalize` at 1.x\n-- `liquidjs` is pinned to 9.41.0 because of https://github.com/11ty/eleventy/issues/2571\n# Release Procedure\n" } ]
JavaScript
MIT License
11ty/eleventy
Docs pinned priority
699
18.11.2022 17:16:15
21,600
0c27a80617d8c5be1498c67175767721a116167c
Decouple processing ignores from watchIgnores. Fixes Whether we want to ignore a file during watch or ignore a file for processing are two separate concerns.
[ { "change_type": "MODIFY", "old_path": "src/EleventyFiles.js", "new_path": "src/EleventyFiles.js", "diff": "@@ -3,6 +3,7 @@ const fastglob = require(\"fast-glob\");\nconst { TemplatePath } = require(\"@11ty/eleventy-utils\");\nconst EleventyExtensionMap = require(\"./EleventyExtensionMap\");\n+const EleventyWatchTargets = require(\"./EleventyWatchTargets\");\nconst TemplateData = require(\"./TemplateData\");\nconst TemplateGlob = require(\"./TemplateGlob\");\nconst TemplatePassthroughManager = require(\"./TemplatePassthroughManager\");\n@@ -216,6 +217,12 @@ class EleventyFiles {\nfor (let ignore of this.extraIgnores) {\nuniqueIgnores.add(ignore);\n}\n+ // Placing the config ignores last here is import to the tests\n+ for (let ignore of this.config.ignores) {\n+ uniqueIgnores.add(\n+ TemplateGlob.normalizePath(this.localPathRoot || \".\", ignore)\n+ );\n+ }\nreturn Array.from(uniqueIgnores);\n}\n@@ -299,10 +306,6 @@ class EleventyFiles {\nlet rootDirectory = this.localPathRoot || \".\";\nlet files = new Set();\n- for (let ignore of this.config.ignores) {\n- files.add(TemplateGlob.normalizePath(rootDirectory, ignore));\n- }\n-\nif (this.config.useGitIgnore) {\nfor (let ignore of EleventyFiles.getFileIgnores([\nTemplatePath.join(rootDirectory, \".gitignore\"),\n@@ -474,11 +477,20 @@ class EleventyFiles {\n/* Ignored by `eleventy --watch` */\ngetGlobWatcherIgnores() {\n// convert to format without ! since they are passed in as a separate argument to glob watcher\n- let entries = this.fileIgnores.map((ignore) =>\n+ let entries = new Set(\n+ this.fileIgnores.map((ignore) =>\nTemplatePath.stripLeadingDotSlash(ignore)\n+ )\n+ );\n+\n+ for (let ignore of this.config.watchIgnores) {\n+ entries.add(\n+ TemplateGlob.normalizePath(this.localPathRoot || \".\", ignore)\n);\n+ }\n+\n// de-duplicated\n- return Array.from(new Set(entries));\n+ return Array.from(entries);\n}\n_getIncludesAndDataDirs() {\n" }, { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -68,9 +68,12 @@ class UserConfig {\nthis.dynamicPermalinks = true;\nthis.useGitIgnore = true;\n- this.ignores = new Set();\n- this.ignores.add(\"**/node_modules/**\");\n- this.ignores.add(\".git/**\");\n+\n+ let defaultIgnores = new Set();\n+ defaultIgnores.add(\"**/node_modules/**\");\n+ defaultIgnores.add(\".git/**\");\n+ this.ignores = new Set(defaultIgnores);\n+ this.watchIgnores = new Set(defaultIgnores);\nthis.dataDeepMerge = true;\nthis.extensionMap = new Set();\n@@ -897,6 +900,7 @@ class UserConfig {\ndynamicPermalinks: this.dynamicPermalinks,\nuseGitIgnore: this.useGitIgnore,\nignores: this.ignores,\n+ watchIgnores: this.watchIgnores,\ndataDeepMerge: this.dataDeepMerge,\nwatchJavaScriptDependencies: this.watchJavaScriptDependencies,\nadditionalWatchTargets: this.additionalWatchTargets,\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "new_path": "test/EleventyFilesGitIgnoreEleventyIgnoreTest.js", "diff": "@@ -19,11 +19,14 @@ test(\"Get ignores (no .eleventyignore no .gitignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n- \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore1/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n+ ]);\n});\ntest(\"Get ignores (no .eleventyignore)\", (t) => {\n@@ -38,12 +41,15 @@ test(\"Get ignores (no .eleventyignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalrootgitignore\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n- \"./test/stubs/ignorelocalrootgitignore/.git/**\",\n\"./test/stubs/ignorelocalrootgitignore/thisshouldnotexist12345\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n\"./test/stubs/ignore2/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/.git/**\",\n+ ]);\n});\ntest(\"Get ignores (no .eleventyignore, using setUseGitIgnore(false))\", (t) => {\n@@ -65,10 +71,13 @@ test(\"Get ignores (no .eleventyignore, using setUseGitIgnore(false))\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore2/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-1), [\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n+ ]);\n});\ntest(\"Get ignores (no .gitignore)\", (t) => {\n@@ -83,13 +92,16 @@ test(\"Get ignores (no .gitignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n- \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore3/ignoredFolder/**\",\n\"./test/stubs/ignore3/ignoredFolder/ignored.md\",\n\"./test/stubs/ignore3/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n+ ]);\n});\ntest(\"Get ignores (project .eleventyignore and root .gitignore)\", (t) => {\n@@ -104,14 +116,17 @@ test(\"Get ignores (project .eleventyignore and root .gitignore)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalrootgitignore\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n- \"./test/stubs/ignorelocalrootgitignore/.git/**\",\n\"./test/stubs/ignorelocalrootgitignore/thisshouldnotexist12345\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n\"./test/stubs/ignore4/ignoredFolder/**\",\n\"./test/stubs/ignore4/ignoredFolder/ignored.md\",\n\"./test/stubs/ignore4/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n+ \"./test/stubs/ignorelocalrootgitignore/.git/**\",\n+ ]);\n});\ntest(\"Get ignores (project .eleventyignore and root .gitignore, using setUseGitIgnore(false))\", (t) => {\n@@ -133,12 +148,15 @@ test(\"Get ignores (project .eleventyignore and root .gitignore, using setUseGitI\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalrootgitignore\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n\"./test/stubs/ignorelocalrootgitignore/test.md\",\n\"./test/stubs/ignore4/ignoredFolder/**\",\n\"./test/stubs/ignore4/ignoredFolder/ignored.md\",\n\"./test/stubs/ignore4/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-1), [\n+ \"./test/stubs/ignorelocalrootgitignore/**/node_modules/**\",\n+ ]);\n});\ntest(\"Get ignores (no .eleventyignore .gitignore exists but empty)\", (t) => {\n@@ -154,11 +172,14 @@ test(\"Get ignores (no .eleventyignore .gitignore exists but empty)\", (t) => {\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n- \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore5/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n+ ]);\n});\ntest(\"Get ignores (both .eleventyignore and .gitignore exists, but .gitignore is empty)\", (t) => {\n@@ -173,13 +194,16 @@ test(\"Get ignores (both .eleventyignore and .gitignore exists, but .gitignore is\nevf._setLocalPathRoot(\"./test/stubs/ignorelocalroot\");\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n- \"./test/stubs/ignorelocalroot/.git/**\",\n\"./test/stubs/ignorelocalroot/test.md\",\n\"./test/stubs/ignore6/ignoredFolder/**\",\n\"./test/stubs/ignore6/ignoredFolder/ignored.md\",\n\"./test/stubs/ignore6/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignorelocalroot/**/node_modules/**\",\n+ \"./test/stubs/ignorelocalroot/.git/**\",\n+ ]);\n});\ntest(\"Bad expected output, this indicates a bug upstream in a dependency. Input to 'src' and empty includes dir (issue #403, full paths in eleventyignore)\", async (t) => {\n@@ -324,9 +348,12 @@ test(\"De-duplicated ignores\", (t) => {\n]);\nt.deepEqual(evf.getIgnores(), [\n- \"./test/stubs/ignore-dedupe/**/node_modules/**\",\n- \"./test/stubs/ignore-dedupe/.git/**\",\n\"./test/stubs/ignore-dedupe/ignoredFolder\",\n\"./test/stubs/ignore-dedupe/_site/**\",\n]);\n+\n+ t.deepEqual(evf.getIgnoreGlobs().slice(-2), [\n+ \"./test/stubs/ignore-dedupe/**/node_modules/**\",\n+ \"./test/stubs/ignore-dedupe/.git/**\",\n+ ]);\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Decouple processing ignores from watchIgnores. Fixes #893 Whether we want to ignore a file during watch or ignore a file for processing are two separate concerns.
699
05.12.2022 17:10:10
21,600
3cae34999f9e1d9cf2c77e3ea591829372602440
Extra from
[ { "change_type": "MODIFY", "old_path": "src/Plugins/RenderPlugin.js", "new_path": "src/Plugins/RenderPlugin.js", "diff": "@@ -14,8 +14,6 @@ const EleventyBaseError = require(\"../EleventyBaseError\");\nconst EleventyErrorUtil = require(\"../EleventyErrorUtil\");\nconst Liquid = require(\"../Engines/Liquid\");\n-class EleventyShortcodeError extends EleventyBaseError {}\n-\nasync function compile(\ncontent,\ntemplateLang,\n" } ]
JavaScript
MIT License
11ty/eleventy
Extra from #2577
699
05.12.2022 17:10:48
21,600
350ccccccca4572288a4a99e855967a55dc5e139
One more extra from
[ { "change_type": "MODIFY", "old_path": "src/Plugins/RenderPlugin.js", "new_path": "src/Plugins/RenderPlugin.js", "diff": "@@ -10,7 +10,6 @@ const TemplateDataInitialGlobalData = require(\"../TemplateDataInitialGlobalData\"\nconst EleventyShortcodeError = require(\"../EleventyShortcodeError\");\nconst TemplateRender = require(\"../TemplateRender\");\nconst TemplateConfig = require(\"../TemplateConfig\");\n-const EleventyBaseError = require(\"../EleventyBaseError\");\nconst EleventyErrorUtil = require(\"../EleventyErrorUtil\");\nconst Liquid = require(\"../Engines/Liquid\");\n" } ]
JavaScript
MIT License
11ty/eleventy
One more extra from #2577
699
06.12.2022 09:20:35
21,600
7c935a4bf611a476c1fcb68f16ca8c672621cce4
Adds getCollectionItemIndex universal filter.
[ { "change_type": "ADD", "old_path": null, "new_path": "src/Filters/GetCollectionItemIndex.js", "diff": "+module.exports = function getCollectionItemIndex(collection, page) {\n+ if (!page) {\n+ page = this.page || this.ctx?.page || this.context?.environments?.page;\n+ }\n+\n+ let j = 0;\n+ for (let item of collection) {\n+ if (\n+ item.inputPath === page.inputPath &&\n+ (item.outputPath === page.outputPath || item.url === page.url)\n+ ) {\n+ return j;\n+ }\n+ j++;\n+ }\n+};\n" }, { "change_type": "MODIFY", "old_path": "src/defaultConfig.js", "new_path": "src/defaultConfig.js", "diff": "@@ -3,6 +3,7 @@ const serverlessUrlFilter = require(\"./Filters/ServerlessUrl\");\nconst slugFilter = require(\"./Filters/Slug\");\nconst slugifyFilter = require(\"./Filters/Slugify\");\nconst getLocaleCollectionItem = require(\"./Filters/GetLocaleCollectionItem\");\n+const getCollectionItemIndex = require(\"./Filters/GetCollectionItemIndex\");\nmodule.exports = function (config) {\nlet templateConfig = this;\n@@ -23,6 +24,13 @@ module.exports = function (config) {\nconfig.addFilter(\"serverlessUrl\", serverlessUrlFilter);\n+ config.addFilter(\n+ \"getCollectionItemIndex\",\n+ function (collection, pageOverride) {\n+ return getCollectionItemIndex.call(this, collection, pageOverride);\n+ }\n+ );\n+\nconfig.addFilter(\n\"getCollectionItem\",\nfunction (collection, pageOverride, langCode) {\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/GetCollectionItemIndexTest.js", "diff": "+const test = require(\"ava\");\n+const getCollectionItemIndex = require(\"../src/Filters/GetCollectionItemIndex\");\n+\n+test(\"getCollectionItemIndex\", (t) => {\n+ let first = {\n+ inputPath: \"hello.md\",\n+ outputPath: \"/hello/\",\n+ };\n+ let second = {\n+ inputPath: \"hello2.md\",\n+ outputPath: \"/hello2/\",\n+ };\n+ let third = {\n+ inputPath: \"hello3.md\",\n+ outputPath: \"/hello3/\",\n+ };\n+ let collections = [first, second, third];\n+\n+ t.deepEqual(getCollectionItemIndex(collections, first), 0);\n+ t.deepEqual(getCollectionItemIndex(collections, second), 1);\n+ t.deepEqual(getCollectionItemIndex(collections, third), 2);\n+\n+ t.deepEqual(\n+ getCollectionItemIndex(collections, {\n+ inputPath: \"unknown.md\",\n+ outputPath: \"/unknown/\",\n+ }),\n+ undefined\n+ );\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds getCollectionItemIndex universal filter.
699
06.12.2022 14:34:10
21,600
c1e49b577e7ac63d02b65820d7907f7ed794fde4
Add benchmarks for transforms and linters so they show up in Benchmarking output
[ { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -344,13 +344,19 @@ class UserConfig {\naddTransform(name, callback) {\nname = this.getNamespacedName(name);\n- this.transforms[name] = callback;\n+ this.transforms[name] = this.benchmarks.config.add(\n+ `\"${name}\" Transform`,\n+ callback\n+ );\n}\naddLinter(name, callback) {\nname = this.getNamespacedName(name);\n- this.linters[name] = callback;\n+ this.linters[name] = this.benchmarks.config.add(\n+ `\"${name}\" Linter`,\n+ callback\n+ );\n}\naddLayoutAlias(from, to) {\n" } ]
JavaScript
MIT License
11ty/eleventy
Add benchmarks for transforms and linters so they show up in Benchmarking output
699
06.12.2022 16:10:09
21,600
078b675fa55965d1a5cf4123bb7e34a8d9089005
Normalize to generators
[ { "change_type": "MODIFY", "old_path": "src/Engines/Liquid.js", "new_path": "src/Engines/Liquid.js", "diff": "@@ -93,7 +93,7 @@ class Liquid extends TemplateEngine {\n}\n}\n- static async parseArguments(lexer, str, scope, engine) {\n+ static parseArguments(lexer, str) {\nlet argArray = [];\nif (!lexer) {\n@@ -101,9 +101,8 @@ class Liquid extends TemplateEngine {\n}\nif (typeof str === \"string\") {\n- // TODO key=value key2=value\n- // TODO JSON?\nlexer.reset(str);\n+\nlet arg = lexer.next();\nwhile (arg) {\n/*{\n@@ -119,13 +118,14 @@ class Liquid extends TemplateEngine {\n// Push the promise into an array instead of awaiting it here.\n// This forces the promises to run in order with the correct scope value for each arg.\n// Otherwise they run out of order and can lead to undefined values for arguments in layout template shortcodes.\n- argArray.push(engine.evalValue(arg.value, scope));\n+ // console.log( arg.value, scope, engine );\n+ argArray.push(arg.value);\n}\narg = lexer.next();\n}\n}\n- return await Promise.all(argArray);\n+ return argArray;\n}\nstatic _normalizeShortcodeScope(ctx) {\n@@ -139,26 +139,26 @@ class Liquid extends TemplateEngine {\naddShortcode(shortcodeName, shortcodeFn) {\nlet _t = this;\n- this.addTag(shortcodeName, function () {\n+ this.addTag(shortcodeName, function (liquidEngine) {\nreturn {\n- parse: function (tagToken) {\n+ parse(tagToken) {\nthis.name = tagToken.name;\nthis.args = tagToken.args;\n},\n- render: async function (scope) {\n- let argArray = await Liquid.parseArguments(\n- _t.argLexer,\n- this.args,\n- scope,\n- this.liquid\n- );\n+ render: function* (ctx) {\n+ let rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\n+ let argArray = [];\n+ for (let arg of rawArgs) {\n+ let b = yield liquidEngine.evalValue(arg, ctx);\n+ argArray.push(b);\n+ }\n- return Promise.resolve(\n- shortcodeFn.call(\n- Liquid._normalizeShortcodeScope(scope),\n+ let ret = shortcodeFn.call(\n+ Liquid._normalizeShortcodeScope(ctx),\n...argArray\n- )\n);\n+ yield ret;\n+ return ret;\n},\n};\n});\n@@ -168,7 +168,7 @@ class Liquid extends TemplateEngine {\nlet _t = this;\nthis.addTag(shortcodeName, function (liquidEngine) {\nreturn {\n- parse: function (tagToken, remainTokens) {\n+ parse(tagToken, remainTokens) {\nthis.name = tagToken.name;\nthis.args = tagToken.args;\nthis.templates = [];\n@@ -184,21 +184,25 @@ class Liquid extends TemplateEngine {\nstream.start();\n},\nrender: function* (ctx) {\n- let argArray = yield Liquid.parseArguments(\n- _t.argLexer,\n- this.args,\n- ctx,\n- this.liquid\n- );\n- const html = yield this.liquid.renderer.renderTemplates(\n+ let rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\n+ let argArray = [];\n+ for (let arg of rawArgs) {\n+ let b = yield liquidEngine.evalValue(arg, ctx);\n+ argArray.push(b);\n+ }\n+\n+ const html = yield liquidEngine.renderer.renderTemplates(\nthis.templates,\nctx\n);\n- return shortcodeFn.call(\n+\n+ let ret = shortcodeFn.call(\nLiquid._normalizeShortcodeScope(ctx),\nhtml,\n...argArray\n);\n+ yield ret;\n+ return ret;\n},\n};\n});\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/RenderPlugin.js", "new_path": "src/Plugins/RenderPlugin.js", "diff": "@@ -151,7 +151,7 @@ function EleventyPlugin(eleventyConfig, options = {}) {\nstream.start();\n},\n- render: async function (ctx) {\n+ render: function* (ctx) {\nlet normalizedContext = {};\nif (ctx) {\nif (opts.accessGlobalData) {\n@@ -163,21 +163,24 @@ function EleventyPlugin(eleventyConfig, options = {}) {\nnormalizedContext.eleventy = ctx.get([\"eleventy\"]);\n}\n- let argArray = await Liquid.parseArguments(\n- null,\n- this.args,\n- ctx,\n- this.liquid\n- );\n+ let rawArgs = Liquid.parseArguments(null, this.args);\n+ let argArray = [];\n+ for (let arg of rawArgs) {\n+ let b = yield liquidEngine.evalValue(arg, ctx);\n+ argArray.push(b);\n+ }\n+ // plaintext paired shortcode content\nlet body = this.tokens.map((token) => token.getText()).join(\"\");\n- return _renderStringShortcodeFn.call(\n+ let ret = _renderStringShortcodeFn.call(\nnormalizedContext,\nbody,\n// templateLang, data\n...argArray\n);\n+ yield ret;\n+ return ret;\n},\n};\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Normalize to generators
699
06.12.2022 16:55:06
21,600
a40c631327e9e67ae8572650e655438bda500049
Fix regressions for liquidjs@10 upgrade Mostly the second arg to evalValue.
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"is-glob\": \"^4.0.3\",\n\"iso-639-1\": \"^2.1.15\",\n\"kleur\": \"^4.1.5\",\n- \"liquidjs\": \"9.41.0\",\n+ \"liquidjs\": \"^10.2.0\",\n\"lodash\": \"^4.17.21\",\n\"luxon\": \"^3.1.0\",\n\"markdown-it\": \"^13.0.1\",\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/Liquid.js", "new_path": "src/Engines/Liquid.js", "diff": "@@ -145,19 +145,19 @@ class Liquid extends TemplateEngine {\nthis.name = tagToken.name;\nthis.args = tagToken.args;\n},\n- render: function* (ctx) {\n+ render: function* (ctx, emitter) {\nlet rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\nlet argArray = [];\nfor (let arg of rawArgs) {\n- let b = yield liquidEngine.evalValue(arg, ctx);\n+ let b = yield liquidEngine.evalValue(arg, ctx.environments);\nargArray.push(b);\n}\n- let ret = shortcodeFn.call(\n+ let ret = yield shortcodeFn.call(\nLiquid._normalizeShortcodeScope(ctx),\n...argArray\n);\n- yield ret;\n+ // emitter.write(ret);\nreturn ret;\n},\n};\n@@ -183,11 +183,11 @@ class Liquid extends TemplateEngine {\nstream.start();\n},\n- render: function* (ctx) {\n+ render: function* (ctx, emitter) {\nlet rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\nlet argArray = [];\nfor (let arg of rawArgs) {\n- let b = yield liquidEngine.evalValue(arg, ctx);\n+ let b = yield liquidEngine.evalValue(arg, ctx.environments);\nargArray.push(b);\n}\n@@ -196,12 +196,12 @@ class Liquid extends TemplateEngine {\nctx\n);\n- let ret = shortcodeFn.call(\n+ let ret = yield shortcodeFn.call(\nLiquid._normalizeShortcodeScope(ctx),\nhtml,\n...argArray\n);\n- yield ret;\n+ // emitter.write(ret);\nreturn ret;\n},\n};\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/RenderPlugin.js", "new_path": "src/Plugins/RenderPlugin.js", "diff": "@@ -166,7 +166,7 @@ function EleventyPlugin(eleventyConfig, options = {}) {\nlet rawArgs = Liquid.parseArguments(null, this.args);\nlet argArray = [];\nfor (let arg of rawArgs) {\n- let b = yield liquidEngine.evalValue(arg, ctx);\n+ let b = yield liquidEngine.evalValue(arg, ctx.environments);\nargArray.push(b);\n}\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateRenderLiquidTest.js", "new_path": "test/TemplateRenderLiquidTest.js", "diff": "@@ -230,8 +230,8 @@ test(\"Liquid Custom Tag prefixWithZach\", async (t) => {\nparse: function (tagToken, remainTokens) {\nthis.str = tagToken.args; // name\n},\n- render: function (scope, hash) {\n- var str = liquidEngine.evalValueSync(this.str, scope); // 'alice'\n+ render: function (ctx, hash) {\n+ var str = liquidEngine.evalValueSync(this.str, ctx.environments); // 'alice'\nreturn Promise.resolve(\"Zach\" + str); // 'Alice'\n},\n};\n@@ -250,8 +250,8 @@ test(\"Liquid Custom Tag postfixWithZach\", async (t) => {\nparse: function (tagToken, remainTokens) {\nthis.str = tagToken.args;\n},\n- render: async function (scope, hash) {\n- var str = await liquidEngine.evalValue(this.str, scope);\n+ render: async function (ctx, hash) {\n+ var str = await liquidEngine.evalValue(this.str, ctx.environments);\nreturn Promise.resolve(str + \"Zach\");\n},\n};\n@@ -300,8 +300,8 @@ test(\"Liquid addTags\", async (t) => {\nparse: function (tagToken, remainTokens) {\nthis.str = tagToken.args;\n},\n- render: async function (scope, hash) {\n- var str = await liquidEngine.evalValue(this.str, scope);\n+ render: async function (ctx, hash) {\n+ var str = await liquidEngine.evalValue(this.str, ctx.environments);\nreturn Promise.resolve(str + \"Zach\");\n},\n};\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix regressions for liquidjs@10 upgrade https://github.com/harttle/liquidjs/releases/tag/v10.0.0 Mostly the second arg to evalValue.
699
07.12.2022 09:25:53
21,600
ee4a55845979a971ebe099f2511bad55af1ffeab
Error message cleanup for
[ { "change_type": "MODIFY", "old_path": "src/TemplateData.js", "new_path": "src/TemplateData.js", "diff": "@@ -364,10 +364,10 @@ class TemplateData {\n} else {\n// clean up data for template/directory data files only.\nlet cleanedDataForPath = TemplateData.cleanupData(dataForPath);\n- for (const key in cleanedDataForPath) {\n+ for (let key in cleanedDataForPath) {\nif (dataSource.hasOwnProperty(key)) {\ndebugWarn(\n- \"overwriting '%s' with data from '%s'. Previous data location was %s\",\n+ \"Local data files have conflicting data. Overwriting '%s' with data from '%s'. Previous data location was from '%s'\",\nkey,\npath,\ndataSource[key]\n" } ]
JavaScript
MIT License
11ty/eleventy
Error message cleanup for #1462
699
07.12.2022 09:46:44
21,600
f59d1752825fcdbb2aefe65a344cf0de4ad4604e
Need to use promises fs API for
[ { "change_type": "MODIFY", "old_path": "src/Engines/TemplateEngine.js", "new_path": "src/Engines/TemplateEngine.js", "diff": "@@ -121,20 +121,23 @@ class TemplateEngine {\nif (this.includesDir) {\nlet bench = this.benchmarks.aggregate.get(\"Searching the file system\");\nbench.before();\n- await Promise.all(this.extensions.map(async function (extension) {\n+ await Promise.all(\n+ this.extensions.map(async function (extension) {\npartialFiles = partialFiles.concat(\nawait fastglob(prefix + extension, {\ncaseSensitiveMatch: false,\ndot: true,\n})\n);\n- }));\n+ })\n+ );\nbench.after();\n}\npartialFiles = TemplatePath.addLeadingDotSlashArray(partialFiles);\n- await Promise.all(partialFiles.map(async (partialFile) => {\n+ await Promise.all(\n+ partialFiles.map(async (partialFile) => {\nlet partialPath = TemplatePath.stripLeadingSubPath(\npartialFile,\nthis.includesDir\n@@ -147,8 +150,11 @@ class TemplateEngine {\n);\n});\n- partials[partialPathNoExt] = await fs.readFile(partialFile, \"utf8\");\n- }));\n+ partials[partialPathNoExt] = await fs.promises.readFile(partialFile, {\n+ encoding: \"utf8\",\n+ });\n+ })\n+ );\ndebug(\n`${this.includesDir}/*.{${this.extensions}} found partials for: %o`,\n@@ -223,7 +229,7 @@ class TemplateEngine {\n* @return {Promise}\n*/\nasync compile() {\n- throw new Error('compile() must be implemented by engine');\n+ throw new Error(\"compile() must be implemented by engine\");\n}\n// See https://www.11ty.dev/docs/watch-serve/#watch-javascript-dependencies\n" } ]
JavaScript
MIT License
11ty/eleventy
Need to use promises fs API for #1537
699
07.12.2022 10:11:05
21,600
3265c0ab4e9955b12804270fb6ad1f901d05b3d0
A bit more cleanup for
[ { "change_type": "MODIFY", "old_path": "src/Engines/TemplateEngine.js", "new_path": "src/Engines/TemplateEngine.js", "diff": "@@ -105,22 +105,23 @@ class TemplateEngine {\n/**\n* Search for and cache partial files.\n*\n- * This only runs if getPartials() is called, which is only for Mustache/Handlebars.\n+ * This only runs if getPartials() is called, which only runs if you compile a Mustache/Handlebars template.\n*\n* @protected\n*/\nasync cachePartialFiles() {\n+ this.partialsHaveBeenCached = true;\n+\n+ let results = [];\n+ if (this.includesDir) {\n// Try to skip this require if not used (for bundling reasons)\nconst fastglob = require(\"fast-glob\");\n- this.partialsHaveBeenCached = true;\n- let partials = {};\n- let prefix = this.includesDir + \"/**/*.\";\n- // TODO: reuse mustache partials in handlebars?\n- let partialFiles = [];\n- if (this.includesDir) {\nlet bench = this.benchmarks.aggregate.get(\"Searching the file system\");\nbench.before();\n+\n+ let prefix = this.includesDir + \"/**/*.\";\n+ let partialFiles = [];\nawait Promise.all(\nthis.extensions.map(async function (extension) {\npartialFiles = partialFiles.concat(\n@@ -131,13 +132,12 @@ class TemplateEngine {\n);\n})\n);\n- bench.after();\n- }\n- partialFiles = TemplatePath.addLeadingDotSlashArray(partialFiles);\n+ bench.after();\n- await Promise.all(\n- partialFiles.map(async (partialFile) => {\n+ results = await Promise.all(\n+ partialFiles.map((partialFile) => {\n+ partialFile = TemplatePath.addLeadingDotSlash(partialFile);\nlet partialPath = TemplatePath.stripLeadingSubPath(\npartialFile,\nthis.includesDir\n@@ -150,11 +150,24 @@ class TemplateEngine {\n);\n});\n- partials[partialPathNoExt] = await fs.promises.readFile(partialFile, {\n+ return fs.promises\n+ .readFile(partialFile, {\nencoding: \"utf8\",\n+ })\n+ .then((content) => {\n+ return {\n+ content,\n+ path: partialPathNoExt,\n+ };\n});\n})\n);\n+ }\n+\n+ let partials = {};\n+ for (let result of results) {\n+ partials[result.path] = result.content;\n+ }\ndebug(\n`${this.includesDir}/*.{${this.extensions}} found partials for: %o`,\n" } ]
JavaScript
MIT License
11ty/eleventy
A bit more cleanup for #1537
699
07.12.2022 12:50:21
21,600
d0ab03811e87735ac3d79f03bdbff493358f13df
Refactor for `dataFileSuffixes` and `dataFileDirBaseNameOverride` config options
[ { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -192,7 +192,7 @@ class TemplateConfig {\n* @param {String} pathPrefix - The new path prefix.\n*/\nsetPathPrefix(pathPrefix) {\n- if(pathPrefix && pathPrefix !== '/'){\n+ if (pathPrefix && pathPrefix !== \"/\") {\ndebug(\"Setting pathPrefix to %o\", pathPrefix);\nthis.overrides.pathPrefix = pathPrefix;\n}\n@@ -227,6 +227,11 @@ class TemplateConfig {\ndebug(\"rootConfig %o\", this.rootConfig);\n}\n+ /* Add additional overrides to the root config object, used for testing */\n+ appendToRootConfig(obj) {\n+ Object.assign(this.rootConfig, obj);\n+ }\n+\n/*\n* Process the userland plugins from the Config\n*\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateDataTest.js", "new_path": "test/TemplateDataTest.js", "diff": "@@ -291,6 +291,31 @@ test(\"getLocalDataPaths\", async (t) => {\n]);\n});\n+test(\"getLocalDataPaths (with dataFileDirBaseNameOverride #1699)\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ eleventyConfig.appendToRootConfig({\n+ dataFileDirBaseNameOverride: \"index\",\n+ });\n+\n+ let dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\n+ let paths = await dataObj.getLocalDataPaths(\n+ \"./test/stubs/component/component.liquid\"\n+ );\n+\n+ t.deepEqual(paths, [\n+ \"./test/stubs/index.11tydata.json\",\n+ \"./test/stubs/index.11tydata.cjs\",\n+ \"./test/stubs/index.11tydata.js\",\n+ \"./test/stubs/component/index.11tydata.json\",\n+ \"./test/stubs/component/index.11tydata.cjs\",\n+ \"./test/stubs/component/index.11tydata.js\",\n+ \"./test/stubs/component/component.json\",\n+ \"./test/stubs/component/component.11tydata.json\",\n+ \"./test/stubs/component/component.11tydata.cjs\",\n+ \"./test/stubs/component/component.11tydata.js\",\n+ ]);\n+});\n+\ntest(\"Deeper getLocalDataPaths\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\nlet dataObj = new TemplateData(\"./\", eleventyConfig);\n" } ]
JavaScript
MIT License
11ty/eleventy
Refactor for `dataFileSuffixes` and `dataFileDirBaseNameOverride` config options #1699
699
07.12.2022 14:45:20
21,600
c7fa19ebe1baab867eccf76f47977515dfac2914
Consistency for
[ { "change_type": "MODIFY", "old_path": "src/TemplateData.js", "new_path": "src/TemplateData.js", "diff": "@@ -496,7 +496,9 @@ class TemplateData {\nif (readFile) {\nreturn parser(rawInput, path);\n} else {\n- return parser(path);\n+ // path as a first argument is when `read: false`\n+ // path as a second argument is for consistency with `read: true` API\n+ return parser(path, path);\n}\n} catch (e) {\nthrow new TemplateDataParseError(\n" } ]
JavaScript
MIT License
11ty/eleventy
Consistency for #2188
699
07.12.2022 15:13:58
21,600
7c03471742d650d79e60343bea07c9dfb8ecff1f
No longer throws an error with empty .json data files.
[ { "change_type": "MODIFY", "old_path": ".editorconfig", "new_path": ".editorconfig", "diff": "@@ -13,3 +13,4 @@ insert_final_newline = true\n[/test/stubs*/**]\ninsert_final_newline = unset\n+trim_trailing_whitespace = false\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateDataTest.js", "new_path": "test/TemplateDataTest.js", "diff": "@@ -573,3 +573,14 @@ test(\"eleventy.version and eleventy.generator returned from data\", async (t) =>\nt.is(data.deep.nested.one, \"first\");\nt.is(data.deep.nested.two, \"second\");\n});\n+\n+test(\"getData() empty json file\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ let dataObj = new TemplateData(\n+ \"./test/stubs-empty-json-data/\",\n+ eleventyConfig\n+ );\n+\n+ let data = await dataObj.getData();\n+ t.deepEqual(data.empty, {});\n+});\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-empty-json-data/_data/empty.json", "diff": "+\n+\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
No longer throws an error with empty .json data files.
699
07.12.2022 15:35:07
21,600
db13fb907e198e31ee8166756a1842a879e2f865
Adds Array argument support to `addExtension` For example: eleventyConfig.addExtension([ "11ty.jsx", "11ty.ts", "11ty.tsx" ], { key: "11ty.js" });
[ { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -817,16 +817,27 @@ class UserConfig {\n}\naddExtension(fileExtension, options = {}) {\n+ let extensions;\n+ // Array support added in 2.0.0-canary.19\n+ if (Array.isArray(fileExtension)) {\n+ extensions = fileExtension;\n+ } else {\n+ // single string\n+ extensions = [fileExtension];\n+ }\n+\n+ for (let extension of extensions) {\nthis.extensionMap.add(\nObject.assign(\n{\n- key: fileExtension,\n- extension: fileExtension,\n+ key: extension,\n+ extension: extension,\n},\noptions\n)\n);\n}\n+ }\naddDataExtension(extensionList, parser) {\nlet options = {};\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds Array argument support to `addExtension` #2279 For example: eleventyConfig.addExtension([ "11ty.jsx", "11ty.ts", "11ty.tsx" ], { key: "11ty.js" });
699
07.12.2022 15:37:41
21,600
56b7443ba95c44ea3b91393c391566eb8f711f31
Easier searching
[ { "change_type": "MODIFY", "old_path": "test/TemplateRenderCustomTest.js", "new_path": "test/TemplateRenderCustomTest.js", "diff": "@@ -19,6 +19,7 @@ function getNewTemplateRender(name, inputDir, eleventyConfig) {\ntest(\"Custom plaintext Render\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n+ // addExtension() API\neleventyConfig.userConfig.extensionMap.add({\nextension: \"txt\",\nkey: \"txt\",\n@@ -40,6 +41,7 @@ test(\"Custom plaintext Render\", async (t) => {\ntest(\"Custom Markdown Render with `compile` override\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n+ // addExtension() API\neleventyConfig.userConfig.extensionMap.add({\nextension: \"md\",\nkey: \"md\",\n@@ -61,6 +63,7 @@ test(\"Custom Markdown Render without `compile` override\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\nlet initCalled = false;\n+ // addExtension() API\neleventyConfig.userConfig.extensionMap.add({\nextension: \"md\",\nkey: \"md\",\n@@ -80,6 +83,7 @@ test(\"Custom Markdown Render without `compile` override\", async (t) => {\ntest(\"Custom Markdown Render with `compile` override + call to default compiler\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n+ // addExtension() API\neleventyConfig.userConfig.extensionMap.add({\nextension: \"md\",\nkey: \"md\",\n@@ -104,6 +108,7 @@ test(\"Custom Markdown Render with `compile` override + call to default compiler\"\ntest(\"Custom Vue Render\", async (t) => {\nlet tr = getNewTemplateRender(\"vue\");\n+ // addExtension() API\ntr.eleventyConfig.userConfig.extensionMap.add({\nextension: \"vue\",\nkey: \"vue\",\n@@ -129,6 +134,8 @@ const sass = require(\"sass\");\ntest(\"Custom Sass Render\", async (t) => {\nlet tr = getNewTemplateRender(\"sass\");\n+\n+ // addExtension() API\ntr.eleventyConfig.userConfig.extensionMap.add({\nextension: \"sass\",\nkey: \"sass\",\n@@ -186,6 +193,7 @@ test(\"JavaScript functions should not be mutable but not *that* mutable\", async\n},\n};\n+ // addExtension() API\neleventyConfig.userConfig.extensionMap.add({\nextension: \"js1\",\nkey: \"js1\",\n@@ -218,6 +226,8 @@ test(\"JavaScript functions should not be mutable but not *that* mutable\", async\ntest(\"Return undefined in compile to ignore #2267\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n+\n+ // addExtension() API\neleventyConfig.userConfig.extensionMap.add({\nextension: \"txt\",\nkey: \"txt\",\n" } ]
JavaScript
MIT License
11ty/eleventy
Easier searching
699
07.12.2022 16:37:06
21,600
a9b1c6096aedf5397b6c92a5ed6099d9cb1c8b54
Fix for issue that needed explicit `read: false` for aliases to `11ty.js` (no longer required)
[ { "change_type": "MODIFY", "old_path": "src/EleventyFiles.js", "new_path": "src/EleventyFiles.js", "diff": "@@ -388,21 +388,7 @@ class EleventyFiles {\nlet paths = TemplatePath.addLeadingDotSlashArray(globResults);\nbench.after();\n- // filter individual paths in the new config-specified extension\n- // where is this used?\n- if (\"extensionMap\" in this.config) {\n- let extensions = this.config.extensionMap;\n- if (Array.from(extensions).filter((entry) => !!entry.filter).length) {\n- paths = paths.filter(function (path) {\n- for (let entry of extensions) {\n- if (entry.filter && path.endsWith(`.${entry.extension}`)) {\n- return entry.filter(path);\n- }\n- }\n- return true;\n- });\n- }\n- }\n+ // Note 2.0.0-canary.19 removed a `filter` option for custom template syntax here that was unpublished and unused.\nthis.pathCache = paths;\nreturn paths;\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/Custom.js", "new_path": "src/Engines/Custom.js", "diff": "@@ -21,6 +21,7 @@ class CustomEngine extends TemplateEngine {\ngetExtensionMapEntry() {\nif (\"extensionMap\" in this.config) {\n+ // Iterates over only the user config `addExtension` entries\nfor (let entry of this.config.extensionMap) {\nif (entry.key.toLowerCase() === this.name.toLowerCase()) {\nreturn entry;\n@@ -44,6 +45,14 @@ class CustomEngine extends TemplateEngine {\nif (\"read\" in this.entry) {\nreturn this.entry.read;\n}\n+\n+ // Handle aliases to `11ty.js` templates, avoid reading files in the alias, see #2279\n+ // Here, we are short circuiting fallback to defaultRenderer, does not account for compile\n+ // functions that call defaultRenderer explicitly\n+ if (!this.entry.compile && this._defaultEngine) {\n+ return this._defaultEngine.needsToReadFileContents();\n+ }\n+\nreturn true;\n}\n@@ -144,7 +153,6 @@ class CustomEngine extends TemplateEngine {\nasync compile(str, inputPath, ...args) {\nawait this._runningInit();\n-\nlet defaultRenderer;\nif (this._defaultEngine) {\ndefaultRenderer = async (data) => {\n@@ -159,6 +167,7 @@ class CustomEngine extends TemplateEngine {\n// Fall back to default compiler if the user does not provide their own\nif (!this.entry.compile && defaultRenderer) {\n+ // If the defaultRenderer is used here, needsToReadFileContents is also aliased to the upstream engine too in needsToReadFileContents(), #2279\nreturn defaultRenderer;\n}\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateEngineManager.js", "new_path": "src/TemplateEngineManager.js", "diff": "@@ -93,7 +93,7 @@ class TemplateEngineManager {\ninstance.extensionMap = extensionMap;\ninstance.engineManager = this;\n- // If the user providers a \"Custom\" engine using addExtension,\n+ // If the user provides a \"Custom\" engine using addExtension,\n// But that engine's instance is *not* custom,\n// The user must be overriding an existing engine\n// i.e. addExtension('md', { ...overrideBehavior })\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix for #2279 issue that needed explicit `read: false` for aliases to `11ty.js` (no longer required)
699
08.12.2022 09:12:05
21,600
f4cc4bc7e93efaab3d787e21c9b4af61b1e82a2a
Fix access to scope in Liquid arguments
[ { "change_type": "MODIFY", "old_path": "src/Engines/Liquid.js", "new_path": "src/Engines/Liquid.js", "diff": "@@ -148,8 +148,9 @@ class Liquid extends TemplateEngine {\nrender: function* (ctx, emitter) {\nlet rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\nlet argArray = [];\n+ let contextScope = ctx.getAll();\nfor (let arg of rawArgs) {\n- let b = yield liquidEngine.evalValue(arg, ctx.environments);\n+ let b = yield liquidEngine.evalValue(arg, contextScope);\nargArray.push(b);\n}\n@@ -186,8 +187,9 @@ class Liquid extends TemplateEngine {\nrender: function* (ctx, emitter) {\nlet rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\nlet argArray = [];\n+ let contextScope = ctx.getAll();\nfor (let arg of rawArgs) {\n- let b = yield liquidEngine.evalValue(arg, ctx.environments);\n+ let b = yield liquidEngine.evalValue(arg, contextScope);\nargArray.push(b);\n}\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/RenderPlugin.js", "new_path": "src/Plugins/RenderPlugin.js", "diff": "@@ -155,7 +155,7 @@ function EleventyPlugin(eleventyConfig, options = {}) {\nlet normalizedContext = {};\nif (ctx) {\nif (opts.accessGlobalData) {\n- // parent template data cascade\n+ // parent template data cascade, should this be `ctx.getAll()` (per below?)\nnormalizedContext.data = ctx.environments;\n}\n@@ -165,8 +165,9 @@ function EleventyPlugin(eleventyConfig, options = {}) {\nlet rawArgs = Liquid.parseArguments(null, this.args);\nlet argArray = [];\n+ let contextScope = ctx.getAll();\nfor (let arg of rawArgs) {\n- let b = yield liquidEngine.evalValue(arg, ctx.environments);\n+ let b = yield liquidEngine.evalValue(arg, contextScope);\nargArray.push(b);\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Fix access to scope in Liquid arguments #2678
699
08.12.2022 15:37:05
21,600
6a67b99381a5cf4199a03634fce6113225f80041
Adds skipped test case for
[ { "change_type": "MODIFY", "old_path": "test/MergeTest.js", "new_path": "test/MergeTest.js", "diff": "@@ -194,6 +194,34 @@ test(\"Edge case from #2470\", (t) => {\n);\n});\n+test.skip(\"Edge case from #2684 (multiple conflicting override: props)\", (t) => {\n+ t.deepEqual(\n+ Merge(\n+ {\n+ a: {\n+ \"override:b\": {\n+ c: [1],\n+ },\n+ },\n+ },\n+ {\n+ a: {\n+ \"override:b\": {\n+ c: [2],\n+ },\n+ },\n+ }\n+ ),\n+ {\n+ a: {\n+ b: {\n+ c: [2],\n+ },\n+ },\n+ }\n+ );\n+});\n+\ntest(\"Deep, override: empty\", (t) => {\nt.deepEqual(Merge({}, { a: { b: [3, 4] } }), { a: { b: [3, 4] } });\nt.deepEqual(Merge({}, { a: [2] }), { a: [2] });\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds skipped test case for #2684
699
08.12.2022 16:05:35
21,600
3de539631c78a23e27e3b0c9fef743efa9f8bbed
Did a bad merge, fixing
[ { "change_type": "MODIFY", "old_path": "src/EleventyFiles.js", "new_path": "src/EleventyFiles.js", "diff": "@@ -205,7 +205,7 @@ class EleventyFiles {\nfor (let ignore of this.extraIgnores) {\nuniqueIgnores.add(ignore);\n}\n- // Placing the config ignores last here is import to the tests\n+ // Placing the config ignores last here is important to the tests\nfor (let ignore of this.config.ignores) {\nuniqueIgnores.add(\nTemplateGlob.normalizePath(this.localPathRoot || \".\", ignore)\n@@ -291,13 +291,8 @@ class EleventyFiles {\n}\ngetIgnores() {\n- let rootDirectory = this.localPathRoot || \".\";\nlet files = new Set();\n- for (let ignore of this.config.ignores) {\n- files.add(TemplateGlob.normalizePath(rootDirectory, ignore));\n- }\n-\nfor (let ignore of EleventyFiles.getFileIgnores(this.getIgnoreFiles())) {\nfiles.add(ignore);\n}\n" } ]
JavaScript
MIT License
11ty/eleventy
Did a bad merge, fixing #2480
699
09.12.2022 20:39:43
21,600
19620100ecfa3d7fdeaa5f08e2c55d5146bf9e6d
A bunch of code to make better. Adds `addDependencies` API to declare dependencies for both cache key usage and incremental matching.
[ { "change_type": "MODIFY", "old_path": "src/Engines/Custom.js", "new_path": "src/Engines/Custom.js", "diff": "const TemplateEngine = require(\"./TemplateEngine\");\nconst getJavaScriptData = require(\"../Util/GetJavaScriptData\");\n+const GlobalDependencyMap = require(\"../GlobalDependencyMap\");\n+const eventBus = require(\"../EventBus.js\");\n+\n+let usesMap = new GlobalDependencyMap();\n+\n+let lastModifiedFile = undefined;\n+eventBus.on(\"eleventy.resourceModified\", (path) => {\n+ lastModifiedFile = path;\n+});\nclass CustomEngine extends TemplateEngine {\nconstructor(name, dirs, config) {\n@@ -188,6 +197,9 @@ class CustomEngine extends TemplateEngine {\n// TODO generalize this (look at JavaScript.js)\nlet fn = this.entry.compile.bind({\nconfig: this.config,\n+ addDependencies: (from, toArray = []) => {\n+ usesMap.addDependency(from, toArray);\n+ },\ndefaultRenderer, // bind defaultRenderer to compile function\n})(str, inputPath);\n@@ -214,7 +226,22 @@ class CustomEngine extends TemplateEngine {\nreturn this.entry.outputFileExtension;\n}\n+ hasDependencies(inputPath) {\n+ if (usesMap.getDependencies(inputPath) === false) {\n+ return false;\n+ }\n+ return true;\n+ }\n+\n+ isFileRelevantTo(inputPath, comparisonFile) {\n+ return usesMap.isFileRelevantTo(inputPath, comparisonFile);\n+ }\n+\ngetCompileCacheKey(str, inputPath) {\n+ // Return this separately so we know whether or not to use the cached version\n+ // but still return a key to cache this new render for next time\n+ let useCache = !this.isFileRelevantTo(inputPath, lastModifiedFile);\n+\nif (\nthis.entry.compileOptions &&\n\"getCacheKey\" in this.entry.compileOptions\n@@ -225,9 +252,17 @@ class CustomEngine extends TemplateEngine {\n);\n}\n- return this.entry.compileOptions.getCacheKey(str, inputPath);\n+ return {\n+ useCache,\n+ key: this.entry.compileOptions.getCacheKey(str, inputPath),\n+ };\n}\n- return super.getCompileCacheKey(str, inputPath);\n+\n+ let { key } = super.getCompileCacheKey(str, inputPath);\n+ return {\n+ useCache,\n+ key,\n+ };\n}\npermalinkNeedsCompilation(str) {\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/TemplateEngine.js", "new_path": "src/Engines/TemplateEngine.js", "diff": "@@ -218,9 +218,15 @@ class TemplateEngine {\n}\ngetCompileCacheKey(str, inputPath) {\n- // Changing to use inputPath and contents, this created weird bugs when two identical files had different file paths\n- // TODO update docs\n- return inputPath + str;\n+ // Changing to use inputPath and contents, using only file contents (`str`) caused issues when two\n+ // different files had identical content (2.0.0-canary.16)\n+\n+ // Caches are now segmented based on inputPath so using inputPath here is superfluous (2.0.0-canary.19)\n+ // We do want a non-falsy value here even if `str` is an empty string.\n+ return {\n+ useCache: true,\n+ key: inputPath + str,\n+ };\n}\nget defaultTemplateFileExtension() {\n@@ -249,6 +255,15 @@ class TemplateEngine {\nstatic shouldSpiderJavaScriptDependencies() {\nreturn false;\n}\n+\n+ // always relevant\n+ isFileRelevantTo() {\n+ return true;\n+ }\n+\n+ hasDependencies() {\n+ return false;\n+ }\n}\nmodule.exports = TemplateEngine;\n" }, { "change_type": "ADD", "old_path": null, "new_path": "src/GlobalDependencyMap.js", "diff": "+const { DepGraph } = require(\"dependency-graph\");\n+const { TemplatePath } = require(\"@11ty/eleventy-utils\");\n+\n+const eventBus = require(\"./EventBus.js\");\n+\n+// TODO extend this to built-in template types, this is only used by Custom templates for now\n+\n+class GlobalDependencyMap {\n+ constructor() {\n+ eventBus.on(\"eleventy.compileCacheReset\", () => {\n+ this._map = undefined;\n+ });\n+ }\n+\n+ get map() {\n+ if (!this._map) {\n+ this._map = new DepGraph({ circular: true });\n+ }\n+\n+ return this._map;\n+ }\n+\n+ normalizeNode(node) {\n+ return TemplatePath.stripLeadingDotSlash(node);\n+ }\n+\n+ delete(node) {\n+ node = this.normalizeNode(node);\n+\n+ if (this.map.hasNode(node)) {\n+ this.map.removeNode(node);\n+ }\n+ }\n+\n+ getDependencies(node) {\n+ node = this.normalizeNode(node);\n+\n+ if (!this.map.hasNode(node)) {\n+ return false;\n+ }\n+\n+ return this.map.dependenciesOf(node);\n+ }\n+\n+ addDependency(from, toArray = []) {\n+ from = this.normalizeNode(from);\n+\n+ // reset any existing for this node\n+ this.delete(from);\n+\n+ this.map.addNode(from);\n+\n+ for (let to of toArray) {\n+ to = this.normalizeNode(to);\n+\n+ if (!this.map.hasNode(to)) {\n+ this.map.addNode(to);\n+ }\n+\n+ this.map.addDependency(from, to);\n+ }\n+ }\n+\n+ hasDependency(from, to) {\n+ to = this.normalizeNode(to);\n+\n+ let deps = this.getDependencies(from); // normalizes `from`\n+\n+ if (!deps) {\n+ return false;\n+ }\n+\n+ return deps.includes(to);\n+ }\n+\n+ isFileRelevantTo(fullTemplateInputPath, comparisonFile) {\n+ fullTemplateInputPath = this.normalizeNode(fullTemplateInputPath);\n+ comparisonFile = this.normalizeNode(comparisonFile);\n+\n+ // No watch/serve changed file\n+ if (!comparisonFile) {\n+ return false;\n+ }\n+ // The file that changed is the relevant file\n+ if (fullTemplateInputPath === comparisonFile) {\n+ return true;\n+ }\n+ // The file that changed is a dependency of the template\n+ if (this.hasDependency(fullTemplateInputPath, comparisonFile)) {\n+ return true;\n+ }\n+ return false;\n+ }\n+}\n+\n+module.exports = GlobalDependencyMap;\n" }, { "change_type": "MODIFY", "old_path": "test/DependencyGraphTest.js", "new_path": "test/DependencyGraphTest.js", "diff": "@@ -44,3 +44,23 @@ test(\"Dependency graph assumptions\", async (t) => {\n\"userCollection\",\n]);\n});\n+\n+test(\"Do dependencies get removed when nodes are deleted?\", async (t) => {\n+ const DependencyGraph = require(\"dependency-graph\").DepGraph;\n+ let graph = new DependencyGraph();\n+\n+ graph.addNode(\"template-a\");\n+ graph.addNode(\"template-b\");\n+ graph.addDependency(\"template-a\", \"template-b\");\n+ t.deepEqual(graph.overallOrder(), [\"template-b\", \"template-a\"]);\n+\n+ t.deepEqual(graph.dependenciesOf(\"template-a\"), [\"template-b\"]);\n+\n+ graph.removeNode(\"template-b\");\n+ t.deepEqual(graph.dependenciesOf(\"template-a\"), []);\n+\n+ graph.addNode(\"template-b\");\n+ t.deepEqual(graph.dependenciesOf(\"template-a\"), []);\n+\n+ t.deepEqual(graph.overallOrder(), [\"template-a\", \"template-b\"]);\n+});\n" } ]
JavaScript
MIT License
11ty/eleventy
A bunch of code to make #2258 better. Adds `addDependencies` API to declare dependencies for both cache key usage and incremental matching.
699
12.12.2022 12:17:04
21,600
15b8f32435c7a7919bba3a43a425f91c4c365dc0
Wrong test file content
[ { "change_type": "MODIFY", "old_path": "src/Engines/TemplateEngine.js", "new_path": "src/Engines/TemplateEngine.js", "diff": "@@ -222,7 +222,7 @@ class TemplateEngine {\n// different files had identical content (2.0.0-canary.16)\n// Caches are now segmented based on inputPath so using inputPath here is superfluous (2.0.0-canary.19)\n- // We do want a non-falsy value here even if `str` is an empty string.\n+ // But we do want a non-falsy value here even if `str` is an empty string.\nreturn {\nuseCache: true,\nkey: inputPath + str,\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-2258/_includes/_code.scss", "new_path": "test/stubs-2258/_includes/_code.scss", "diff": "-/* New content */\n\\ No newline at end of file\n+code {\n+ padding: 0.25em;\n+ line-height: 0;\n+}\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
Wrong test file content
699
12.12.2022 12:18:33
21,600
ba273e655ea2432bbb2c5f36c62be946d32de911
Restore test file at the end
[ { "change_type": "MODIFY", "old_path": "test/EleventyTest.js", "new_path": "test/EleventyTest.js", "diff": "@@ -613,6 +613,7 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\nline-height: 0;\n}`;\nlet newContents = `/* New content */`;\n+\nawait fsp.writeFile(includeFilePath, previousContents, { encoding: \"utf8\" });\nlet results = await elev.toJSON();\n@@ -651,4 +652,6 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\n`${newContents}\n/* Comment */`\n);\n+\n+ await fsp.writeFile(includeFilePath, previousContents, { encoding: \"utf8\" });\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Restore test file at the end
699
12.12.2022 13:13:57
21,600
f267a2cbba90af433e4f23fcc32259f587006ee8
normalize global dependency map, windows fix
[ { "change_type": "MODIFY", "old_path": "src/GlobalDependencyMap.js", "new_path": "src/GlobalDependencyMap.js", "diff": "const { DepGraph } = require(\"dependency-graph\");\nconst { TemplatePath } = require(\"@11ty/eleventy-utils\");\n+const PathNormalizer = require(\"./Util/PathNormalizer\");\nconst eventBus = require(\"./EventBus.js\");\n// TODO extend this to built-in template types, this is only used by Custom templates for now\n@@ -32,7 +33,10 @@ class GlobalDependencyMap {\n// Paths should not be absolute (we convert absolute paths to relative)\n// Paths should not have a leading dot slash\n- return TemplatePath.stripLeadingDotSlash(TemplatePath.relativePath(node));\n+ // Paths should always be `/` independent of OS path separator\n+ return TemplatePath.stripLeadingDotSlash(\n+ PathNormalizer.normalizeSeperator(TemplatePath.relativePath(node))\n+ );\n}\ndelete(node) {\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyTest.js", "new_path": "test/EleventyTest.js", "diff": "@@ -601,11 +601,6 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\nconfigPath: \"./test/stubs-2258/eleventy.config.js\",\n});\n- let sizes = [\n- TemplateContent._inputCache.size,\n- TemplateContent._compileCache.size,\n- ];\n-\n// Restore previous contents\nlet includeFilePath = \"./test/stubs-2258/_includes/_code.scss\";\nlet previousContents = `code {\n@@ -616,6 +611,11 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\nawait fsp.writeFile(includeFilePath, previousContents, { encoding: \"utf8\" });\n+ let sizes = [\n+ TemplateContent._inputCache.size,\n+ TemplateContent._compileCache.size,\n+ ];\n+\nlet results = await elev.toJSON();\nt.is(results.length, 1);\n@@ -626,12 +626,11 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\n/* Comment */`\n);\n+ // Cache sizes are now one bigger\nt.is(sizes[0] + 1, 1);\nt.is(sizes[1] + 1, 1);\nlet results2 = await elev.toJSON();\n-\n- t.is(results2.length, 1);\nt.is(\nnormalizeNewLines(results2[0].content),\n`${previousContents}\n@@ -639,14 +638,16 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\n/* Comment */`\n);\n+ // Cache sizes are unchanged from last build\nt.is(sizes[0] + 1, 1);\nt.is(sizes[1] + 1, 1);\nawait fsp.writeFile(includeFilePath, newContents, { encoding: \"utf8\" });\n+\n+ // Trigger that the file has changed\neventBus.emit(\"eleventy.resourceModified\", includeFilePath);\nlet results3 = await elev.toJSON();\n- t.is(results3.length, 1);\nt.is(\nnormalizeNewLines(results3[0].content),\n`${newContents}\n" } ]
JavaScript
MIT License
11ty/eleventy
normalize global dependency map, windows fix #2258
699
12.12.2022 15:38:12
21,600
e46c3663b010a0fd2db7f7186a7e424bd375c0c7
Superfluous code from
[ { "change_type": "MODIFY", "old_path": "src/TemplateContent.js", "new_path": "src/TemplateContent.js", "diff": "@@ -552,23 +552,19 @@ class TemplateContent {\nreturn false;\n} else {\n+ // Not great way of building all templates if this is a layout, include, JS dependency.\n+ // TODO improve this for default template syntaxes\n+\n// This is the fallback way of determining if something is incremental (no isIncrementalMatch available)\n+ // This will be true if the inputPath and incrementalFile are the same\nif (isRelevant) {\nreturn true;\n}\n- // Not great way of building all templates if this is a layout, include, JS dependency.\n- // TODO improve this for default template syntaxes\n-\n// only return true here if dependencies are not known\nif (!hasDependencies && !metadata.isFullTemplate) {\nreturn true;\n}\n-\n- // only build if this input path is the same as the file that was changed\n- if (this.inputPath === incrementalFile) {\n- return true;\n- }\n}\nreturn false;\n" } ]
JavaScript
MIT License
11ty/eleventy
Superfluous code from #2258
699
12.12.2022 16:49:07
21,600
db3c9bf5c9aad7682b369e0217e15f3cb78da18f
Adds for-free layout dependency checking
[ { "change_type": "MODIFY", "old_path": "src/Eleventy.js", "new_path": "src/Eleventy.js", "diff": "@@ -644,6 +644,7 @@ Arguments:\n* @param {String} changedFilePath - File that triggered a re-run (added or modified)\n*/\nasync _addFileToWatchQueue(changedFilePath) {\n+ // Note: this is a sync event!\neventBus.emit(\"eleventy.resourceModified\", changedFilePath);\nthis.watchManager.addToPendingQueue(changedFilePath);\n}\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/Custom.js", "new_path": "src/Engines/Custom.js", "diff": "@@ -14,6 +14,8 @@ class CustomEngine extends TemplateEngine {\nconstructor(name, dirs, config) {\nsuper(name, dirs, config);\n+ usesMap.setConfig(config);\n+\nthis.entry = this.getExtensionMapEntry();\nthis.needsInit =\n\"init\" in this.entry && typeof this.entry.init === \"function\";\n" }, { "change_type": "MODIFY", "old_path": "test/EleventyTest.js", "new_path": "test/EleventyTest.js", "diff": "@@ -596,7 +596,7 @@ test(\"Does pathPrefix affect page URLs\", async (t) => {\nt.is(result.url, \"/README/\");\n});\n-test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\n+test(\"Improvements to custom template syntax APIs (includes a layout file) #2258\", async (t) => {\nlet elev = new Eleventy(\"./test/stubs-2258/\", \"./test/stubs-2258/_site\", {\nconfigPath: \"./test/stubs-2258/eleventy.config.js\",\n});\n@@ -621,7 +621,8 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\nt.is(results.length, 1);\nt.is(\nnormalizeNewLines(results[0].content),\n- `${previousContents}\n+ `/* Banner */\n+${previousContents}\n/* Comment */`\n);\n@@ -633,7 +634,8 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\nlet results2 = await elev.toJSON();\nt.is(\nnormalizeNewLines(results2[0].content),\n- `${previousContents}\n+ `/* Banner */\n+${previousContents}\n/* Comment */`\n);\n@@ -650,7 +652,8 @@ test(\"Improvements to custom template syntax APIs, #2258\", async (t) => {\nlet results3 = await elev.toJSON();\nt.is(\nnormalizeNewLines(results3[0].content),\n- `${newContents}\n+ `/* Banner */\n+${newContents}\n/* Comment */`\n);\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/stubs-2258/_includes/layout.njk", "diff": "+/* Banner */\n+{{ content | safe }}\n\\ No newline at end of file\n" }, { "change_type": "MODIFY", "old_path": "test/stubs-2258/style.scss", "new_path": "test/stubs-2258/style.scss", "diff": "+---\n+layout: layout.njk\n+---\n@use \"code.scss\";\n/* Comment */\n\\ No newline at end of file\n" } ]
JavaScript
MIT License
11ty/eleventy
Adds for-free layout dependency checking #2258
699
13.12.2022 12:28:35
21,600
8be59ccf8144d0dc59b18a93a72365542d5a1746
Fixes for layout checks, should only apply to incremental, layouts are irrelevant to the compile cache
[ { "change_type": "MODIFY", "old_path": "src/Engines/Custom.js", "new_path": "src/Engines/Custom.js", "diff": "@@ -235,14 +235,14 @@ class CustomEngine extends TemplateEngine {\nreturn true;\n}\n- isFileRelevantTo(inputPath, comparisonFile) {\n- return usesMap.isFileRelevantTo(inputPath, comparisonFile);\n+ isFileRelevantTo(inputPath, comparisonFile, includeLayouts) {\n+ return usesMap.isFileRelevantTo(inputPath, comparisonFile, includeLayouts);\n}\ngetCompileCacheKey(str, inputPath) {\n// Return this separately so we know whether or not to use the cached version\n// but still return a key to cache this new render for next time\n- let useCache = !this.isFileRelevantTo(inputPath, lastModifiedFile);\n+ let useCache = !this.isFileRelevantTo(inputPath, lastModifiedFile, false);\nif (\nthis.entry.compileOptions &&\n" } ]
JavaScript
MIT License
11ty/eleventy
Fixes for layout checks, should only apply to incremental, layouts are irrelevant to the compile cache #2258
699
14.12.2022 15:55:34
21,600
44a48cb577f3db7174121631842a576849a0b757
Some internal filter simplification from
[ { "change_type": "MODIFY", "old_path": "src/Filters/GetCollectionItemIndex.js", "new_path": "src/Filters/GetCollectionItemIndex.js", "diff": "// TODO locale-friendly, see GetLocaleCollectionItem.js)\nmodule.exports = function getCollectionItemIndex(collection, page) {\nif (!page) {\n- page = this.page || this.ctx?.page || this.context?.environments?.page;\n+ page = this.page;\n}\nlet j = 0;\n" }, { "change_type": "MODIFY", "old_path": "src/Filters/GetLocaleCollectionItem.js", "new_path": "src/Filters/GetLocaleCollectionItem.js", "diff": "@@ -18,13 +18,16 @@ function getLocaleCollectionItem(\nlangCode,\nindexModifier = 0\n) {\n- let page = this.page || this.ctx?.page || this.context?.environments?.page;\nif (!langCode) {\n// if page.lang exists (2.0.0-canary.14 and i18n plugin added, use page language)\n- if (page.lang) {\n- langCode = page.lang;\n+ if (this.page.lang) {\n+ langCode = this.page.lang;\n} else {\n- return getCollectionItem(collection, pageOverride || page, indexModifier);\n+ return getCollectionItem(\n+ collection,\n+ pageOverride || this.page,\n+ indexModifier\n+ );\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/HtmlBasePlugin.js", "new_path": "src/Plugins/HtmlBasePlugin.js", "diff": "@@ -107,11 +107,7 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\nreturn transformUrl.call(this, url, base, {\npathPrefix: eleventyConfig.pathPrefix,\n- pageUrl:\n- pageUrlOverride ||\n- this.page?.url ||\n- this.ctx?.page?.url ||\n- this.context?.environments?.page?.url,\n+ pageUrl: pageUrlOverride || this.page?.url,\n});\n}\n);\n@@ -126,14 +122,10 @@ module.exports = function (eleventyConfig, defaultOptions = {}) {\nreturn content;\n}\n- let fallbackPageUrl =\n- this.page?.url ||\n- this.ctx?.page?.url ||\n- this.context?.environments?.page?.url;\nreturn addToAllHtmlUrls(content, (url) => {\nreturn transformUrl.call(this, url.trim(), base, {\npathPrefix: eleventyConfig.pathPrefix,\n- pageUrl: pageUrlOverride || fallbackPageUrl,\n+ pageUrl: pageUrlOverride || this.page?.url,\n});\n});\n}\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/I18nPlugin.js", "new_path": "src/Plugins/I18nPlugin.js", "diff": "@@ -100,12 +100,6 @@ class Comparator {\n}\n}\n-function getPageInFilter(context) {\n- return (\n- context.page || context.ctx?.page || context.context?.environments?.page\n- );\n-}\n-\nfunction normalizeInputPath(inputPath, extensionMap) {\nif (extensionMap) {\nreturn extensionMap.removeTemplateExtension(inputPath);\n@@ -248,7 +242,7 @@ function EleventyPlugin(eleventyConfig, opts = {}) {\nfunction (url, langCodeOverride) {\nlet langCode =\nlangCodeOverride ||\n- LangUtils.getLanguageCodeFromUrl(getPageInFilter(this)?.url) ||\n+ LangUtils.getLanguageCodeFromUrl(this.page?.url) ||\noptions.defaultLanguage;\n// Already has a language code on it and has a relevant url with the target language code\n@@ -298,7 +292,7 @@ function EleventyPlugin(eleventyConfig, opts = {}) {\n// Refactor to use url\n// Find the links that are localized alternates to the inputPath argument\neleventyConfig.addFilter(options.filters.links, function (urlOverride) {\n- let url = urlOverride || getPageInFilter(this)?.url;\n+ let url = urlOverride || this.page?.url;\nreturn contentMaps.localeUrlsMap[url] || [];\n});\n@@ -312,7 +306,7 @@ function EleventyPlugin(eleventyConfig, opts = {}) {\nlanguageCode = options.defaultLanguage;\n}\n- let page = pageOverride || getPageInFilter(this);\n+ let page = pageOverride || this.page;\nlet url; // new url\nif (contentMaps.localeUrlsMap[page.url]) {\nfor (let entry of contentMaps.localeUrlsMap[page.url]) {\n" } ]
JavaScript
MIT License
11ty/eleventy
Some internal filter simplification from #2250
699
14.12.2022 16:08:46
21,600
0b549b000f5ea17e88fd7cd28ccf633ea7831046
A bit more shortcode normalization cleanup for
[ { "change_type": "MODIFY", "old_path": "src/Engines/Liquid.js", "new_path": "src/Engines/Liquid.js", "diff": "@@ -53,6 +53,28 @@ class Liquid extends TemplateEngine {\nreturn options;\n}\n+ static wrapFilter(fn) {\n+ return function (...args) {\n+ if (this.context && \"get\" in this.context) {\n+ this.page = this.context.get([\"page\"]);\n+ this.eleventy = this.context.get([\"eleventy\"]);\n+ }\n+\n+ return fn.call(this, ...args);\n+ };\n+ }\n+\n+ // Shortcodes\n+ static normalizeScope(context) {\n+ let obj = {};\n+ if (context) {\n+ obj.ctx = context;\n+ obj.page = context.get([\"page\"]);\n+ obj.eleventy = context.get([\"eleventy\"]);\n+ }\n+ return obj;\n+ }\n+\naddCustomTags(tags) {\nfor (let name in tags) {\nthis.addTag(name, tags[name]);\n@@ -69,17 +91,6 @@ class Liquid extends TemplateEngine {\nthis.liquidLib.registerFilter(name, Liquid.wrapFilter(filter));\n}\n- static wrapFilter(fn) {\n- return function (...args) {\n- if (this.context && \"get\" in this.context) {\n- this.page = this.context.get([\"page\"]);\n- this.eleventy = this.context.get([\"eleventy\"]);\n- }\n-\n- return fn.call(this, ...args);\n- };\n- }\n-\naddTag(name, tagFn) {\nlet tagObj;\nif (typeof tagFn === \"function\") {\n@@ -139,15 +150,6 @@ class Liquid extends TemplateEngine {\nreturn argArray;\n}\n- static _normalizeShortcodeScope(ctx) {\n- let obj = {};\n- if (ctx) {\n- obj.page = ctx.get([\"page\"]);\n- obj.eleventy = ctx.get([\"eleventy\"]);\n- }\n- return obj;\n- }\n-\naddShortcode(shortcodeName, shortcodeFn) {\nlet _t = this;\nthis.addTag(shortcodeName, function (liquidEngine) {\n@@ -156,7 +158,7 @@ class Liquid extends TemplateEngine {\nthis.name = tagToken.name;\nthis.args = tagToken.args;\n},\n- render: function* (ctx, emitter) {\n+ render: function* (ctx) {\nlet rawArgs = Liquid.parseArguments(_t.argLexer, this.args);\nlet argArray = [];\nlet contextScope = ctx.getAll();\n@@ -166,10 +168,9 @@ class Liquid extends TemplateEngine {\n}\nlet ret = yield shortcodeFn.call(\n- Liquid._normalizeShortcodeScope(ctx),\n+ Liquid.normalizeScope(ctx),\n...argArray\n);\n- // emitter.write(ret);\nreturn ret;\n},\n};\n@@ -210,7 +211,7 @@ class Liquid extends TemplateEngine {\n);\nlet ret = yield shortcodeFn.call(\n- Liquid._normalizeShortcodeScope(ctx),\n+ Liquid.normalizeScope(ctx),\nhtml,\n...argArray\n);\n" }, { "change_type": "MODIFY", "old_path": "src/Engines/Nunjucks.js", "new_path": "src/Engines/Nunjucks.js", "diff": "@@ -114,6 +114,23 @@ class Nunjucks extends TemplateEngine {\n};\n}\n+ // Shortcodes\n+ static normalizeContext(context) {\n+ let obj = {};\n+ if (context.ctx) {\n+ obj.ctx = context.ctx;\n+\n+ if (context.ctx.page) {\n+ obj.page = context.ctx.page;\n+ }\n+\n+ if (context.ctx.eleventy) {\n+ obj.eleventy = context.ctx.eleventy;\n+ }\n+ }\n+ return obj;\n+ }\n+\naddCustomTags(tags) {\nfor (let name in tags) {\nthis.addTag(name, tags[name]);\n@@ -155,20 +172,6 @@ class Nunjucks extends TemplateEngine {\n}\n}\n- static _normalizeShortcodeContext(context) {\n- let obj = {};\n- if (context.ctx) {\n- obj.ctx = context.ctx;\n- if (context.ctx.page) {\n- obj.page = context.ctx.page;\n- }\n- if (context.ctx.eleventy) {\n- obj.eleventy = context.ctx.eleventy;\n- }\n- }\n- return obj;\n- }\n-\n_getShortcodeFn(shortcodeName, shortcodeFn, isAsync = false) {\nreturn function ShortcodeFunction() {\nthis.tags = [shortcodeName];\n@@ -203,7 +206,7 @@ class Nunjucks extends TemplateEngine {\nif (isAsync) {\nshortcodeFn\n- .call(Nunjucks._normalizeShortcodeContext(context), ...argArray)\n+ .call(Nunjucks.normalizeContext(context), ...argArray)\n.then(function (returnValue) {\nresolve(\nnull,\n@@ -223,7 +226,7 @@ class Nunjucks extends TemplateEngine {\n} else {\ntry {\nlet ret = shortcodeFn.call(\n- Nunjucks._normalizeShortcodeContext(context),\n+ Nunjucks.normalizeContext(context),\n...argArray\n);\nreturn new NunjucksLib.runtime.SafeString(\"\" + ret);\n@@ -274,7 +277,7 @@ class Nunjucks extends TemplateEngine {\nif (isAsync) {\nshortcodeFn\n.call(\n- Nunjucks._normalizeShortcodeContext(context),\n+ Nunjucks.normalizeContext(context),\nbodyContent,\n...argArray\n)\n@@ -297,7 +300,7 @@ class Nunjucks extends TemplateEngine {\nnull,\nnew NunjucksLib.runtime.SafeString(\nshortcodeFn.call(\n- Nunjucks._normalizeShortcodeContext(context),\n+ Nunjucks.normalizeContext(context),\nbodyContent,\n...argArray\n)\n" } ]
JavaScript
MIT License
11ty/eleventy
A bit more shortcode normalization cleanup for #1522
699
14.12.2022 16:16:22
21,600
5ad00b32a3416e21a4f4fc1ffaf465edb58971e2
Make `page` available to transforms and linters,
[ { "change_type": "MODIFY", "old_path": "src/Template.js", "new_path": "src/Template.js", "diff": "@@ -481,6 +481,8 @@ class Template extends TemplateContent {\nasync runLinters(str, page) {\nlet { inputPath, outputPath, url } = page;\n+ let pageData = page.data.page;\n+\nfor (let linter of this.linters) {\n// these can be asynchronous but no guarantee of order when they run\nlinter.call(\n@@ -488,6 +490,7 @@ class Template extends TemplateContent {\ninputPath,\noutputPath,\nurl,\n+ page: pageData,\n},\nstr,\ninputPath,\n@@ -505,6 +508,8 @@ class Template extends TemplateContent {\nasync runTransforms(str, page) {\nlet { inputPath, outputPath, url } = page;\n+ let pageData = page.data.page;\n+\nfor (let { callback, name } of this.transforms) {\ntry {\nlet hadStrBefore = !!str;\n@@ -513,6 +518,7 @@ class Template extends TemplateContent {\ninputPath,\noutputPath,\nurl,\n+ page: pageData,\n},\nstr,\noutputPath\n" } ]
JavaScript
MIT License
11ty/eleventy
Make `page` available to transforms and linters, #1522
699
14.12.2022 16:21:21
21,600
47729b145adfd14ad7c1c64af764196e3c052964
Re-enable a skipped test for
[ { "change_type": "MODIFY", "old_path": "test/TemplateTest.js", "new_path": "test/TemplateTest.js", "diff": "@@ -1024,7 +1024,7 @@ test(\"Test a transform\", async (t) => {\n});\n// #789: https://github.com/11ty/eleventy/issues/789\n-test.skip(\"Test a transform (does it have inputPath?)\", async (t) => {\n+test(\"Test a transform (does it have this.inputPath?)\", async (t) => {\nt.plan(3);\nlet tmpl = getNewTemplate(\n@@ -1033,9 +1033,9 @@ test.skip(\"Test a transform (does it have inputPath?)\", async (t) => {\n\"./test/stubs/_site\"\n);\n- tmpl.addTransform(\"transformName\", function (content, outputPath, inputPath) {\n+ tmpl.addTransform(\"transformName\", function (content, outputPath) {\nt.true(outputPath.endsWith(\".html\"));\n- t.true(!!inputPath);\n+ t.true(!!this.inputPath);\nreturn \"OVERRIDE BY A TRANSFORM\";\n});\n" } ]
JavaScript
MIT License
11ty/eleventy
Re-enable a skipped test for #789
699
14.12.2022 17:20:06
21,600
bf016192892d5274cb4a26aed06971900da0513b
Add `content` (alias to `templateContent`) and `page` for collections items, fixes
[ { "change_type": "MODIFY", "old_path": "test/TemplateTest-JavaScript.js", "new_path": "test/TemplateTest-JavaScript.js", "diff": "@@ -16,6 +16,10 @@ test(\"JavaScript template type (function)\", async (t) => {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Zach</p>\");\n+\n+ // New in 2.0.0-canary.19 Issue #1522\n+ t.is(pages[0].content.trim(), \"<p>Zach</p>\");\n+ t.is(pages[0].page.url, \"/function/\");\n});\ntest(\"JavaScript template type (class with data getter)\", async (t) => {\n@@ -30,6 +34,7 @@ test(\"JavaScript template type (class with data getter)\", async (t) => {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\n});\ntest(\"JavaScript template type (class with data method)\", async (t) => {\n@@ -44,6 +49,7 @@ test(\"JavaScript template type (class with data method)\", async (t) => {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\n});\nif (semver.gte(process.version, \"12.4.0\")) {\n@@ -59,6 +65,7 @@ if (semver.gte(process.version, \"12.4.0\")) {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\n});\n}\n@@ -77,6 +84,7 @@ test(\"JavaScript template type (class with shorthand data method)\", async (t) =>\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\n});\ntest(\"JavaScript template type (class with async data method)\", async (t) => {\n@@ -91,6 +99,7 @@ test(\"JavaScript template type (class with async data method)\", async (t) => {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\n});\ntest(\"JavaScript template type (class with data getter and a javascriptFunction)\", async (t) => {\n@@ -110,6 +119,7 @@ test(\"JavaScript template type (class with data getter and a javascriptFunction)\nlet data = await tmpl.getData();\nt.is(await tmpl.getOutputPath(data), \"./dist/class-data-filter/index.html\");\nlet pages = await getRenderedTmpls(tmpl, data);\n+ t.is(pages[0].content.trim(), \"<p>TED</p>\");\nt.is(pages[0].templateContent.trim(), \"<p>TED</p>\");\n});\n@@ -133,6 +143,7 @@ test(\"JavaScript template type (class with data method and a javascriptFunction)\n\"./dist/class-data-fn-filter/index.html\"\n);\nlet pages = await getRenderedTmpls(tmpl, data);\n+ t.is(pages[0].content.trim(), \"<p>TED</p>\");\nt.is(pages[0].templateContent.trim(), \"<p>TED</p>\");\n});\n@@ -212,6 +223,7 @@ test(\"JavaScript template type (should use the same class instance for data and\n// the template renders the random number created in the class constructor\n// the data returns the random number created in the class constructor\n// if they are different, the class is not reused.\n+ t.is(pages[0].content.trim(), `<p>Ted${data.rand}</p>`);\nt.is(pages[0].templateContent.trim(), `<p>Ted${data.rand}</p>`);\n});\n@@ -224,6 +236,7 @@ test(\"JavaScript template type (multiple exports)\", async (t) => {\nlet data = await tmpl.getData();\nlet pages = await getRenderedTmpls(tmpl, data);\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -238,6 +251,7 @@ test(\"JavaScript template type (multiple exports, promises)\", async (t) => {\nt.is(data.name, \"Ted\");\nlet pages = await getRenderedTmpls(tmpl, data);\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -252,6 +266,7 @@ test(\"JavaScript template type (object)\", async (t) => {\nt.is(data.name, \"Ted\");\nlet pages = await getRenderedTmpls(tmpl, data);\n+ t.is(pages[0].content.trim(), \"<p>Ted</p>\");\nt.is(pages[0].templateContent.trim(), \"<p>Ted</p>\");\n});\n@@ -267,6 +282,7 @@ test(\"JavaScript template type (object, no render method)\", async (t) => {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"\");\n+ t.is(pages[0].content.trim(), \"\");\n});\ntest(\"JavaScript template type (class, no render method)\", async (t) => {\n@@ -281,6 +297,7 @@ test(\"JavaScript template type (class, no render method)\", async (t) => {\nlet pages = await getRenderedTmpls(tmpl, data);\nt.is(pages[0].templateContent.trim(), \"\");\n+ t.is(pages[0].content.trim(), \"\");\n});\ntest(\"JavaScript template type (data returns a string)\", async (t) => {\nlet tmpl = getNewTemplate(\n" } ]
JavaScript
MIT License
11ty/eleventy
Add `content` (alias to `templateContent`) and `page` for collections items, fixes #1522
699
15.12.2022 13:14:23
21,600
b67ad0c10282e45618b8735abba047415dda9530
Config API for more tests
[ { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "const fs = require(\"fs\");\nconst chalk = require(\"kleur\");\n-const lodashUniq = require(\"lodash/uniq\");\n-const lodashMerge = require(\"lodash/merge\");\nconst { TemplatePath } = require(\"@11ty/eleventy-utils\");\nconst EleventyBaseError = require(\"./EleventyBaseError.js\");\nconst UserConfig = require(\"./UserConfig.js\");\nconst { EleventyRequire } = require(\"./Util/Require.js\");\n+const merge = require(\"./Util/Merge.js\");\n+const unique = require(\"./Util/Unique\");\nconst eventBus = require(\"./EventBus.js\");\nconst debug = require(\"debug\")(\"Eleventy:TemplateConfig\");\n@@ -342,7 +342,7 @@ class TemplateConfig {\ndelete localConfig.templateFormats;\n}\n- let mergedConfig = lodashMerge({}, this.rootConfig, localConfig);\n+ let mergedConfig = merge({}, this.rootConfig, localConfig);\n// Delay processing plugins until after the result of localConfig is returned\n// But BEFORE the rest of the config options are merged\n@@ -379,7 +379,7 @@ class TemplateConfig {\ndelete eleventyConfigApiMergingObject.templateFormats;\n}\n- lodashMerge(mergedConfig, eleventyConfigApiMergingObject);\n+ merge(mergedConfig, eleventyConfigApiMergingObject);\n// debug(\"this.userConfig.getMergingConfigObject: %o\", this.userConfig.getMergingConfigObject());\n// debug(\"mergedConfig: %o\", mergedConfig);\n@@ -390,16 +390,15 @@ class TemplateConfig {\ntemplateFormats = this.overrides.templateFormats;\ndelete this.overrides.templateFormats;\n}\n- lodashMerge(mergedConfig, this.overrides);\n+ merge(mergedConfig, this.overrides);\n// Additive should preserve original templateFormats, wherever those come from (config API or config return object)\n- mergedConfig.templateFormats = lodashUniq([\n+ mergedConfig.templateFormats = unique([\n...templateFormats,\n...templateFormatsAdded,\n]);\ndebug(\"Current configuration: %o\", mergedConfig);\n-\nreturn mergedConfig;\n}\n}\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateData.js", "new_path": "src/TemplateData.js", "diff": "@@ -3,10 +3,10 @@ const fastglob = require(\"fast-glob\");\nconst path = require(\"path\");\nconst lodashset = require(\"lodash/set\");\nconst lodashget = require(\"lodash/get\");\n-const lodashUniq = require(\"lodash/uniq\");\nconst { TemplatePath, isPlainObject } = require(\"@11ty/eleventy-utils\");\nconst merge = require(\"./Util/Merge\");\n+const unique = require(\"./Util/Unique\");\nconst TemplateRender = require(\"./TemplateRender\");\nconst TemplateGlob = require(\"./TemplateGlob\");\nconst EleventyExtensionMap = require(\"./EleventyExtensionMap\");\n@@ -176,6 +176,7 @@ class TemplateData {\nif (Array.isArray(this.config.dataFileSuffixes)) {\nreturn this.config.dataFileSuffixes;\n}\n+\n// Backwards compatibility\nif (this.config.jsDataFileSuffix) {\nlet suffixes = [];\n@@ -685,7 +686,7 @@ class TemplateData {\n}\ndebug(\"getLocalDataPaths(%o): %o\", templatePath, paths);\n- return lodashUniq(paths).reverse();\n+ return unique(paths).reverse();\n}\nstatic mergeDeep(config, target, ...source) {\n" }, { "change_type": "MODIFY", "old_path": "src/UserConfig.js", "new_path": "src/UserConfig.js", "diff": "@@ -100,6 +100,10 @@ class UserConfig {\nthis.libraryAmendments = {};\nthis.serverPassthroughCopyBehavior = \"passthrough\";\nthis.urlTransforms = [];\n+\n+ // Defaults in `defaultConfig.js`\n+ this.dataFileSuffixesOverride = false;\n+ this.dataFileDirBaseNameOverride = false;\n}\nversionCheck(expected) {\n@@ -887,8 +891,16 @@ class UserConfig {\nthis.urlTransforms.push(callback);\n}\n+ setDataFileSuffixes(suffixArray) {\n+ this.dataFileSuffixesOverride = suffixArray;\n+ }\n+\n+ setDataFileBaseName(baseName) {\n+ this.dataFileDirBaseNameOverride = baseName;\n+ }\n+\ngetMergingConfigObject() {\n- return {\n+ let obj = {\ntemplateFormats: this.templateFormats,\ntemplateFormatsAdded: this.templateFormatsAdded,\n// filters removed in 1.0 (use addTransform instead)\n@@ -945,6 +957,17 @@ class UserConfig {\nserverPassthroughCopyBehavior: this.serverPassthroughCopyBehavior,\nurlTransforms: this.urlTransforms,\n};\n+\n+ if (Array.isArray(this.dataFileSuffixesOverride)) {\n+ // no upstream merging of this array, so we add the override: prefix\n+ obj[\"override:dataFileSuffixes\"] = this.dataFileSuffixesOverride;\n+ }\n+\n+ if (this.dataFileDirBaseNameOverride) {\n+ obj.dataFileDirBaseNameOverride = this.dataFileDirBaseNameOverride;\n+ }\n+\n+ return obj;\n}\n}\n" }, { "change_type": "ADD", "old_path": null, "new_path": "src/Util/Unique.js", "diff": "+module.exports = function Unique(arr) {\n+ return Array.from(new Set(arr));\n+};\n" }, { "change_type": "MODIFY", "old_path": "test/TemplateDataTest.js", "new_path": "test/TemplateDataTest.js", "diff": "@@ -291,11 +291,9 @@ test(\"getLocalDataPaths\", async (t) => {\n]);\n});\n-test(\"getLocalDataPaths (with dataFileDirBaseNameOverride #1699)\", async (t) => {\n+test(\"getLocalDataPaths (with setDataFileBaseName #1699)\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\n- eleventyConfig.appendToRootConfig({\n- dataFileDirBaseNameOverride: \"index\",\n- });\n+ eleventyConfig.userConfig.setDataFileBaseName(\"index\");\nlet dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\nlet paths = await dataObj.getLocalDataPaths(\n@@ -316,6 +314,58 @@ test(\"getLocalDataPaths (with dataFileDirBaseNameOverride #1699)\", async (t) =>\n]);\n});\n+test(\"getLocalDataPaths (with empty setDataFileSuffixes #1699)\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ eleventyConfig.userConfig.setDataFileSuffixes([]);\n+\n+ let dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\n+ let paths = await dataObj.getLocalDataPaths(\n+ \"./test/stubs/component/component.liquid\"\n+ );\n+\n+ t.deepEqual(paths, []);\n+});\n+\n+test(\"getLocalDataPaths (with setDataFileSuffixes override #1699)\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ eleventyConfig.userConfig.setDataFileSuffixes([\".howdy\"]);\n+\n+ let dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\n+ let paths = await dataObj.getLocalDataPaths(\n+ \"./test/stubs/component/component.liquid\"\n+ );\n+\n+ t.deepEqual(paths, [\n+ \"./test/stubs/stubs.howdy.json\",\n+ \"./test/stubs/stubs.howdy.cjs\",\n+ \"./test/stubs/stubs.howdy.js\",\n+ \"./test/stubs/component/component.howdy.json\",\n+ \"./test/stubs/component/component.howdy.cjs\",\n+ \"./test/stubs/component/component.howdy.js\",\n+ ]);\n+});\n+\n+test(\"getLocalDataPaths (with setDataFileSuffixes override with two entries #1699)\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ eleventyConfig.userConfig.setDataFileSuffixes([\".howdy\", \"\"]);\n+\n+ let dataObj = new TemplateData(\"./test/stubs/\", eleventyConfig);\n+ let paths = await dataObj.getLocalDataPaths(\n+ \"./test/stubs/component/component.liquid\"\n+ );\n+\n+ t.deepEqual(paths, [\n+ \"./test/stubs/stubs.json\",\n+ \"./test/stubs/stubs.howdy.json\",\n+ \"./test/stubs/stubs.howdy.cjs\",\n+ \"./test/stubs/stubs.howdy.js\",\n+ \"./test/stubs/component/component.json\",\n+ \"./test/stubs/component/component.howdy.json\",\n+ \"./test/stubs/component/component.howdy.cjs\",\n+ \"./test/stubs/component/component.howdy.js\",\n+ ]);\n+});\n+\ntest(\"Deeper getLocalDataPaths\", async (t) => {\nlet eleventyConfig = new TemplateConfig();\nlet dataObj = new TemplateData(\"./\", eleventyConfig);\n" } ]
JavaScript
MIT License
11ty/eleventy
Config API for #1699, more tests
699
15.12.2022 13:39:01
21,600
2fc0e5e38b1cdbba301abd2100b41f0aec5ca284
Cleanup some config code after changes for
[ { "change_type": "MODIFY", "old_path": "src/TemplateConfig.js", "new_path": "src/TemplateConfig.js", "diff": "@@ -281,12 +281,11 @@ class TemplateConfig {\n}\n/**\n- * Merges different config files together.\n+ * Fetches and executes the local configuration file\n*\n- * @param {String} projectConfigPath - Path to project config.\n- * @returns {{}} merged - The merged config file.\n+ * @returns {{}} merged - The merged config file object.\n*/\n- mergeConfig() {\n+ requireLocalConfigFile() {\nlet localConfig = {};\nlet path = this.projectConfigPaths\n.filter((path) => path)\n@@ -336,6 +335,22 @@ class TemplateConfig {\ndebug(\"Eleventy local project config file not found, skipping.\");\n}\n+ return localConfig;\n+ }\n+\n+ /**\n+ * Merges different config files together.\n+ *\n+ * @param {String} projectConfigPath - Path to project config.\n+ * @returns {{}} merged - The merged config file.\n+ */\n+ mergeConfig() {\n+ let localConfig = this.requireLocalConfigFile();\n+\n+ // Template Formats:\n+ // 1. Root Config (usually defaultConfig.js)\n+ // 2. Local Config return object (project .eleventy.js)\n+ // 3.\nlet templateFormats = this.rootConfig.templateFormats || [];\nif (localConfig && localConfig.templateFormats) {\ntemplateFormats = localConfig.templateFormats;\n@@ -344,33 +359,34 @@ class TemplateConfig {\nlet mergedConfig = merge({}, this.rootConfig, localConfig);\n- // Delay processing plugins until after the result of localConfig is returned\n- // But BEFORE the rest of the config options are merged\n- // this way we can pass directories and other template information to plugins\n-\n- // Temporarily restore templateFormats\n- mergedConfig.templateFormats = templateFormats;\n+ // Setup a few properties for plugins:\n// Setup pathPrefix set via command line for plugin consumption\nif (this.overrides.pathPrefix) {\nmergedConfig.pathPrefix = this.overrides.pathPrefix;\n}\n+\n// Returning a falsy value (e.g. \"\") from user config should reset to the default value.\nif (!mergedConfig.pathPrefix) {\nmergedConfig.pathPrefix = this.rootConfig.pathPrefix;\n}\n+ // Delay processing plugins until after the result of localConfig is returned\n+ // But BEFORE the rest of the config options are merged\n+ // this way we can pass directories and other template information to plugins\n+\n+ // Temporarily restore templateFormats\n+ mergedConfig.templateFormats = templateFormats;\n+\nthis.processPlugins(mergedConfig);\n+\ndelete mergedConfig.templateFormats;\nlet eleventyConfigApiMergingObject =\nthis.userConfig.getMergingConfigObject();\n- // `templateFormats` is via `setTemplateFormats`\n- // `templateFormatsAdded` is via `addTemplateFormats`\n- let templateFormatsAdded =\n- eleventyConfigApiMergingObject.templateFormatsAdded || [];\n- delete eleventyConfigApiMergingObject.templateFormatsAdded;\n+ // `templateFormats` is an override via `setTemplateFormats`\n+ // `templateFormatsAdded` is additive via `addTemplateFormats`\nif (\neleventyConfigApiMergingObject &&\neleventyConfigApiMergingObject.templateFormats\n@@ -379,24 +395,20 @@ class TemplateConfig {\ndelete eleventyConfigApiMergingObject.templateFormats;\n}\n+ let templateFormatsAdded =\n+ eleventyConfigApiMergingObject.templateFormatsAdded || [];\n+ delete eleventyConfigApiMergingObject.templateFormatsAdded;\n+\n+ templateFormats = unique([...templateFormats, ...templateFormatsAdded]);\n+\nmerge(mergedConfig, eleventyConfigApiMergingObject);\n- // debug(\"this.userConfig.getMergingConfigObject: %o\", this.userConfig.getMergingConfigObject());\n- // debug(\"mergedConfig: %o\", mergedConfig);\n+ // Apply overrides, currently only pathPrefix uses this I think!\ndebug(\"overrides: %o\", this.overrides);\n-\n- // Object assign overrides original values (good only for templateFormats) but not good for anything else\n- if (this.overrides && this.overrides.templateFormats) {\n- templateFormats = this.overrides.templateFormats;\n- delete this.overrides.templateFormats;\n- }\nmerge(mergedConfig, this.overrides);\n- // Additive should preserve original templateFormats, wherever those come from (config API or config return object)\n- mergedConfig.templateFormats = unique([\n- ...templateFormats,\n- ...templateFormatsAdded,\n- ]);\n+ // Restore templateFormats\n+ mergedConfig.templateFormats = templateFormats;\ndebug(\"Current configuration: %o\", mergedConfig);\nreturn mergedConfig;\n" } ]
JavaScript
MIT License
11ty/eleventy
Cleanup some config code after changes for #1699
699
15.12.2022 13:50:55
21,600
6fd206a08c592c45b6fe967136cfe20d3a6576af
Replace global lodash with direct function deps savings in npm install: 38.6 MB to 33.5 MB (-5.1 MB)
[ { "change_type": "MODIFY", "old_path": "package.json", "new_path": "package.json", "diff": "\"iso-639-1\": \"^2.1.15\",\n\"kleur\": \"^4.1.5\",\n\"liquidjs\": \"^10.2.0\",\n- \"lodash\": \"^4.17.21\",\n+ \"lodash.chunk\": \"^4.2.0\",\n+ \"lodash.get\": \"^4.4.2\",\n+ \"lodash.set\": \"^4.3.2\",\n\"luxon\": \"^3.1.0\",\n\"markdown-it\": \"^13.0.1\",\n\"minimist\": \"^1.2.7\",\n" }, { "change_type": "MODIFY", "old_path": "src/ComputedData.js", "new_path": "src/ComputedData.js", "diff": "-const lodashGet = require(\"lodash/get\");\n-const lodashSet = require(\"lodash/set\");\n+const lodashGet = require(\"lodash.get\");\n+const lodashSet = require(\"lodash.set\");\nconst ComputedDataQueue = require(\"./ComputedDataQueue\");\nconst ComputedDataTemplateString = require(\"./ComputedDataTemplateString\");\n" }, { "change_type": "MODIFY", "old_path": "src/ComputedDataProxy.js", "new_path": "src/ComputedDataProxy.js", "diff": "-const lodashSet = require(\"lodash/set\");\n-const lodashGet = require(\"lodash/get\");\n+const lodashSet = require(\"lodash.set\");\n+const lodashGet = require(\"lodash.get\");\nconst { isPlainObject } = require(\"@11ty/eleventy-utils\");\n/* Calculates computed data using Proxies */\n" }, { "change_type": "MODIFY", "old_path": "src/ComputedDataTemplateString.js", "new_path": "src/ComputedDataTemplateString.js", "diff": "-const lodashSet = require(\"lodash/set\");\n+const lodashSet = require(\"lodash.set\");\nconst debug = require(\"debug\")(\"Eleventy:ComputedDataTemplateString\");\n/* Calculates computed data in Template Strings.\n" }, { "change_type": "MODIFY", "old_path": "src/Plugins/Pagination.js", "new_path": "src/Plugins/Pagination.js", "diff": "-const lodashChunk = require(\"lodash/chunk\");\n-const lodashGet = require(\"lodash/get\");\n-const lodashSet = require(\"lodash/set\");\n+const lodashChunk = require(\"lodash.chunk\");\n+const lodashGet = require(\"lodash.get\");\n+const lodashSet = require(\"lodash.set\");\nconst { isPlainObject } = require(\"@11ty/eleventy-utils\");\nconst EleventyBaseError = require(\"../EleventyBaseError\");\n" }, { "change_type": "MODIFY", "old_path": "src/Template.js", "new_path": "src/Template.js", "diff": "@@ -6,8 +6,8 @@ const mkdir = util.promisify(fs.mkdir);\nconst os = require(\"os\");\nconst path = require(\"path\");\nconst normalize = require(\"normalize-path\");\n-const lodashGet = require(\"lodash/get\");\n-const lodashSet = require(\"lodash/set\");\n+const lodashGet = require(\"lodash.get\");\n+const lodashSet = require(\"lodash.set\");\nconst { DateTime } = require(\"luxon\");\nconst { TemplatePath, isPlainObject } = require(\"@11ty/eleventy-utils\");\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateContent.js", "new_path": "src/TemplateContent.js", "diff": "@@ -4,7 +4,7 @@ const util = require(\"util\");\nconst readFile = util.promisify(fs.readFile);\nconst normalize = require(\"normalize-path\");\nconst matter = require(\"gray-matter\");\n-const lodashSet = require(\"lodash/set\");\n+const lodashSet = require(\"lodash.set\");\nconst { TemplatePath } = require(\"@11ty/eleventy-utils\");\nconst EleventyExtensionMap = require(\"./EleventyExtensionMap\");\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateData.js", "new_path": "src/TemplateData.js", "diff": "const fs = require(\"fs\");\nconst fastglob = require(\"fast-glob\");\nconst path = require(\"path\");\n-const lodashset = require(\"lodash/set\");\n-const lodashget = require(\"lodash/get\");\n+const lodashset = require(\"lodash.set\");\n+const lodashget = require(\"lodash.get\");\nconst { TemplatePath, isPlainObject } = require(\"@11ty/eleventy-utils\");\nconst merge = require(\"./Util/Merge\");\n" }, { "change_type": "MODIFY", "old_path": "src/TemplateDataInitialGlobalData.js", "new_path": "src/TemplateDataInitialGlobalData.js", "diff": "const pkg = require(\"../package.json\");\nconst semver = require(\"semver\");\n-const lodashset = require(\"lodash/set\");\n+const lodashset = require(\"lodash.set\");\nclass TemplateDataInitialGlobalData {\nconstructor(templateConfig) {\n" } ]
JavaScript
MIT License
11ty/eleventy
Replace global lodash with direct function deps savings in npm install: 38.6 MB to 33.5 MB (-5.1 MB)
699
16.12.2022 16:11:29
21,600
243539ef80dcf20be3c552fd01544c41e9e71832
Refactor to add eleventyImportCollections, fixes
[ { "change_type": "ADD", "old_path": null, "new_path": "test/_issues/975/975-test.js", "diff": "+const test = require(\"ava\");\n+const TemplateMap = require(\"../../../src/TemplateMap\");\n+const TemplateConfig = require(\"../../../src/TemplateConfig\");\n+\n+const getNewTemplateForTests = require(\"../../_getNewTemplateForTests\");\n+\n+function getNewTemplate(filename, input, output, eleventyConfig) {\n+ return getNewTemplateForTests(\n+ filename,\n+ input,\n+ output,\n+ null,\n+ null,\n+ eleventyConfig\n+ );\n+}\n+\n+test(\"Get ordered list of templates\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ let tm = new TemplateMap(eleventyConfig);\n+\n+ // These two templates are add-order-dependent\n+ await tm.add(\n+ getNewTemplate(\n+ \"./test/_issues/975/post.md\",\n+ \"./test/_issues/975/\",\n+ \"./test/_issues/975/_site\",\n+ eleventyConfig\n+ )\n+ );\n+\n+ await tm.add(\n+ getNewTemplate(\n+ \"./test/_issues/975/another-post.md\",\n+ \"./test/_issues/975/\",\n+ \"./test/_issues/975/_site\",\n+ eleventyConfig\n+ )\n+ );\n+\n+ // This template should always be last\n+ await tm.add(\n+ getNewTemplate(\n+ \"./test/_issues/975/index.md\",\n+ \"./test/_issues/975/\",\n+ \"./test/_issues/975/_site\",\n+ eleventyConfig\n+ )\n+ );\n+\n+ let [first, second, third, fourth] = tm.getFullTemplateMapOrder();\n+ t.deepEqual(\n+ first.filter((entry) => !entry.startsWith(TemplateMap.tagPrefix)),\n+ [\n+ \"./test/_issues/975/post.md\",\n+ \"./test/_issues/975/another-post.md\",\n+ \"./test/_issues/975/index.md\",\n+ ]\n+ );\n+});\n+\n+test(\"Get ordered list of templates (reverse add)\", async (t) => {\n+ let eleventyConfig = new TemplateConfig();\n+ let tm = new TemplateMap(eleventyConfig);\n+\n+ // This template should always be last\n+ await tm.add(\n+ getNewTemplate(\n+ \"./test/_issues/975/index.md\",\n+ \"./test/_issues/975/\",\n+ \"./test/_issues/975/_site\",\n+ eleventyConfig\n+ )\n+ );\n+\n+ // These two templates are add-order-dependent\n+ await tm.add(\n+ getNewTemplate(\n+ \"./test/_issues/975/another-post.md\",\n+ \"./test/_issues/975/\",\n+ \"./test/_issues/975/_site\",\n+ eleventyConfig\n+ )\n+ );\n+\n+ await tm.add(\n+ getNewTemplate(\n+ \"./test/_issues/975/post.md\",\n+ \"./test/_issues/975/\",\n+ \"./test/_issues/975/_site\",\n+ eleventyConfig\n+ )\n+ );\n+\n+ let [first, second, third, fourth] = tm.getFullTemplateMapOrder();\n+ t.deepEqual(\n+ first.filter((entry) => !entry.startsWith(TemplateMap.tagPrefix)),\n+ [\n+ \"./test/_issues/975/another-post.md\",\n+ \"./test/_issues/975/post.md\",\n+ \"./test/_issues/975/index.md\",\n+ ]\n+ );\n+});\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/_issues/975/another-post.md", "diff": "+---\n+tags:\n+ - post\n+---\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/_issues/975/index.md", "diff": "+---\n+eleventyImportCollections:\n+ - post\n+---\n" }, { "change_type": "ADD", "old_path": null, "new_path": "test/_issues/975/post.md", "diff": "+---\n+tags:\n+ - post\n+---\n" } ]
JavaScript
MIT License
11ty/eleventy
Refactor to add eleventyImportCollections, fixes #975