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