mirror of
https://github.com/gosticks/fresh.git
synced 2026-07-01 13:50:03 +00:00
This commit adds initial support for fresh "plugins". These are bundles of functionality that can be added to a fresh plugin through a simple addition in the `main.ts` file. Right now plugins are only able to hook into the render steps. This means that they can inject styling and scripts. They can not yet hook into routing. Things that I think should be possible now: - styling integrations for twind, unocss, and probably a few other tools Things that are not possible yet: - google analytics middleware - database connectors - CMS connectors The routing additions to plugins can be added in a follow-up though.
19 lines
417 B
TypeScript
19 lines
417 B
TypeScript
import { Plugin } from "$fresh/server.ts";
|
|
|
|
let CSS_TO_INJECT = "";
|
|
export function inject(cssText: string) {
|
|
CSS_TO_INJECT = cssText;
|
|
}
|
|
|
|
export default {
|
|
name: "css-inject",
|
|
render(ctx) {
|
|
CSS_TO_INJECT = "";
|
|
const res = ctx.render();
|
|
if (res.requiresHydration) {
|
|
CSS_TO_INJECT += " h1 { color: blue; }";
|
|
}
|
|
return { styles: [{ cssText: CSS_TO_INJECT, id: "abc" }] };
|
|
},
|
|
} as Plugin;
|