You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd expect that the content with permalink: false and for my transform function to work normally
Screenshots
$ eleventy
Writing dist/index.html from ./src/index.njk.
Error writing templates: (more in DEBUG output)
> Having trouble writing template: false
TemplateWriterWriteError was thrown
> outputPath.endsWith is not a function
TypeError was thrown:
TypeError: outputPath.endsWith is not a function
at Template. (/home/ckot/projects/work/11ty_test/.eleventy.js:7:24)
at Template.runTransforms (/usr/lib/node_modules/@11ty/eleventy/src/Template.js:387:29)
at Template.renderPageEntry (/usr/lib/node_modules/@11ty/eleventy/src/Template.js:548:28)
at process._tickCallback (internal/process/next_tick.js:68:7)
Problem writing Eleventy templates: (more in DEBUG output)
Environment:
OS and version: Ubuntu LTS 18.04
Eleventy Version: 0.10.0
Additional context
I suppose this is not a code bug but rather a documentation bug, although perhaps thinks which have permalink-false should't be passed through transforms, as they don't have an outputPath to begin with.
My fix was to simply test that outputPath is truthy, and that it's a string, prior to calling a string method on it. Regardless of whether there is a code fix for this, it would probably be good that the docs should look more like my solution, simply since it uses defensive programming.
const htmlmin = require("html-minifier");
module.exports = function(eleventyConfig) {
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
// test that outputPath is a string prior to doing anything with it. setting permalink: false, will
// set outputPath to 'false', and perhaps other settings may give unexpected outputPath values
if( outputPath && "string" === typeof(outputPath) && outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
};
The text was updated successfully, but these errors were encountered:
Describe the bug
I recently added
permalink: false
to some templates and my transform function blew up an exception (listed below in screenshots section)To Reproduce
permalink: false
to some template's dataExpected behavior
I'd expect that the content with
permalink: false
and for my transform function to work normallyScreenshots
$ eleventy
Writing dist/index.html from ./src/index.njk.
Error writing templates: (more in DEBUG output)
> Having trouble writing template: false
TemplateWriterWriteError was thrown
> outputPath.endsWith is not a function
TypeError was thrown:
TypeError: outputPath.endsWith is not a function
at Template. (/home/ckot/projects/work/11ty_test/.eleventy.js:7:24)
at Template.runTransforms (/usr/lib/node_modules/@11ty/eleventy/src/Template.js:387:29)
at Template.renderPageEntry (/usr/lib/node_modules/@11ty/eleventy/src/Template.js:548:28)
at process._tickCallback (internal/process/next_tick.js:68:7)
Problem writing Eleventy templates: (more in DEBUG output)
Environment:
Additional context
I suppose this is not a code bug but rather a documentation bug, although perhaps thinks which have permalink-false should't be passed through transforms, as they don't have an outputPath to begin with.
My fix was to simply test that outputPath is truthy, and that it's a string, prior to calling a string method on it. Regardless of whether there is a code fix for this, it would probably be good that the docs should look more like my solution, simply since it uses defensive programming.
The text was updated successfully, but these errors were encountered: