You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
972 B

{{#SSR}}
let ssr = {};
// remove when client bundle umi.js
if (process.env.__IS_SERVER) {
ssr = {
modifyServerHTML: (html, { cheerio }) => {
const { Helmet } = require('{{{ HelmetPkg }}}');
const helmet = Helmet.renderStatic();
if (!helmet) return html;
const title = helmet.title.toString();
const htmlAttributes = helmet.htmlAttributes.toComponent();
const meta = helmet.meta.toString();
const link = helmet.link.toString();
const $ = cheerio.load(html, {
decodeEntities: false,
});
if (title) {
$('head').prepend(title);
}
if (meta) {
$('head').append(meta);
}
if (link) {
$('link').append(link);
}
if (Object.keys(htmlAttributes)) {
Object.keys(htmlAttributes).forEach(attrKey => {
$('html').attr(attrKey, htmlAttributes[attrKey]);
});
}
return $.html();
}
};
}
export {
ssr
};
{{/SSR}}