@blocklet/pages-kit-inner-components 0.4.104 → 0.4.106
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/lib/cjs/add-component.js +15 -15
- package/lib/cjs/chunks/home-CvupnQk0.js +36 -0
- package/lib/cjs/chunks/{publish-button-ByqPCT2Y.js → publish-button-CgvaIqqI.js} +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +4 -4
- package/lib/cjs/setting.js +3 -3
- package/lib/es/add-component.js +73 -82
- package/lib/es/chunks/home-BkhNJi9S.js +479 -0
- package/lib/es/chunks/{publish-button-OwaTBakj.js → publish-button-DiuEASJd.js} +1 -1
- package/lib/es/home.js +1 -1
- package/lib/es/project-html.js +70 -63
- package/lib/es/setting.js +779 -1036
- package/package.json +8 -8
- package/lib/cjs/chunks/home-CMaoUDJD.js +0 -36
- package/lib/es/chunks/home-BBfstt15.js +0 -470
package/lib/es/project-html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as y, b as H } from "./chunks/site-state-Bn8mEgOx.js";
|
|
2
2
|
import { initCronCrawlBlocklet as W, cancelCronCrawlBlocklet as N, initSEOMiddleware as J } from "@blocklet/crawler/middlewares";
|
|
3
3
|
import { PreloadComponentScriptModule as G } from "@blocklet/pages-kit/types";
|
|
4
4
|
import { injectPreloadComponents as K } from "@blocklet/pages-kit/utils/preload";
|
|
@@ -11,15 +11,15 @@ import X from "mustache";
|
|
|
11
11
|
import { resolve as j } from "path";
|
|
12
12
|
import { withQuery as Y, joinURL as U } from "ufo";
|
|
13
13
|
const Z = ["/assets/"], M = () => [!0, "true"].includes(a.env.preferences.allowCrawler);
|
|
14
|
-
function
|
|
14
|
+
function x() {
|
|
15
15
|
M() ? W({
|
|
16
16
|
time: "0 0 */12 * * *",
|
|
17
17
|
options: {}
|
|
18
18
|
}) : N();
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
a.events.on(a.Events.envUpdate,
|
|
22
|
-
function
|
|
20
|
+
x();
|
|
21
|
+
a.events.on(a.Events.envUpdate, x);
|
|
22
|
+
function de({
|
|
23
23
|
app: c,
|
|
24
24
|
viteDevServer: h,
|
|
25
25
|
// projectId,
|
|
@@ -27,95 +27,102 @@ function me({
|
|
|
27
27
|
}) {
|
|
28
28
|
let C;
|
|
29
29
|
if (h) {
|
|
30
|
-
const
|
|
31
|
-
c.use(async (b,
|
|
32
|
-
const
|
|
33
|
-
C = await h.transformIndexHtml(
|
|
30
|
+
const o = I(j(process.cwd(), "./index.html"), "utf-8");
|
|
31
|
+
c.use(async (f, b, v) => {
|
|
32
|
+
const $ = f.originalUrl;
|
|
33
|
+
C = await h.transformIndexHtml($, o), v();
|
|
34
34
|
});
|
|
35
35
|
} else
|
|
36
36
|
C = I(j(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const _ = V();
|
|
38
|
+
_.use(
|
|
39
|
+
(o, f, b) => {
|
|
40
|
+
if (o.headers["x-unique-record"] === "dial_http") {
|
|
41
|
+
y.info("[html] dial http request, return 200 status code"), f.status(200).send("ok");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
b();
|
|
45
|
+
},
|
|
39
46
|
J({
|
|
40
47
|
autoReturnHtml: !0,
|
|
41
48
|
allowCrawler: M
|
|
42
49
|
})
|
|
43
|
-
),
|
|
50
|
+
), _.get("/:path(*)?", async (o, f, b) => {
|
|
44
51
|
var T, E, S;
|
|
45
|
-
if (Z.some((
|
|
46
|
-
var
|
|
47
|
-
return (
|
|
52
|
+
if (Z.some((r) => {
|
|
53
|
+
var s;
|
|
54
|
+
return (s = o.path) == null ? void 0 : s.startsWith(r);
|
|
48
55
|
})) {
|
|
49
|
-
|
|
56
|
+
b();
|
|
50
57
|
return;
|
|
51
58
|
}
|
|
52
|
-
const
|
|
53
|
-
let e, p,
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
let
|
|
57
|
-
if ((!
|
|
59
|
+
const v = performance.now(), $ = () => Math.round(performance.now() - v), D = "production";
|
|
60
|
+
let e, p, g = C;
|
|
61
|
+
if (o.path.startsWith("/pages")) {
|
|
62
|
+
const r = o.params.lang, s = o.cookies.nf_lang, w = /* @__PURE__ */ new Set([...a.env.languages.map((u) => u.code)]);
|
|
63
|
+
let m = (r && w.has(r) ? r : void 0) || (w.has(s) ? s : void 0) || [...w][0];
|
|
64
|
+
if ((!m || !((T = n.supportedLocales) != null && T.find((u) => u.locale === m))) && (m = ((S = (E = n.supportedLocales) == null ? void 0 : E[0]) == null ? void 0 : S.locale) || ""), m) {
|
|
58
65
|
const u = [];
|
|
59
|
-
Object.values(n.pages).forEach((
|
|
60
|
-
const B = Object.values((
|
|
61
|
-
(
|
|
62
|
-
var
|
|
63
|
-
return
|
|
66
|
+
Object.values(n.pages).forEach((l) => {
|
|
67
|
+
const B = Object.values((l == null ? void 0 : l.sections) ?? {}).filter(
|
|
68
|
+
(i) => {
|
|
69
|
+
var k;
|
|
70
|
+
return i.component === "custom-component" && ((k = i.config) == null ? void 0 : k.componentId);
|
|
64
71
|
}
|
|
65
|
-
).map((
|
|
66
|
-
var
|
|
72
|
+
).map((i) => {
|
|
73
|
+
var k, L;
|
|
67
74
|
return {
|
|
68
|
-
id:
|
|
69
|
-
componentId:
|
|
70
|
-
useCache:
|
|
71
|
-
cacheDuration:
|
|
72
|
-
properties: (L = (
|
|
75
|
+
id: i.id,
|
|
76
|
+
componentId: i.config.componentId,
|
|
77
|
+
useCache: i.config.useCache,
|
|
78
|
+
cacheDuration: i.config.cacheDuration,
|
|
79
|
+
properties: (L = (k = i.locales) == null ? void 0 : k[m]) == null ? void 0 : L.properties
|
|
73
80
|
};
|
|
74
81
|
});
|
|
75
82
|
u.push(...B);
|
|
76
83
|
});
|
|
77
|
-
const
|
|
84
|
+
const R = new Promise((l) => {
|
|
78
85
|
setTimeout(() => {
|
|
79
|
-
|
|
86
|
+
l({});
|
|
80
87
|
}, 90 * 1e3);
|
|
81
88
|
});
|
|
82
89
|
try {
|
|
83
90
|
await Promise.race([
|
|
84
|
-
|
|
91
|
+
R,
|
|
85
92
|
H({
|
|
86
|
-
mode:
|
|
87
|
-
req:
|
|
93
|
+
mode: D,
|
|
94
|
+
req: o,
|
|
88
95
|
state: n,
|
|
89
|
-
locale:
|
|
96
|
+
locale: m,
|
|
90
97
|
instances: u,
|
|
91
98
|
module: G.UMD_FN
|
|
92
|
-
}).then((
|
|
93
|
-
|
|
99
|
+
}).then((l) => {
|
|
100
|
+
l && (p = K(l));
|
|
94
101
|
})
|
|
95
102
|
]);
|
|
96
|
-
} catch (
|
|
97
|
-
|
|
103
|
+
} catch (l) {
|
|
104
|
+
y.warn("getPreloadComponents timeout in promise race, skip inject html elements"), y.warn(l);
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
try {
|
|
102
|
-
const
|
|
103
|
-
title:
|
|
104
|
-
description:
|
|
109
|
+
const r = (e == null ? void 0 : e.title) || a.env.appName, s = (e == null ? void 0 : e.description) || a.env.appDescription, w = Y(U(a.env.appUrl, "/.well-known/service/blocklet/og.png"), {
|
|
110
|
+
title: r,
|
|
111
|
+
description: s
|
|
105
112
|
});
|
|
106
|
-
|
|
107
|
-
ogTitle:
|
|
108
|
-
ogDescription:
|
|
109
|
-
ogImage:
|
|
113
|
+
g = X.render(C, {
|
|
114
|
+
ogTitle: r,
|
|
115
|
+
ogDescription: s,
|
|
116
|
+
ogImage: q(e == null ? void 0 : e.image) || w,
|
|
110
117
|
pagesPublishedAt: (n == null ? void 0 : n.config.publishedAt) || (/* @__PURE__ */ new Date()).getTime()
|
|
111
118
|
});
|
|
112
119
|
} catch {
|
|
113
120
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
121
|
+
const t = n == null ? void 0 : n.config.fontFamily, O = o.query.mode === "draft" || o.url.includes("preview"), d = A.load(g);
|
|
122
|
+
d("head").find("#injected-head-elements").replaceWith(`
|
|
116
123
|
${e != null && e.backgroundColor ? `<meta name="theme-color" content="${e.backgroundColor}" /><style>html,body,#app {background-color: ${e.backgroundColor} !important;}</style>` : ""}
|
|
117
|
-
${
|
|
118
|
-
${
|
|
124
|
+
${t != null && t.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${t.title}&display=swap">` : ""}
|
|
125
|
+
${t != null && t.description && (t == null ? void 0 : t.description) !== (t == null ? void 0 : t.title) ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${t.description}&display=swap">` : ""}
|
|
119
126
|
<script>
|
|
120
127
|
|
|
121
128
|
window.__PAGE_STATE__ = ${JSON.stringify(n, null, 0)}
|
|
@@ -128,7 +135,7 @@ function me({
|
|
|
128
135
|
});
|
|
129
136
|
<\/script>
|
|
130
137
|
|
|
131
|
-
${
|
|
138
|
+
${O ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
132
139
|
<script>
|
|
133
140
|
window.tailwind.config = {
|
|
134
141
|
darkMode: "class",
|
|
@@ -136,17 +143,17 @@ function me({
|
|
|
136
143
|
<\/script>` : ""}
|
|
137
144
|
`);
|
|
138
145
|
const P = z();
|
|
139
|
-
if (P &&
|
|
140
|
-
const
|
|
141
|
-
|
|
146
|
+
if (P && d('script[src="__blocklet__.js"]').replaceWith(`<script>${P}<\/script>`), p != null && p.html && d("head").find("#injected-html-elements").replaceWith(p.html), o.cachedHtml) {
|
|
147
|
+
const r = A.load(o.cachedHtml);
|
|
148
|
+
d("body").html(r("body").html() || "");
|
|
142
149
|
}
|
|
143
|
-
|
|
144
|
-
}), c.use(
|
|
150
|
+
g = d.html(), f.send(g), y.info(`[html] render: ${o.path}, ${$()}ms`), d.root().children().remove(), g = null, e = null, p = null;
|
|
151
|
+
}), c.use(_);
|
|
145
152
|
}
|
|
146
|
-
function
|
|
153
|
+
function q(c) {
|
|
147
154
|
const h = Q("image-bin");
|
|
148
155
|
return h && c && !/^(https?:\/\/|\/)/.test(c) ? a.env.appUrl + U(h, "uploads", c) : c;
|
|
149
156
|
}
|
|
150
157
|
export {
|
|
151
|
-
|
|
158
|
+
de as default
|
|
152
159
|
};
|