-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
transformPage
#3511
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
transformPage
#3511
Comments
Thank you for pointing out how it can be done after #3384! Yes, please. This would allow for a better way to handle templating of app.html. Here's what it would look like to allow export async function handle({ event, resolve }) {
return await resolve(event, {
transformPage: ({ html }) => ejs.render(html, { foo: 'bar' }))
});
} |
I also think this would be useful. I have to do these kinds of operations in almost every SK app I build and this syntax is concise while making the intent clearer. |
Definitely very useful for my use case as well. Thanks 👍 |
Describe the problem
Until recently, the way to manipulate HTML was to do something like this in
handle
:With #3384, we're now dealing with
Response
objects meaning that you'd now do this:For all the advantages brought by using
Request
andResponse
, this does not feel like an improvement. Verbosity aside, doingawait response.text()
and creating a new response feels like a lot of overhead.Describe the proposed solution
We could do this:
Then this line...
kit/packages/kit/src/runtime/server/page/render.js
Line 218 in 0cca670
Alternatives considered
The alternative is to do nothing. It depends on whether we consider manipulating the HTML response to be 'supported' — if it's a rarely-used hack, perhaps it's not necessary, but if we consider it to be a valid and common use case then the API probably pays for itself.
Minification is one use case; injecting the correct
<html lang="...">
attribute is another (albeit one that Kit will eventually have full support for anyway). I've seen it be used for other stuff — here's a snippet from the NYT covid tracker that allows multiple Kit apps to exist on the same page......and there are doubtless other uses we can't anticipate. So I vote for its inclusion, but others might feel differently.
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: