2022-03-18 17:35:45 -05:00
|
|
|
import { h, createSSRApp } from 'vue';
|
|
|
|
import { renderToString } from 'vue/server-renderer';
|
|
|
|
import StaticHtml from './static-html.js';
|
|
|
|
|
|
|
|
function check(Component) {
|
|
|
|
return !!Component['ssrRender'];
|
|
|
|
}
|
|
|
|
|
2022-06-23 10:10:54 -05:00
|
|
|
async function renderToStaticMarkup(Component, props, slotted) {
|
2022-03-18 17:35:45 -05:00
|
|
|
const slots = {};
|
2022-06-23 10:10:54 -05:00
|
|
|
for (const [key, value] of Object.entries(slotted)) {
|
|
|
|
slots[key] = () => h(StaticHtml, { value, name: key === 'default' ? undefined : key });
|
2022-03-18 17:35:45 -05:00
|
|
|
}
|
|
|
|
const app = createSSRApp({ render: () => h(Component, props, slots) });
|
|
|
|
const html = await renderToString(app);
|
|
|
|
return { html };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
|
|
|
};
|