70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
33 lines
799 B
TypeScript
33 lines
799 B
TypeScript
import type { PluginArgs } from "..";
|
|
|
|
type ExamplePagesPluginFunction<
|
|
Env = unknown,
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
Params extends string = any,
|
|
Data extends Record<string, unknown> = Record<string, unknown>,
|
|
> = PagesPluginFunction<Env, Params, Data, PluginArgs>;
|
|
|
|
class BodyHandler {
|
|
footerText: string;
|
|
|
|
constructor({ footerText }) {
|
|
this.footerText = footerText;
|
|
}
|
|
|
|
element(element) {
|
|
// Don't actually set HTML like this!
|
|
element.append(`<footer>${this.footerText}</footer>`, { html: true });
|
|
}
|
|
}
|
|
|
|
export const onRequest: ExamplePagesPluginFunction = async ({
|
|
next,
|
|
pluginArgs,
|
|
}) => {
|
|
const response = await next();
|
|
|
|
return new HTMLRewriter()
|
|
.on("body", new BodyHandler({ footerText: pluginArgs.footerText }))
|
|
.transform(response);
|
|
};
|