@unhead/ssr 1.0.21 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +14 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.mjs +11 -3
- package/package.json +7 -9
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const shared = require('@unhead/shared');
|
|
4
4
|
|
|
5
5
|
const propsToString = (props) => {
|
|
6
6
|
const handledAttributes = [];
|
|
@@ -15,10 +15,18 @@ const propsToString = (props) => {
|
|
|
15
15
|
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
function encodeHtmlEntities(str) {
|
|
19
|
+
return str.replace(/[\u00A0-\u9999<>\&]/gim, (i) => `&#${i.charCodeAt(0)};`);
|
|
20
|
+
}
|
|
18
21
|
const tagToString = (tag) => {
|
|
19
22
|
const attrs = propsToString(tag.props);
|
|
20
23
|
const openTag = `<${tag.tag}${attrs}>`;
|
|
21
|
-
|
|
24
|
+
if (!shared.TagsWithInnerContent.includes(tag.tag))
|
|
25
|
+
return shared.SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
26
|
+
let content = tag.children || "";
|
|
27
|
+
if (content && tag.tag === "title")
|
|
28
|
+
content = encodeHtmlEntities(content);
|
|
29
|
+
return shared.SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
22
30
|
};
|
|
23
31
|
|
|
24
32
|
function ssrRenderTags(tags) {
|
|
@@ -59,4 +67,8 @@ async function renderSSRHead(head) {
|
|
|
59
67
|
return renderCtx.html;
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
exports.encodeHtmlEntities = encodeHtmlEntities;
|
|
71
|
+
exports.propsToString = propsToString;
|
|
62
72
|
exports.renderSSRHead = renderSSRHead;
|
|
73
|
+
exports.ssrRenderTags = ssrRenderTags;
|
|
74
|
+
exports.tagToString = tagToString;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import { Unhead, SSRHeadPayload } from '@unhead/schema';
|
|
1
|
+
import { Unhead, SSRHeadPayload, HeadTag } from '@unhead/schema';
|
|
2
2
|
export { SSRHeadPayload } from '@unhead/schema';
|
|
3
3
|
|
|
4
4
|
declare function renderSSRHead<T extends {}>(head: Unhead<T>): Promise<SSRHeadPayload>;
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
declare const propsToString: (props: Record<string, any>) => string;
|
|
7
|
+
|
|
8
|
+
declare function encodeHtmlEntities(str: string): string;
|
|
9
|
+
declare const tagToString: <T extends HeadTag>(tag: T) => string;
|
|
10
|
+
|
|
11
|
+
declare function ssrRenderTags<T extends HeadTag>(tags: T[]): {
|
|
12
|
+
headTags: string;
|
|
13
|
+
bodyTags: string;
|
|
14
|
+
bodyTagsOpen: string;
|
|
15
|
+
htmlAttrs: string;
|
|
16
|
+
bodyAttrs: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { encodeHtmlEntities, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { TagsWithInnerContent, SelfClosingTags } from '@unhead/shared';
|
|
2
2
|
|
|
3
3
|
const propsToString = (props) => {
|
|
4
4
|
const handledAttributes = [];
|
|
@@ -13,10 +13,18 @@ const propsToString = (props) => {
|
|
|
13
13
|
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
function encodeHtmlEntities(str) {
|
|
17
|
+
return str.replace(/[\u00A0-\u9999<>\&]/gim, (i) => `&#${i.charCodeAt(0)};`);
|
|
18
|
+
}
|
|
16
19
|
const tagToString = (tag) => {
|
|
17
20
|
const attrs = propsToString(tag.props);
|
|
18
21
|
const openTag = `<${tag.tag}${attrs}>`;
|
|
19
|
-
|
|
22
|
+
if (!TagsWithInnerContent.includes(tag.tag))
|
|
23
|
+
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
24
|
+
let content = tag.children || "";
|
|
25
|
+
if (content && tag.tag === "title")
|
|
26
|
+
content = encodeHtmlEntities(content);
|
|
27
|
+
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
20
28
|
};
|
|
21
29
|
|
|
22
30
|
function ssrRenderTags(tags) {
|
|
@@ -57,4 +65,4 @@ async function renderSSRHead(head) {
|
|
|
57
65
|
return renderCtx.html;
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
export { renderSSRHead };
|
|
68
|
+
export { encodeHtmlEntities, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"packageManager": "pnpm@7.
|
|
4
|
+
"version": "1.0.22",
|
|
5
|
+
"packageManager": "pnpm@7.26.3",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
9
|
-
"homepage": "https://
|
|
9
|
+
"homepage": "https://unhead.harlanzw.com",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
12
|
+
"url": "git+https://github.com/unjs/unhead.git",
|
|
13
13
|
"directory": "packages/ssr"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/unjs/unhead/issues"
|
|
17
17
|
},
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"exports": {
|
|
@@ -30,10 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/schema": "1.0.
|
|
34
|
-
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"zhead": "^1.1.0"
|
|
33
|
+
"@unhead/schema": "1.0.22",
|
|
34
|
+
"@unhead/shared": "1.0.22"
|
|
37
35
|
},
|
|
38
36
|
"scripts": {
|
|
39
37
|
"build": "unbuild .",
|