-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added template transform api and changed documentation #641
Added template transform api and changed documentation #641
Conversation
This seems fairly reasonable to me. My only suggestion is that it'd be nice to have a test |
I have added a basic test, but seems like i did something wrong. It works locally.. |
looks like it was just a flaky test. I kicked the tests off again and they're all passing now |
Thanks for the PR. Over on #334 (comment) we've been discussing making it easier to add custom logic to the main request handler, in such a way that you could do this: // src/hooks.js
import cookie from 'cookie';
export function getContext({ headers }) {
return {
dark: cookie.parse(headers.cookie).dark === 'true'
}
}
export function handle(request, render) {
const rendered = render(request); // { status, headers, body }
if (rendered.headers['content-type'] === 'text/html') {
return {
...rendered,
body: rendered.body.replace('%My.HtmlClass%', request.context.dark ? 'dark' : 'light')
};
}
return rendered;
} This is slightly lower-level than What do you think? |
I think the API in #334 (comment) should cover all the use cases this would cover. Perhaps to future-proof it, the API should be |
Sounds fairly reasonable to me, I like this approach even better. |
Im closing this in favor of #670 |
Before submitting the PR, please make sure you do the following
I couldn't find any issue or milestone about transforming the app.html template as requested in #1642 and 1695.
This opens up for stuff like adding classes to the html element or changing the language attribute.
It would be really useful for tailwind darkmode or theming in general, adding csrf token on a meta tag etc.
Im open for any changes to this, its also okay if you don't consider this right now it would just help me adding proper darkmode to my project without setting it on the client with javascript.
Tests
pnpm test
and lint the project withpnpm lint
I don't really know how to write tests for this atm.
Changesets
pnpx changeset
and following the prompts