no message
This commit is contained in:
84
.output/server/node_modules/@unhead/ssr/dist/index.mjs
generated
vendored
Normal file
84
.output/server/node_modules/@unhead/ssr/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
import { TagsWithInnerContent, SelfClosingTags } from '@unhead/shared';
|
||||
|
||||
function encodeAttribute(value) {
|
||||
return String(value).replace(/"/g, """);
|
||||
}
|
||||
function propsToString(props) {
|
||||
const attrs = [];
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (value !== false && value !== null)
|
||||
attrs.push(value === true ? key : `${key}="${encodeAttribute(value)}"`);
|
||||
}
|
||||
return `${attrs.length > 0 ? " " : ""}${attrs.join(" ")}`;
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return str.replace(/[&<>"'/]/g, (char) => {
|
||||
switch (char) {
|
||||
case "&":
|
||||
return "&";
|
||||
case "<":
|
||||
return "<";
|
||||
case ">":
|
||||
return ">";
|
||||
case '"':
|
||||
return """;
|
||||
case "'":
|
||||
return "'";
|
||||
case "/":
|
||||
return "/";
|
||||
default:
|
||||
return char;
|
||||
}
|
||||
});
|
||||
}
|
||||
function tagToString(tag) {
|
||||
const attrs = propsToString(tag.props);
|
||||
const openTag = `<${tag.tag}${attrs}>`;
|
||||
if (!TagsWithInnerContent.includes(tag.tag))
|
||||
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
||||
let content = String(tag.innerHTML || "");
|
||||
if (tag.textContent)
|
||||
content = escapeHtml(String(tag.textContent));
|
||||
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
||||
}
|
||||
|
||||
function ssrRenderTags(tags) {
|
||||
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: [], bodyClose: [], bodyOpen: [] } };
|
||||
for (const tag of tags) {
|
||||
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
|
||||
schema[tag.tag] = { ...schema[tag.tag], ...tag.props };
|
||||
continue;
|
||||
}
|
||||
schema.tags[tag.tagPosition || "head"].push(tagToString(tag));
|
||||
}
|
||||
return {
|
||||
headTags: schema.tags.head.join("\n"),
|
||||
bodyTags: schema.tags.bodyClose.join("\n"),
|
||||
bodyTagsOpen: schema.tags.bodyOpen.join("\n"),
|
||||
htmlAttrs: propsToString(schema.htmlAttrs),
|
||||
bodyAttrs: propsToString(schema.bodyAttrs)
|
||||
};
|
||||
}
|
||||
|
||||
async function renderSSRHead(head) {
|
||||
const beforeRenderCtx = { shouldRender: true };
|
||||
await head.hooks.callHook("ssr:beforeRender", beforeRenderCtx);
|
||||
if (!beforeRenderCtx.shouldRender) {
|
||||
return {
|
||||
headTags: "",
|
||||
bodyTags: "",
|
||||
bodyTagsOpen: "",
|
||||
htmlAttrs: "",
|
||||
bodyAttrs: ""
|
||||
};
|
||||
}
|
||||
const ctx = { tags: await head.resolveTags() };
|
||||
await head.hooks.callHook("ssr:render", ctx);
|
||||
const html = ssrRenderTags(ctx.tags);
|
||||
const renderCtx = { tags: ctx.tags, html };
|
||||
await head.hooks.callHook("ssr:rendered", renderCtx);
|
||||
return renderCtx.html;
|
||||
}
|
||||
|
||||
export { escapeHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
40
.output/server/node_modules/@unhead/ssr/package.json
generated
vendored
Normal file
40
.output/server/node_modules/@unhead/ssr/package.json
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "@unhead/ssr",
|
||||
"type": "module",
|
||||
"version": "1.8.8",
|
||||
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
||||
"license": "MIT",
|
||||
"funding": "https://github.com/sponsors/harlan-zw",
|
||||
"homepage": "https://unhead.unjs.io",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/unjs/unhead.git",
|
||||
"directory": "packages/ssr"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/unjs/unhead/issues"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "dist/index.cjs",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@unhead/schema": "1.8.8",
|
||||
"@unhead/shared": "1.8.8"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild .",
|
||||
"stub": "unbuild . --stub",
|
||||
"export:sizes": "npx export-size . -r"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user