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