-
-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose inputPath
in transforms
#789
Comments
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open. View the enhancement backlog here. Don’t forget to upvote the top comment with 👍! |
If anyone needs this, until it is supported I use a little trick: I put the
I then need to use jsdom (or regexes) to get the value inside the transform, but at least I get the value. |
Waiting for a better solution in 11ty/eleventy#789
Actually, I need both the I'm currently passing it from the template: <body
…
data-img-src="{{ page.inputPath | dirname }}/"
data-img-dist="{{ page.outputPath | dirname }}/"
> To the transform: // Get images src and dist path from attributes on body
// TODO: move to context data
let documentBody = document.querySelector('body');
let srcPath = documentBody.getAttribute('data-img-src');
let distPath = documentBody.getAttribute('data-img-dist');
documentBody.removeAttribute('data-img-src');
documentBody.removeAttribute('data-img-dist'); |
https://www.npmjs.com/package/eleventy-plugin-local-respimg would benefit greatly from this as well |
I'm still using the trick in #789 (comment) My situation is the following: I developed a plugin: NB: Here, I'm not even sure I pass the plugin options as I should, it feels strange using a global variable for that: https://github.com/nhoizey/eleventy-plugin-images-responsiver/blob/master/.eleventy.js Anyway, this transform calls an But I need to be able to add const imagesResponsiver = require('eleventy-plugin-images-responsiver');
const imagesResponsiverConfig = require('./src/_data/images-responsiver-config.js');
eleventyConfig.addPlugin(imagesResponsiver, imagesResponsiverConfig); The It contains the In my current case, the let srcPath = documentBody.getAttribute('data-img-src');
let distPath = documentBody.getAttribute('data-img-dist').replace(/^dist/, ''); If NB: I could already do it for Thanks for reading all of this, if you did… 😅 |
Really sorry, this is getting punted to 1.0. |
@zachleat no problem on my side, I have a work around which can last as long as you need. |
The awkward part of this is that the linter and transform arguments are going to be reversed. Hmm. |
I think aligning them is a good idea. Given it'll be a breaking change for one of them, doing it either under 0.x or 1.x should be OK given that 0.x public APIs aren't considered stable under Semver (presuming you're keeping strict Semver)
… On May 16, 2020, at 1:33 PM, Zach Leatherman ***@***.***> wrote:
The awkward part of this is that the linter and transform arguments are going to be reversed. Hmm.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I agree they should not be reversed for the future, and breaking it right know, before 1.0 (or for it) is better than later. |
imho best would be to have an object for options 🤔 eleventyConfig.addLinter("my-linter", (content, { inputPath, outputPath }) => {}); that way the order doesn't matter and additional info can get added without a breaking change. PS: in my experience an options object generally better for optional infos |
any way we can help to make this happen? I mean the code change is "trivial" - so what info do we need to proceed? we now patch it for our use case... but that is of course not a long term solution 😅 |
It seems this one is needed in multiple places, breaking change(s) or not!! |
In a transform, can you not access the eleventyConfig.addTransform('myTransform', function(content, outputPath) {
console.log(this.inputPath)
}) (Not a long-term solution, I just wondered if this would work fine for now) |
Just to add a little something...
|
I actually need a different const that = this;
this.elev.config.filters['hook-for-rocket'] = function hook(html, outputPath) {
const { inputPath } = this;
return that.doSomething(inputPath);
}; thx for the workaround 🤗 but yeah no workaround would be better 😬 so fixing this would still be nice 👍 |
@TigersWay you should thank @gregives instead… 😅 |
Code is in for this. We’re using More importantly, since it seems like y’all are using them here (specifically #789 (comment)): the object key Hopefully that workaround won’t be necessary anyway with this fix. |
🚢🛳⛴🚀📦 |
That's awesome, thanks a lot Zach! 👍 |
Linters support an
inputPath
argument but transforms do nothttps://www.11ty.io/docs/config/#transforms
https://www.11ty.io/docs/config/#linters
Requested by @nhoizey https://twitter.com/nhoizey/status/1197932949708165120
The text was updated successfully, but these errors were encountered: