Skip to content

Instantly share code, notes, and snippets.

@nathonius
Created December 31, 2024 02:35
Show Gist options
  • Save nathonius/f6235936d37bd42d45eb48cba72b78bc to your computer and use it in GitHub Desktop.
Save nathonius/f6235936d37bd42d45eb48cba72b78bc to your computer and use it in GitHub Desktop.
11ty preact renderer
import { render } from "preact-render-to-string";
import type { FunctionComponent } from "preact";
export default function (config) {
config.addExtension("11ty.tsx", {
getInstanceFromInputPath: async function (path) {
const module: { default: FunctionComponent } = await import(path);
return module.default;
},
compile: function (component: FunctionComponent) {
return (props) => {
const result = render(component(props));
return `<!doctype html>\n${result}`;
};
},
useJavaScriptImport: true,
outputFileExtension: "html",
});
// ...rest of your config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment