@blocklet/pages-kit-inner-components 0.4.25 → 0.4.26
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/project-html.js +8 -3
- package/lib/es/project-html.js +54 -49
- package/package.json +3 -3
package/lib/cjs/project-html.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
"use strict";const N=require("vite-plugin-node-polyfills/shims/process"),_=require("./_chunks/site-state-DNRKik3e.js"),P=require("@blocklet/crawler/middlewares"),
|
|
1
|
+
"use strict";const N=require("vite-plugin-node-polyfills/shims/process"),_=require("./_chunks/site-state-DNRKik3e.js"),P=require("@blocklet/crawler/middlewares"),G=require("@blocklet/pages-kit/types"),J=require("@blocklet/pages-kit/utils/preload"),W=require("@blocklet/sdk/lib/component"),R=require("@blocklet/sdk/lib/config"),K=require("express"),M=require("fs"),Q=require("mustache"),x=require("path"),S=require("ufo"),T=o=>o&&o.__esModule?o:{default:o},U=T(N),p=T(R),z=T(Q),V=["/assets/"],q=()=>[!0,"true"].includes(p.default.env.preferences.allowCrawler);function D(){q()?P.initCronCrawlBlocklet({time:"30 30 */12 * * *",options:{}}):P.cancelCronCrawlBlocklet()}D();p.default.events.on(p.default.Events.envUpdate,D);function X({app:o,viteDevServer:g,state:c}){let w;if(g){const n=M.readFileSync(x.resolve(U.default.cwd(),"./index.html"),"utf-8");o.use(async(C,v,k)=>{const b=C.originalUrl;w=await g.transformIndexHtml(b,n),k()})}else w=M.readFileSync(x.resolve(U.default.env.BLOCKLET_APP_DIR,"dist/index.html"),"utf-8");const y=K.Router();y.use(P.initSEOMiddleware({autoReturnHtml:!1,allowCrawler:q})),y.get("/:path(*)?",async(n,C,v)=>{var $,L,j;if(V.some(r=>n.path.startsWith(r))){v();return}const k=performance.now(),b=()=>Math.round(performance.now()-k),O="production";let e,u,s=w;if(n.path.startsWith("/pages")){const r=n.params.lang,i=n.cookies.nf_lang,d=new Set([...p.default.env.languages.map(f=>f.code)]);let m=(r&&d.has(r)?r:void 0)||(d.has(i)?i:void 0)||[...d][0];if((!m||!(($=c.supportedLocales)!=null&&$.find(f=>f.locale===m)))&&(m=((j=(L=c.supportedLocales)==null?void 0:L[0])==null?void 0:j.locale)||""),m){const f=[];Object.values(c.pages).forEach(l=>{const E=Object.values((l==null?void 0:l.sections)??{}).filter(a=>{var h;return a.component==="custom-component"&&((h=a.config)==null?void 0:h.componentId)}).map(a=>{var h,I;return{id:a.id,componentId:a.config.componentId,useCache:a.config.useCache,cacheDuration:a.config.cacheDuration,properties:(I=(h=a.locales)==null?void 0:h[m])==null?void 0:I.properties}});f.push(...E)});const H=new Promise((l,E)=>{setTimeout(()=>{E(new Error("getPreloadComponents timeout in promise race, skip it"))},90*1e3)});try{await Promise.race([H,_.getPreloadComponents({mode:O,req:n,state:c,locale:m,instances:f,module:G.PreloadComponentScriptModule.UMD_FN}).then(l=>{l&&(u=J.injectPreloadComponents(l))})])}catch(l){_.logger.warn("getPreloadComponents timeout in promise race, skip inject html elements"),_.logger.warn(l)}}}try{const r=(e==null?void 0:e.title)||p.default.env.appName,i=(e==null?void 0:e.description)||p.default.env.appDescription,d=S.withQuery(S.joinURL(p.default.env.appUrl,"/.well-known/service/blocklet/og.png"),{title:r,description:i});s=z.default.render(w,{ogTitle:r,ogDescription:i,ogImage:Y(e==null?void 0:e.image)||d,pagesPublishedAt:(c==null?void 0:c.config.publishedAt)||new Date().getTime()})}catch{}const t=c==null?void 0:c.config.fontFamily,B=n.query.mode==="draft"||n.url.includes("preview");s=s.replace('<script id="injected-head-elements"><\/script>',`
|
|
2
2
|
${e!=null&&e.backgroundColor?`<meta name="theme-color" content="${e.backgroundColor}" /><style>html,body,#app {background-color: ${e.backgroundColor} !important;}</style>`:""}
|
|
3
3
|
${t!=null&&t.title?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${t.title}&display=swap">`:""}
|
|
4
4
|
${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">`:""}
|
|
5
|
+
|
|
6
|
+
<script type="application/json" id="__PAGE_STATE__">
|
|
7
|
+
${JSON.stringify(c).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026")}
|
|
8
|
+
<\/script>
|
|
9
|
+
|
|
5
10
|
<script>
|
|
6
11
|
|
|
7
|
-
window.__PAGE_STATE__ =
|
|
12
|
+
window.__PAGE_STATE__ = JSON.parse(document.getElementById('__PAGE_STATE__').textContent)
|
|
8
13
|
|
|
9
14
|
document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
|
|
10
15
|
const l = document.createElement('link');
|
|
@@ -20,4 +25,4 @@
|
|
|
20
25
|
darkMode: "class",
|
|
21
26
|
};
|
|
22
27
|
<\/script>`:""}
|
|
23
|
-
`);const
|
|
28
|
+
`);const A=R.getBlockletJs();if(A&&(s=s.replace('<script src="__blocklet__.js"><\/script>',`<script>${A}<\/script>`)),u!=null&&u.html&&(s=s.replace('<script id="injected-html-elements"><\/script>',u.html)),n.cachedHtml){const r=/<body>([\s\S]*?)<\/body>/,i=r.exec(n.cachedHtml),d=i?i[1]:"";s=s.replace(r,`<body>${d}</body>`)}C.send(s),_.logger.info(`[html] render: ${n.path}, ${b()}ms`),s=null,e=null,u=null}),o.use(y)}function Y(o){const g=W.getComponentMountPoint("image-bin");return g&&o&&!/^(https?:\/\/|\/)/.test(o)?p.default.env.appUrl+S.joinURL(g,"uploads",o):o}module.exports=X;
|
package/lib/es/project-html.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { b as
|
|
3
|
-
import { initCronCrawlBlocklet as H, cancelCronCrawlBlocklet as N, initSEOMiddleware as
|
|
4
|
-
import { PreloadComponentScriptModule as
|
|
1
|
+
import I from "vite-plugin-node-polyfills/shims/process";
|
|
2
|
+
import { b as D, l as E } from "./_chunks/site-state-B0nM69Rk.js";
|
|
3
|
+
import { initCronCrawlBlocklet as H, cancelCronCrawlBlocklet as N, initSEOMiddleware as G } from "@blocklet/crawler/middlewares";
|
|
4
|
+
import { PreloadComponentScriptModule as J } from "@blocklet/pages-kit/types";
|
|
5
5
|
import { injectPreloadComponents as W } from "@blocklet/pages-kit/utils/preload";
|
|
6
6
|
import { getComponentMountPoint as K } from "@blocklet/sdk/lib/component";
|
|
7
7
|
import p, { getBlockletJs as Q } from "@blocklet/sdk/lib/config";
|
|
8
8
|
import { Router as z } from "express";
|
|
9
|
-
import { readFileSync as
|
|
9
|
+
import { readFileSync as L } from "fs";
|
|
10
10
|
import V from "mustache";
|
|
11
11
|
import { resolve as j } from "path";
|
|
12
|
-
import { withQuery as X, joinURL as
|
|
13
|
-
const Y = ["/assets/"],
|
|
14
|
-
function
|
|
15
|
-
|
|
12
|
+
import { withQuery as X, joinURL as x } from "ufo";
|
|
13
|
+
const Y = ["/assets/"], M = () => [!0, "true"].includes(p.env.preferences.allowCrawler);
|
|
14
|
+
function U() {
|
|
15
|
+
M() ? H({
|
|
16
16
|
time: "30 30 */12 * * *",
|
|
17
17
|
options: {}
|
|
18
18
|
}) : N();
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
p.events.on(p.Events.envUpdate,
|
|
20
|
+
U();
|
|
21
|
+
p.events.on(p.Events.envUpdate, U);
|
|
22
22
|
function me({
|
|
23
23
|
app: s,
|
|
24
|
-
viteDevServer:
|
|
24
|
+
viteDevServer: g,
|
|
25
25
|
// projectId,
|
|
26
26
|
state: n
|
|
27
27
|
}) {
|
|
28
28
|
let w;
|
|
29
|
-
if (
|
|
30
|
-
const t =
|
|
31
|
-
s.use(async (
|
|
32
|
-
const
|
|
33
|
-
w = await
|
|
29
|
+
if (g) {
|
|
30
|
+
const t = L(j(I.cwd(), "./index.html"), "utf-8");
|
|
31
|
+
s.use(async (C, P, y) => {
|
|
32
|
+
const k = C.originalUrl;
|
|
33
|
+
w = await g.transformIndexHtml(k, t), y();
|
|
34
34
|
});
|
|
35
35
|
} else
|
|
36
|
-
w =
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
w = L(j(I.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
37
|
+
const _ = z();
|
|
38
|
+
_.use(
|
|
39
|
+
G({
|
|
40
40
|
autoReturnHtml: !1,
|
|
41
|
-
allowCrawler:
|
|
41
|
+
allowCrawler: M
|
|
42
42
|
})
|
|
43
|
-
),
|
|
44
|
-
var
|
|
43
|
+
), _.get("/:path(*)?", async (t, C, P) => {
|
|
44
|
+
var S, v, A;
|
|
45
45
|
if (Y.some((c) => t.path.startsWith(c))) {
|
|
46
46
|
P();
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
49
|
+
const y = performance.now(), k = () => Math.round(performance.now() - y), O = "production";
|
|
50
50
|
let e, d, r = w;
|
|
51
51
|
if (t.path.startsWith("/pages")) {
|
|
52
52
|
const c = t.params.lang, i = t.cookies.nf_lang, m = /* @__PURE__ */ new Set([...p.env.languages.map((f) => f.code)]);
|
|
53
53
|
let u = (c && m.has(c) ? c : void 0) || (m.has(i) ? i : void 0) || [...m][0];
|
|
54
|
-
if ((!u || !((
|
|
54
|
+
if ((!u || !((S = n.supportedLocales) != null && S.find((f) => f.locale === u))) && (u = ((A = (v = n.supportedLocales) == null ? void 0 : v[0]) == null ? void 0 : A.locale) || ""), u) {
|
|
55
55
|
const f = [];
|
|
56
56
|
Object.values(n.pages).forEach((l) => {
|
|
57
|
-
const
|
|
57
|
+
const b = Object.values((l == null ? void 0 : l.sections) ?? {}).filter(
|
|
58
58
|
(a) => {
|
|
59
|
-
var
|
|
60
|
-
return a.component === "custom-component" && ((
|
|
59
|
+
var h;
|
|
60
|
+
return a.component === "custom-component" && ((h = a.config) == null ? void 0 : h.componentId);
|
|
61
61
|
}
|
|
62
62
|
).map((a) => {
|
|
63
|
-
var
|
|
63
|
+
var h, $;
|
|
64
64
|
return {
|
|
65
65
|
id: a.id,
|
|
66
66
|
componentId: a.config.componentId,
|
|
67
67
|
useCache: a.config.useCache,
|
|
68
68
|
cacheDuration: a.config.cacheDuration,
|
|
69
|
-
properties: (
|
|
69
|
+
properties: ($ = (h = a.locales) == null ? void 0 : h[u]) == null ? void 0 : $.properties
|
|
70
70
|
};
|
|
71
71
|
});
|
|
72
|
-
f.push(...
|
|
72
|
+
f.push(...b);
|
|
73
73
|
});
|
|
74
|
-
const
|
|
74
|
+
const B = new Promise((l, b) => {
|
|
75
75
|
setTimeout(() => {
|
|
76
|
-
|
|
76
|
+
b(new Error("getPreloadComponents timeout in promise race, skip it"));
|
|
77
77
|
}, 90 * 1e3);
|
|
78
78
|
});
|
|
79
79
|
try {
|
|
80
80
|
await Promise.race([
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
mode:
|
|
81
|
+
B,
|
|
82
|
+
D({
|
|
83
|
+
mode: O,
|
|
84
84
|
req: t,
|
|
85
85
|
state: n,
|
|
86
86
|
locale: u,
|
|
87
87
|
instances: f,
|
|
88
|
-
module:
|
|
88
|
+
module: J.UMD_FN
|
|
89
89
|
}).then((l) => {
|
|
90
90
|
l && (d = W(l));
|
|
91
91
|
})
|
|
92
92
|
]);
|
|
93
93
|
} catch (l) {
|
|
94
|
-
|
|
94
|
+
E.warn("getPreloadComponents timeout in promise race, skip inject html elements"), E.warn(l);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
try {
|
|
99
|
-
const c = (e == null ? void 0 : e.title) || p.env.appName, i = (e == null ? void 0 : e.description) || p.env.appDescription, m = X(
|
|
99
|
+
const c = (e == null ? void 0 : e.title) || p.env.appName, i = (e == null ? void 0 : e.description) || p.env.appDescription, m = X(x(p.env.appUrl, "/.well-known/service/blocklet/og.png"), {
|
|
100
100
|
title: c,
|
|
101
101
|
description: i
|
|
102
102
|
});
|
|
@@ -108,16 +108,21 @@ function me({
|
|
|
108
108
|
});
|
|
109
109
|
} catch {
|
|
110
110
|
}
|
|
111
|
-
const o = n == null ? void 0 : n.config.fontFamily,
|
|
111
|
+
const o = n == null ? void 0 : n.config.fontFamily, R = t.query.mode === "draft" || t.url.includes("preview");
|
|
112
112
|
r = r.replace(
|
|
113
113
|
'<script id="injected-head-elements"><\/script>',
|
|
114
114
|
`
|
|
115
115
|
${e != null && e.backgroundColor ? `<meta name="theme-color" content="${e.backgroundColor}" /><style>html,body,#app {background-color: ${e.backgroundColor} !important;}</style>` : ""}
|
|
116
116
|
${o != null && o.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${o.title}&display=swap">` : ""}
|
|
117
117
|
${o != null && o.description && (o == null ? void 0 : o.description) !== (o == null ? void 0 : o.title) ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${o.description}&display=swap">` : ""}
|
|
118
|
+
|
|
119
|
+
<script type="application/json" id="__PAGE_STATE__">
|
|
120
|
+
${JSON.stringify(n).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026")}
|
|
121
|
+
<\/script>
|
|
122
|
+
|
|
118
123
|
<script>
|
|
119
124
|
|
|
120
|
-
window.__PAGE_STATE__ =
|
|
125
|
+
window.__PAGE_STATE__ = JSON.parse(document.getElementById('__PAGE_STATE__').textContent)
|
|
121
126
|
|
|
122
127
|
document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
|
|
123
128
|
const l = document.createElement('link');
|
|
@@ -127,7 +132,7 @@ function me({
|
|
|
127
132
|
});
|
|
128
133
|
<\/script>
|
|
129
134
|
|
|
130
|
-
${
|
|
135
|
+
${R ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
131
136
|
<script>
|
|
132
137
|
window.tailwind.config = {
|
|
133
138
|
darkMode: "class",
|
|
@@ -135,17 +140,17 @@ function me({
|
|
|
135
140
|
<\/script>` : ""}
|
|
136
141
|
`
|
|
137
142
|
);
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
143
|
+
const T = Q();
|
|
144
|
+
if (T && (r = r.replace('<script src="__blocklet__.js"><\/script>', `<script>${T}<\/script>`)), d != null && d.html && (r = r.replace('<script id="injected-html-elements"><\/script>', d.html)), t.cachedHtml) {
|
|
140
145
|
const c = /<body>([\s\S]*?)<\/body>/, i = c.exec(t.cachedHtml), m = i ? i[1] : "";
|
|
141
146
|
r = r.replace(c, `<body>${m}</body>`);
|
|
142
147
|
}
|
|
143
|
-
|
|
144
|
-
}), s.use(
|
|
148
|
+
C.send(r), E.info(`[html] render: ${t.path}, ${k()}ms`), r = null, e = null, d = null;
|
|
149
|
+
}), s.use(_);
|
|
145
150
|
}
|
|
146
151
|
function Z(s) {
|
|
147
|
-
const
|
|
148
|
-
return
|
|
152
|
+
const g = K("image-bin");
|
|
153
|
+
return g && s && !/^(https?:\/\/|\/)/.test(s) ? p.env.appUrl + x(g, "uploads", s) : s;
|
|
149
154
|
}
|
|
150
155
|
export {
|
|
151
156
|
me as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-inner-components",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.26",
|
|
4
4
|
"description": "Pages Kit inner components library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -202,8 +202,8 @@
|
|
|
202
202
|
"yaml": "^2.5.0",
|
|
203
203
|
"yjs": "^13.6.18",
|
|
204
204
|
"zustand": "^4.5.5",
|
|
205
|
-
"@blocklet/pages-kit": "^0.4.
|
|
206
|
-
"@blocklet/pages-kit-block-studio": "^0.4.
|
|
205
|
+
"@blocklet/pages-kit": "^0.4.26",
|
|
206
|
+
"@blocklet/pages-kit-block-studio": "^0.4.26"
|
|
207
207
|
},
|
|
208
208
|
"devDependencies": {
|
|
209
209
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|