@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.
@@ -1,4 +1,4 @@
1
- import { b as H, l as _ } from "./chunks/site-state-Bn8mEgOx.js";
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 D() {
14
+ function x() {
15
15
  M() ? W({
16
16
  time: "0 0 */12 * * *",
17
17
  options: {}
18
18
  }) : N();
19
19
  }
20
- D();
21
- a.events.on(a.Events.envUpdate, D);
22
- function me({
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 t = I(j(process.cwd(), "./index.html"), "utf-8");
31
- c.use(async (b, $, y) => {
32
- const v = b.originalUrl;
33
- C = await h.transformIndexHtml(v, t), y();
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 k = V();
38
- k.use(
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
- ), k.get("/:path(*)?", async (t, b, $) => {
50
+ ), _.get("/:path(*)?", async (o, f, b) => {
44
51
  var T, E, S;
45
- if (Z.some((l) => {
46
- var i;
47
- return (i = t.path) == null ? void 0 : i.startsWith(l);
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 y = performance.now(), v = () => Math.round(performance.now() - y), O = "production";
53
- let e, p, f = C;
54
- if (t.path.startsWith("/pages")) {
55
- const l = t.params.lang, i = t.cookies.nf_lang, g = /* @__PURE__ */ new Set([...a.env.languages.map((u) => u.code)]);
56
- let d = (l && g.has(l) ? l : void 0) || (g.has(i) ? i : void 0) || [...g][0];
57
- if ((!d || !((T = n.supportedLocales) != null && T.find((u) => u.locale === d))) && (d = ((S = (E = n.supportedLocales) == null ? void 0 : E[0]) == null ? void 0 : S.locale) || ""), d) {
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((r) => {
60
- const B = Object.values((r == null ? void 0 : r.sections) ?? {}).filter(
61
- (s) => {
62
- var w;
63
- return s.component === "custom-component" && ((w = s.config) == null ? void 0 : w.componentId);
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((s) => {
66
- var w, L;
72
+ ).map((i) => {
73
+ var k, L;
67
74
  return {
68
- id: s.id,
69
- componentId: s.config.componentId,
70
- useCache: s.config.useCache,
71
- cacheDuration: s.config.cacheDuration,
72
- properties: (L = (w = s.locales) == null ? void 0 : w[d]) == null ? void 0 : L.properties
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 x = new Promise((r) => {
84
+ const R = new Promise((l) => {
78
85
  setTimeout(() => {
79
- r({});
86
+ l({});
80
87
  }, 90 * 1e3);
81
88
  });
82
89
  try {
83
90
  await Promise.race([
84
- x,
91
+ R,
85
92
  H({
86
- mode: O,
87
- req: t,
93
+ mode: D,
94
+ req: o,
88
95
  state: n,
89
- locale: d,
96
+ locale: m,
90
97
  instances: u,
91
98
  module: G.UMD_FN
92
- }).then((r) => {
93
- r && (p = K(r));
99
+ }).then((l) => {
100
+ l && (p = K(l));
94
101
  })
95
102
  ]);
96
- } catch (r) {
97
- _.warn("getPreloadComponents timeout in promise race, skip inject html elements"), _.warn(r);
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 l = (e == null ? void 0 : e.title) || a.env.appName, i = (e == null ? void 0 : e.description) || a.env.appDescription, g = Y(U(a.env.appUrl, "/.well-known/service/blocklet/og.png"), {
103
- title: l,
104
- description: i
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
- f = X.render(C, {
107
- ogTitle: l,
108
- ogDescription: i,
109
- ogImage: F(e == null ? void 0 : e.image) || g,
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 o = n == null ? void 0 : n.config.fontFamily, R = t.query.mode === "draft" || t.url.includes("preview"), m = A.load(f);
115
- m("head").find("#injected-head-elements").replaceWith(`
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
- ${o != null && o.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${o.title}&display=swap">` : ""}
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">` : ""}
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
- ${R ? `<script src="https://cdn.tailwindcss.com"><\/script>
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 && m('script[src="__blocklet__.js"]').replaceWith(`<script>${P}<\/script>`), p != null && p.html && m("head").find("#injected-html-elements").replaceWith(p.html), t.cachedHtml) {
140
- const l = A.load(t.cachedHtml);
141
- m("body").html(l("body").html() || "");
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
- f = m.html(), b.send(f), _.info(`[html] render: ${t.path}, ${v()}ms`), m.root().children().remove(), f = null, e = null, p = null;
144
- }), c.use(k);
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 F(c) {
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
- me as default
158
+ de as default
152
159
  };