UNPKG

radish

Version:

Radish is a React-based static site generator that outputs plain HTML and CSS.

28 lines (27 loc) 1.02 kB
import { createElement } from "react"; import { renderToStaticMarkup } from "react-dom/server"; export default function render(page, props) { const markup = renderToStaticMarkup(createElement(page.default, props)).replace(/<radish:noop><\/radish:noop>/g, ""); if (page.layout === false) return markup; return html(markup, page.head.helmet); } function html(markup, helmet) { const html = helmet.htmlAttributes.toString(); const body = helmet.bodyAttributes.toString(); return [ `<!DOCTYPE html>`, `<html${html.length ? " " + html : ""}>`, ` <head>`, ` ` + helmet.title.toString().replace(rh, ""), ` ` + helmet.meta.toString().replace(rh, ""), ` ` + helmet.link.toString().replace(rh, ""), ` ` + helmet.script.toString().replace(rh, ""), ` </head>`, ` <body ${body.length ? " " + body : ""}>`, markup, ` </body>`, `</html>` ].join("\n"); } const rh = / data-rh="true"/g;