initial commit
This commit is contained in:
12
node_modules/@unhead/ssr/README.md
generated
vendored
Normal file
12
node_modules/@unhead/ssr/README.md
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# @unhead/dom
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
# yarn add @unhead/dom
|
||||
npm install @unhead/ssr
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
See the [Unhead](https://unhead.harlanzw.com/) for more details.
|
||||
62
node_modules/@unhead/ssr/dist/index.cjs
generated
vendored
Normal file
62
node_modules/@unhead/ssr/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
const SelfClosingTags = ["meta", "link", "base"];
|
||||
|
||||
const propsToString = (props) => {
|
||||
const handledAttributes = [];
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (value === false || value == null)
|
||||
continue;
|
||||
let attribute = key;
|
||||
if (value !== true)
|
||||
attribute += `="${String(value).replace(/"/g, """)}"`;
|
||||
handledAttributes.push(attribute);
|
||||
}
|
||||
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
|
||||
};
|
||||
|
||||
const tagToString = (tag) => {
|
||||
const attrs = propsToString(tag.props);
|
||||
const openTag = `<${tag.tag}${attrs}>`;
|
||||
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${tag.children || ""}</${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;
|
||||
}
|
||||
|
||||
exports.renderSSRHead = renderSSRHead;
|
||||
6
node_modules/@unhead/ssr/dist/index.d.ts
generated
vendored
Normal file
6
node_modules/@unhead/ssr/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Unhead, SSRHeadPayload } from '@unhead/schema';
|
||||
export { SSRHeadPayload } from '@unhead/schema';
|
||||
|
||||
declare function renderSSRHead<T extends {}>(head: Unhead<T>): Promise<SSRHeadPayload>;
|
||||
|
||||
export { renderSSRHead };
|
||||
60
node_modules/@unhead/ssr/dist/index.mjs
generated
vendored
Normal file
60
node_modules/@unhead/ssr/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
const SelfClosingTags = ["meta", "link", "base"];
|
||||
|
||||
const propsToString = (props) => {
|
||||
const handledAttributes = [];
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (value === false || value == null)
|
||||
continue;
|
||||
let attribute = key;
|
||||
if (value !== true)
|
||||
attribute += `="${String(value).replace(/"/g, """)}"`;
|
||||
handledAttributes.push(attribute);
|
||||
}
|
||||
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
|
||||
};
|
||||
|
||||
const tagToString = (tag) => {
|
||||
const attrs = propsToString(tag.props);
|
||||
const openTag = `<${tag.tag}${attrs}>`;
|
||||
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${tag.children || ""}</${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 { renderSSRHead };
|
||||
43
node_modules/@unhead/ssr/package.json
generated
vendored
Normal file
43
node_modules/@unhead/ssr/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@unhead/ssr",
|
||||
"type": "module",
|
||||
"version": "1.0.14",
|
||||
"packageManager": "pnpm@7.19.0",
|
||||
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
||||
"license": "MIT",
|
||||
"funding": "https://github.com/sponsors/harlan-zw",
|
||||
"homepage": "https://github.com/harlan-zw/unhead#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/harlan-zw/unhead.git",
|
||||
"directory": "packages/ssr"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/harlan-zw/unhead/issues"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs"
|
||||
}
|
||||
},
|
||||
"main": "dist/index.cjs",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@unhead/schema": "1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"zhead": "^1.0.9"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild .",
|
||||
"stub": "unbuild . --stub",
|
||||
"export:sizes": "npx export-size . -r"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user