-
Notifications
You must be signed in to change notification settings - Fork 19
How to use post-processing functions? #319
Comments
like here: https://github.com/adobe/helix-pipeline#using-extension-points ? or what do you want to do? |
@filmaj you can find a real-life example here: https://github.com/adobe/helix-cli/blob/9b1b05c80f9976cb83c0331278e0109af3944572/test/integration/src/html.pre.js#L98-L110 The list of extension points that you can hook in |
Thanks! I don't know how I missed the text in common extension points... What I'm trying to do: Instead of loading all of spectrum-css's SVG icons in one massive go as part of our current global HTML template, I want to post-process HTML in the global HTML template, search through the HTML and find which spectrum-css icons are used, and inject only the ones being used into the DOM. We are thinking this would improve loading times. |
The optimal extension point for that might not yet be exposed. It would be here: helix-pipeline/src/defaults/html.pipe.js Line 69 in 17e9060
|
@trieloff Any timeline for having that I tried playing with the existing common extension points you mention above, yesterday. In our global template, they all seem to execute before the |
@ryanbetts as soon as #324 is merged ;) |
@trieloff Music to my ears! Thx. |
@trieloff Looking at the contents of the payload in the Here's where I've looked:
Am I just looking in the wrong spot? |
I think, it's in helix-pipeline/src/html/html-to-hast.js Line 20 in e9bb5ac
|
@tripodsan That object is not empty, but seems to also be incomplete. I'm still unfamiliar with working with these When I do that with the the |
I don't think you go back to vdom again. I think the hast is meant to last-minute cleanup. btw:
hmm, I think there is a misconception. the response from the esi:includes are not incorporated into the response of the htl that includes them during the pipeline, this is an operation that happens on the (edge) server. the idea is, that the esi:included responses are cacheable independent. if you really need to perform an operation on the very final dom, then there is no other way as to do it clientside. |
Thanks for the speedy replies! I think I need to spend some more time in Helix school. Okay, so if I'm following you correctly: So, if we wanted to have something that was run for every template, we have 3 options:
Am I correct that number (3) is an option? |
yes, you can provide your own pipeline, via a I would keep your cleanup-function in a helper, and then add it to every template. something like: /src/cleanup.js module.exports = (context, action) => { ... cleanup code ... }. /src/footer.html.pre.js module.after = { hast: require('./cleanup.js') }; |
Gotcha. Thanks! |
@tripodsan Still quite confused as to what I should be doing with the HAST. Is there any documentation on how to work with that format? |
I'm not too familiar myself. @trieloff might know more. |
@ryanbetts you can find a short introduction to the format here: https://github.com/syntax-tree/hast (it's a lightweight representation of the HTML syntax tree with a focus on ease of transformation, embedded into the unifiedjs ecosystem – i.e. the same stuff we use for Markdown handling) There is a long list utilities specifically for HAST and another list of utilities for all unified syntax trees that make working with HAST really easy. The most useful are:
|
@trieloff This is great, thx! Between this list and examples in your source I think I'm off to the races. |
@ryanbetts please note that we made |
Duly noted. Will refactor to that now. Thx! |
Can this be closed? |
The readme mentions it, but I'm not sure how to assemble it. pre.js seems to magically work based on the filename and export names? I tried copying a working pre.js I have and renaming it to post.js, and renaming the exports to post, but that didn't work.
The text was updated successfully, but these errors were encountered: