Created
December 31, 2024 02:35
-
-
Save nathonius/f6235936d37bd42d45eb48cba72b78bc to your computer and use it in GitHub Desktop.
11ty preact renderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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