@blocklet/pages-kit-inner-components 0.1.7 → 0.1.8

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