@ubean/pages 0.1.11 → 0.1.13
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.d.ts +2 -0
- package/dist/index.js +31 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -27,6 +27,33 @@ function pageJsonResponse(pageObj, headers = {}) {
|
|
|
27
27
|
function escapeAttr(str) {
|
|
28
28
|
return str.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<");
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* 根据文件扩展名推断 favicon 的 MIME type。
|
|
32
|
+
* SVG 必须显式声明 `type="image/svg+xml"`,否则部分浏览器不会渲染;
|
|
33
|
+
* 其他类型浏览器可从 URL 自动推断,但显式声明更规范。
|
|
34
|
+
*/
|
|
35
|
+
function faviconMimeType(href) {
|
|
36
|
+
switch (href.split(".").pop()?.toLowerCase()) {
|
|
37
|
+
case "svg": return "image/svg+xml";
|
|
38
|
+
case "ico": return "image/x-icon";
|
|
39
|
+
case "png": return "image/png";
|
|
40
|
+
case "jpg":
|
|
41
|
+
case "jpeg": return "image/jpeg";
|
|
42
|
+
case "gif": return "image/gif";
|
|
43
|
+
case "webp": return "image/webp";
|
|
44
|
+
default: return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 生成 favicon `<link>` 标签字符串。
|
|
49
|
+
* 当 `favicon` 为空/未设置时返回空字符串。
|
|
50
|
+
*/
|
|
51
|
+
function renderFaviconLink(favicon) {
|
|
52
|
+
if (!favicon) return "";
|
|
53
|
+
const type = faviconMimeType(favicon);
|
|
54
|
+
const typeAttr = type ? ` type="${escapeAttr(type)}"` : "";
|
|
55
|
+
return `<link rel="icon" href="${escapeAttr(favicon)}"${typeAttr}>`;
|
|
56
|
+
}
|
|
30
57
|
function renderHeadTags(head) {
|
|
31
58
|
if (!head) return {
|
|
32
59
|
headTags: "",
|
|
@@ -60,6 +87,7 @@ function buildPageShell(pageObj, assetTags, preambleScript = "", appId = "app",
|
|
|
60
87
|
const css = assetTags.css ?? "";
|
|
61
88
|
const preloads = assetTags.preloads ?? "";
|
|
62
89
|
const bodyTags = assetTags.body ?? "";
|
|
90
|
+
const faviconLink = renderFaviconLink(assetTags.favicon);
|
|
63
91
|
const locale = renderContext?.locale;
|
|
64
92
|
const localeDir = renderContext?.localeDir || "ltr";
|
|
65
93
|
const messages = renderContext?.messages;
|
|
@@ -81,7 +109,7 @@ function buildPageShell(pageObj, assetTags, preambleScript = "", appId = "app",
|
|
|
81
109
|
return `<!doctype html>
|
|
82
110
|
<html${finalHtmlAttrs ? ` ${finalHtmlAttrs}` : ""}>
|
|
83
111
|
<head>
|
|
84
|
-
${headTags ? `${headTags}\n ` : ""}${css}${preloads}
|
|
112
|
+
${faviconLink ? `${faviconLink}\n ` : ""}${headTags ? `${headTags}\n ` : ""}${css}${preloads}
|
|
85
113
|
</head>
|
|
86
114
|
<body${finalBodyAttrs ? ` ${finalBodyAttrs}` : ""}>
|
|
87
115
|
${localeScript}
|
|
@@ -113,6 +141,7 @@ function buildClientOnlyShell(pageObj, assetTags, preambleScript = "", appId = "
|
|
|
113
141
|
const css = assetTags.css ?? "";
|
|
114
142
|
const preloads = assetTags.preloads ?? "";
|
|
115
143
|
const bodyTags = assetTags.body ?? "";
|
|
144
|
+
const faviconLink = renderFaviconLink(assetTags.favicon);
|
|
116
145
|
const locale = renderContext?.locale;
|
|
117
146
|
const localeDir = renderContext?.localeDir || "ltr";
|
|
118
147
|
const messages = renderContext?.messages;
|
|
@@ -134,7 +163,7 @@ function buildClientOnlyShell(pageObj, assetTags, preambleScript = "", appId = "
|
|
|
134
163
|
return `<!doctype html>
|
|
135
164
|
<html${finalHtmlAttrs ? ` ${finalHtmlAttrs}` : ""}>
|
|
136
165
|
<head>
|
|
137
|
-
${headTags ? `${headTags}\n ` : ""}${preambleScript}${css}${preloads}
|
|
166
|
+
${faviconLink ? `${faviconLink}\n ` : ""}${headTags ? `${headTags}\n ` : ""}${preambleScript}${css}${preloads}
|
|
138
167
|
</head>
|
|
139
168
|
<body${finalBodyAttrs ? ` ${finalBodyAttrs}` : ""}>
|
|
140
169
|
${localeScript}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/pages",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Page data protocol and isomorphic data layer for ubean (PageObject, useData, invalidateData)",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ubean/types": "0.1.
|
|
19
|
+
"@ubean/types": "0.1.13"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^26.1.2",
|