Repository navigation
Change call order of compileOptions.permalink and compile to support MD5 hash in permalink
#2786
danburzo
started this conversation in
Enhancement Queue
Replies: 1 comment
|
A possible workaround involves processing the SCSS file at the config.addTemplateFormats('scss');
config.addExtension('scss', {
read: false,
getData: async function(inputPath) {
const { css } = sass.compile(inputPath);
return {
_content: css,
_hash: getHash(css)
};
},
compileOptions: {
permalink: function(permalink, inputPath) {
if (path.basename(inputPath).startsWith("_")) {
return false;
}
return data => `${data.page.filePathStem}.${data._hash}.css`;
}
},
compile: () => data => data._content
}); |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
A common task is to add cache-busting hashes to asset filenames, such as requested here:
This could work well with
config.addExtension()as it has all the necessary ingredients (as @zachleat mentions in his answer to the aforementioned discussion), but the processing order seems to make it impossible to pass things from.compile()to.compileOptions.permalink().Here is a sample Eleventy config, based on the documentation, where I try to add MD5 hashing in the output filename for SCSS files:
But
compile()doesn't have a chance to populate the_md5data property by the timepermalinkneeds it.Would it make sense to execute
compile()beforepermalink()? It would probably open up a few other use-cases.All reactions