2022-03-18 22:35:45 +00: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 15:10:54 +00:00
|
|
|
async function renderToStaticMarkup(Component, props, slotted) {
|
2022-03-18 22:35:45 +00:00
|
|
|
const slots = {};
|
2022-06-23 15:10:54 +00:00
|
|
|
for (const [key, value] of Object.entries(slotted)) {
|
|
|
|
slots[key] = () => h(StaticHtml, { value, name: key === 'default' ? undefined : key });
|
2022-03-18 22:35:45 +00:00
|
|
|
}
|
|
|
|
const app = createSSRApp({ render: () => h(Component, props, slots) });
|
|
|
|
const html = await renderToString(app);
|
|
|
|
return { html };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
|
|
|
};
|