@bagelink/blox 1.12.22 → 1.13.1

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.
@@ -0,0 +1,66 @@
1
+ import { PageRead, WebsiteRead } from '../api/types';
2
+ /** Resolved page data shape (subset of PageResolveRead). */
3
+ export interface SeoPageData {
4
+ page: PageRead;
5
+ alternates?: Record<string, string>;
6
+ contexts?: Record<string, Record<string, unknown> | null>;
7
+ }
8
+ /** Website meta bag (freeform JSON stored on WebsiteRead.meta). */
9
+ export interface WebsiteMeta {
10
+ default_meta_title?: string;
11
+ default_meta_description?: string;
12
+ default_og_image?: string;
13
+ webclip?: string;
14
+ og_site_name?: string;
15
+ og_description?: string;
16
+ og_type?: string;
17
+ twitter_card?: string;
18
+ twitter_site?: string;
19
+ canonical_base_url?: string;
20
+ noindex?: boolean;
21
+ verification_google?: string;
22
+ verification_bing?: string;
23
+ structured_data_org?: unknown;
24
+ [key: string]: unknown;
25
+ }
26
+ export interface RedirectEntry {
27
+ from_path: string;
28
+ to_path: string;
29
+ status_code: number;
30
+ }
31
+ /**
32
+ * Build a complete `<head>` fragment for a single page.
33
+ *
34
+ * Includes: title, meta description, OG tags, Twitter Card, canonical,
35
+ * hreflang alternates, noindex, and the __BLOX_STATE__ script.
36
+ */
37
+ export declare function buildPageHead(options: {
38
+ url: string;
39
+ resolvedData: SeoPageData | null;
40
+ website: WebsiteRead | null;
41
+ stateScript?: string;
42
+ }): string;
43
+ /**
44
+ * Build site-wide `<head>` tags: verification, structured data, analytics, favicon.
45
+ * These replace hardcoded equivalents in the HTML template.
46
+ */
47
+ export declare function buildSiteHead(website: WebsiteRead | null): string;
48
+ export declare function generateSitemapXml(options: {
49
+ renderedPaths: string[];
50
+ canonicalBase: string;
51
+ defaultChangefreq?: string;
52
+ defaultPriority?: string;
53
+ }): string;
54
+ export declare function generateRobotsTxt(options: {
55
+ robotsTxt?: string | null;
56
+ canonicalBase?: string;
57
+ noindex?: boolean;
58
+ }): string;
59
+ export declare function generateNetlifyRedirects(redirects: RedirectEntry[]): string;
60
+ /**
61
+ * Strip hardcoded SEO tags from the HTML template so SSG can inject
62
+ * per-page equivalents. Removes: title, meta description, og:*, twitter:*,
63
+ * apple-touch-icon, and favicon.
64
+ */
65
+ export declare function stripTemplateSeoTags(template: string): string;
66
+ //# sourceMappingURL=seo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../../src/ssg/seo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAMzD,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,QAAQ,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;CACzD;AAED,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,aAAa;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;CACnB;AAMD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE;IACtC,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,WAAW,GAAG,IAAI,CAAA;IAChC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,MAAM,CAiFT;AAMD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,MAAM,CA4CjE;AAMD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC3C,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,MAAM,CAmBT;AAMD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAC1C,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,GAAG,MAAM,CAmBT;AAMD,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,CAK3E;AAMD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgB7D"}
package/package.json CHANGED
@@ -1,126 +1,127 @@
1
1
  {
2
- "name": "@bagelink/blox",
3
- "type": "module",
4
- "version": "1.12.22",
5
- "description": "Blox page builder library for drag-and-drop page building and static data management",
6
- "author": {
7
- "name": "Bagel Studio",
8
- "email": "info@bagelstudio.co.il",
9
- "url": "https://bagelstudio.co.il"
10
- },
11
- "license": "MIT",
12
- "homepage": "https://github.com/bageldb/bagelink/tree/master/packages/blox#readme",
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/bageldb/bagelink.git",
16
- "directory": "packages/blox"
17
- },
18
- "bugs": "https://github.com/bageldb/bagelink/issues",
19
- "keywords": [
20
- "blox",
21
- "page-builder",
22
- "preview",
23
- "external-preview",
24
- "cms",
25
- "vue",
26
- "component-library",
27
- "drag-and-drop",
28
- "static-pages"
29
- ],
30
- "bin": {
31
- "blox-ssg": "./dist/ssg/cli.mjs"
32
- },
33
- "sideEffects": false,
34
- "exports": {
35
- "./package.json": "./package.json",
36
- "./vite": {
37
- "types": "./dist/vite-plugin.d.ts",
38
- "import": "./dist/vite-plugin.mjs"
39
- },
40
- ".": {
41
- "types": "./dist/index.d.ts",
42
- "require": "./dist/index.cjs",
43
- "import": "./dist/index.mjs"
44
- },
45
- "./ssg": {
46
- "types": "./dist/ssg/index.d.ts",
47
- "import": "./dist/ssg/index.mjs"
48
- },
49
- "./ssg/client": {
50
- "types": "./dist/ssg/client.d.ts",
51
- "import": "./dist/ssg/client.mjs"
52
- },
53
- "./components": {
54
- "types": "./dist/components/index.d.ts",
55
- "import": "./dist/components/index.mjs"
56
- },
57
- "./core": {
58
- "types": "./dist/core/types.d.ts",
59
- "import": "./dist/core/types.mjs"
60
- },
61
- "./utils": {
62
- "types": "./dist/utils/styles.d.ts",
63
- "import": "./dist/utils/styles.mjs"
64
- },
65
- "./dist/style.css": "./dist/style.css"
66
- },
67
- "main": "./dist/index.cjs",
68
- "module": "./dist/index.mjs",
69
- "types": "./dist/index.d.ts",
70
- "typesVersions": {
71
- "*": {
72
- "*": [
73
- "./dist/*",
74
- "./dist/index.d.ts"
75
- ]
76
- }
77
- },
78
- "files": [
79
- "dist",
80
- "core",
81
- "components",
82
- "config",
83
- "ssg",
84
- "utils",
85
- "views",
86
- "setup.ts",
87
- "index.ts",
88
- "README.md"
89
- ],
90
- "publishConfig": {
91
- "access": "public"
92
- },
93
- "peerDependencies": {
94
- "@bagelink/vue": "*",
95
- "happy-dom": ">=14.0.0",
96
- "vite": ">=5.0.0",
97
- "vue": "^3.3.0",
98
- "vue-router": "^4.0.0"
99
- },
100
- "peerDependenciesMeta": {
101
- "happy-dom": {
102
- "optional": true
103
- },
104
- "vite": {
105
- "optional": true
106
- }
107
- },
108
- "devDependencies": {
109
- "@vitejs/plugin-vue": "^5.0.0",
110
- "@vue/tsconfig": "^0.7.0",
111
- "magic-string": "^0.30.21",
112
- "typescript": "^5.8.3",
113
- "vite": "^5.0.0",
114
- "vite-plugin-dts": "^4.0.0",
115
- "vite-tsconfig-paths": "^5.0.0",
116
- "vitest": "^3.2.4",
117
- "vue": "^3.5.32",
118
- "vue-router": "^4.6.3",
119
- "vue-tsc": "^2.0.0"
120
- },
121
- "scripts": {
122
- "dev": "vite build --watch",
123
- "build": "vite build",
124
- "typecheck": "vue-tsc --noEmit"
125
- }
126
- }
2
+ "name": "@bagelink/blox",
3
+ "type": "module",
4
+ "version": "1.13.1",
5
+ "description": "Blox page builder library for drag-and-drop page building and static data management",
6
+ "author": {
7
+ "name": "Bagel Studio",
8
+ "email": "info@bagelstudio.co.il",
9
+ "url": "https://bagelstudio.co.il"
10
+ },
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/bageldb/bagelink/tree/master/packages/blox#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/bageldb/bagelink.git",
16
+ "directory": "packages/blox"
17
+ },
18
+ "bugs": "https://github.com/bageldb/bagelink/issues",
19
+ "keywords": [
20
+ "blox",
21
+ "page-builder",
22
+ "preview",
23
+ "external-preview",
24
+ "cms",
25
+ "vue",
26
+ "component-library",
27
+ "drag-and-drop",
28
+ "static-pages"
29
+ ],
30
+ "bin": {
31
+ "blox-ssg": "./dist/ssg/cli.mjs"
32
+ },
33
+ "sideEffects": false,
34
+ "exports": {
35
+ "./package.json": "./package.json",
36
+ "./vite": {
37
+ "types": "./dist/vite-plugin.d.ts",
38
+ "import": "./dist/vite-plugin.mjs"
39
+ },
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "require": "./dist/index.cjs",
43
+ "import": "./dist/index.mjs"
44
+ },
45
+ "./ssg": {
46
+ "types": "./dist/ssg/index.d.ts",
47
+ "import": "./dist/ssg/index.mjs"
48
+ },
49
+ "./ssg/client": {
50
+ "types": "./dist/ssg/client.d.ts",
51
+ "import": "./dist/ssg/client.mjs"
52
+ },
53
+ "./components": {
54
+ "types": "./dist/components/index.d.ts",
55
+ "import": "./dist/components/index.mjs"
56
+ },
57
+ "./core": {
58
+ "types": "./dist/core/types.d.ts",
59
+ "import": "./dist/core/types.mjs"
60
+ },
61
+ "./utils": {
62
+ "types": "./dist/utils/styles.d.ts",
63
+ "import": "./dist/utils/styles.mjs"
64
+ },
65
+ "./dist/style.css": "./dist/style.css"
66
+ },
67
+ "main": "./dist/index.cjs",
68
+ "module": "./dist/index.mjs",
69
+ "types": "./dist/index.d.ts",
70
+ "typesVersions": {
71
+ "*": {
72
+ "*": [
73
+ "./dist/*",
74
+ "./dist/index.d.ts"
75
+ ]
76
+ }
77
+ },
78
+ "files": [
79
+ "dist",
80
+ "core",
81
+ "components",
82
+ "config",
83
+ "ssg",
84
+ "utils",
85
+ "views",
86
+ "setup.ts",
87
+ "index.ts",
88
+ "README.md"
89
+ ],
90
+ "scripts": {
91
+ "prepublishOnly": "pnpm build",
92
+ "dev": "vite build --watch",
93
+ "build": "vite build",
94
+ "typecheck": "vue-tsc --noEmit"
95
+ },
96
+ "publishConfig": {
97
+ "access": "public"
98
+ },
99
+ "peerDependencies": {
100
+ "@bagelink/vue": "*",
101
+ "happy-dom": ">=14.0.0",
102
+ "vite": ">=5.0.0",
103
+ "vue": "^3.3.0",
104
+ "vue-router": "^4.0.0"
105
+ },
106
+ "peerDependenciesMeta": {
107
+ "happy-dom": {
108
+ "optional": true
109
+ },
110
+ "vite": {
111
+ "optional": true
112
+ }
113
+ },
114
+ "devDependencies": {
115
+ "@vitejs/plugin-vue": "^5.0.0",
116
+ "@vue/tsconfig": "^0.7.0",
117
+ "magic-string": "^0.30.21",
118
+ "typescript": "^5.8.3",
119
+ "vite": "^5.0.0",
120
+ "vite-plugin-dts": "^4.0.0",
121
+ "vite-tsconfig-paths": "^5.0.0",
122
+ "vitest": "^3.2.4",
123
+ "vue": "^3.5.32",
124
+ "vue-router": "^4.6.3",
125
+ "vue-tsc": "^2.0.0"
126
+ }
127
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Bagel Studio
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,282 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import process from "node:process";
4
- import { pathToFileURL } from "node:url";
5
- async function fetchCmsPrerenderPaths(apiBase, websiteName) {
6
- const sitesRes = await fetch(`${apiBase}/cms/websites`);
7
- const sitesData = await sitesRes.json();
8
- const sites = Array.isArray(sitesData) ? sitesData : sitesData.data ?? [];
9
- const site = sites.find((s) => s.name === websiteName);
10
- if ((site == null ? void 0 : site.id) == null || site.id === "") throw new Error(`Website "${websiteName}" not found at ${apiBase}`);
11
- const pagesRes = await fetch(`${apiBase}/cms/websites/${site.id}/pages?locale=en`);
12
- const pagesData = await pagesRes.json();
13
- const pages = Array.isArray(pagesData) ? pagesData : pagesData.data ?? [];
14
- const routes = [];
15
- for (const page of pages) {
16
- const slug = page.slug ?? "/";
17
- if (slug.includes(":") && page.data_bindings) {
18
- for (const [, binding] of Object.entries(page.data_bindings)) {
19
- const b = binding;
20
- if (b.adapter === "datastore" && b.collection != null && b.collection !== "" && b.store != null && b.store !== "" && b.bind_by != null && b.bind_by !== "") {
21
- try {
22
- const itemsRes = await fetch(
23
- `${apiBase}/datastore/${b.store}/collections/${b.collection}?limit=200`
24
- );
25
- const itemsData = await itemsRes.json();
26
- const items = Array.isArray(itemsData) ? itemsData : itemsData.data ?? [];
27
- for (const item of items) {
28
- const bindValue = item[b.bind_by];
29
- if (bindValue != null && bindValue !== "") {
30
- const concrete = slug.replace(/:([a-z_]+)/g, (_m, p) => p === b.bind_by ? String(bindValue) : String(item[p] ?? ""));
31
- routes.push(concrete);
32
- }
33
- }
34
- } catch (e) {
35
- console.warn(` [blox-ssg] Could not expand ${slug}: ${e.message}`);
36
- }
37
- }
38
- }
39
- } else if (!slug.includes(":")) {
40
- routes.push(slug === "" ? "/" : slug);
41
- }
42
- }
43
- return [...new Set(routes)];
44
- }
45
- async function polyfillBloxSsgGlobals(options) {
46
- const { env } = await import("node:process");
47
- const pageUrl = (options == null ? void 0 : options.pageUrl) ?? env.BAGELINK_API_URL ?? "https://example.com/";
48
- const { Window: HappyWindow } = await import("happy-dom");
49
- const _win = new HappyWindow({ url: pageUrl });
50
- const g = globalThis;
51
- if (g.window == null) g.window = g;
52
- for (const key of Object.getOwnPropertyNames(_win)) {
53
- if (key === "window" || key === "global" || key === "globalThis") continue;
54
- try {
55
- if (!(key in g)) g[key] = _win[key];
56
- } catch {
57
- }
58
- }
59
- for (const key of [
60
- "document",
61
- "location",
62
- "localStorage",
63
- "sessionStorage",
64
- "navigator",
65
- "Element",
66
- "Document",
67
- "HTMLElement",
68
- "Event",
69
- "CustomEvent",
70
- "MouseEvent",
71
- "KeyboardEvent",
72
- "MutationObserver",
73
- "IntersectionObserver",
74
- "ResizeObserver",
75
- "getComputedStyle",
76
- "matchMedia",
77
- "requestAnimationFrame",
78
- "cancelAnimationFrame"
79
- ]) {
80
- try {
81
- g[key] = _win[key];
82
- } catch {
83
- }
84
- }
85
- g.window = g;
86
- g.window.location = _win.location;
87
- g.window.document = _win.document;
88
- }
89
- async function prerender({
90
- root = process.cwd(),
91
- clientOutDir = "dist/client",
92
- serverEntry = "dist/server/main.server.js",
93
- paths = [],
94
- crawl = true,
95
- excludePaths = [],
96
- failFast = false,
97
- maxPages = 5e3,
98
- mode = "dir"
99
- } = {}) {
100
- const absRoot = path.resolve(root);
101
- const absClient = path.resolve(absRoot, clientOutDir);
102
- const absServerEntry = path.resolve(absRoot, serverEntry);
103
- const templatePath = path.join(absClient, "index.html");
104
- const template = await fs.readFile(templatePath, "utf8");
105
- const serverMod = await import(pathToFileURL(absServerEntry).href);
106
- if (typeof serverMod.render !== "function") {
107
- throw new TypeError(
108
- `SSR entry must export async function render(url, ctx). Missing "render" in: ${absServerEntry}`
109
- );
110
- }
111
- let manifest = null;
112
- try {
113
- const manifestPath = path.join(absClient, "ssr-manifest.json");
114
- manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
115
- } catch {
116
- }
117
- const isExcluded = makeExcludeChecker(excludePaths);
118
- const queue = [];
119
- const seen = /* @__PURE__ */ new Set();
120
- enqueue("/", queue, seen, isExcluded);
121
- for (const p of paths) enqueue(p, queue, seen, isExcluded);
122
- const fontPreloads = await discoverFontPreloads(absClient);
123
- const rendered = [];
124
- const failures = [];
125
- while (queue.length) {
126
- if (rendered.length >= maxPages) break;
127
- const urlPath = queue.shift();
128
- if (urlPath == null || urlPath === "") continue;
129
- if (isExcluded(urlPath)) continue;
130
- try {
131
- const { html, head = "", htmlAttrs = "" } = await serverMod.render(urlPath, {
132
- manifest,
133
- template
134
- });
135
- const outHtml = injectIntoTemplate(template, head, html, fontPreloads, htmlAttrs);
136
- const outfile = outFilePath(absClient, urlPath, mode);
137
- await fs.mkdir(path.dirname(outfile), { recursive: true });
138
- await fs.writeFile(outfile, outHtml, "utf8");
139
- rendered.push(urlPath);
140
- if (crawl) {
141
- const discovered = discoverInternalLinks(outHtml);
142
- for (const p of discovered) enqueue(p, queue, seen, isExcluded);
143
- }
144
- } catch (err) {
145
- failures.push({ path: urlPath, error: err });
146
- if (failFast) throw err;
147
- console.warn(`[prerender] failed: ${urlPath}
148
- `, err.stack ?? err);
149
- }
150
- }
151
- return {
152
- rendered,
153
- failures,
154
- queuedRemaining: queue.length,
155
- totalDiscovered: seen.size
156
- };
157
- }
158
- function normalizePath(p) {
159
- if (!p) return "/";
160
- try {
161
- if (p.startsWith("http://") || p.startsWith("https://")) {
162
- const u = new URL(p);
163
- p = u.pathname + (u.search || "");
164
- }
165
- } catch {
166
- }
167
- if (!p.startsWith("/")) p = `/${p}`;
168
- const hashIdx = p.indexOf("#");
169
- if (hashIdx !== -1) p = p.slice(0, hashIdx);
170
- p = p.replace(/\/{2,}/g, "/");
171
- if (p.length > 1 && p.endsWith("/")) p = p.slice(0, -1);
172
- return p || "/";
173
- }
174
- function enqueue(p, queue, seen, isExcluded) {
175
- const np = normalizePath(p);
176
- if (seen.has(np)) return;
177
- if (isExcluded(np)) return;
178
- seen.add(np);
179
- queue.push(np);
180
- }
181
- function makeExcludeChecker(excludePaths) {
182
- const rules = Array.isArray(excludePaths) ? excludePaths : [excludePaths];
183
- return (p) => {
184
- const np = normalizePath(p);
185
- for (const r of rules) {
186
- if (typeof r === "string" && r === "") continue;
187
- if (typeof r === "function") {
188
- if (r(np)) return true;
189
- } else if (r instanceof RegExp) {
190
- if (r.test(np)) return true;
191
- } else if (typeof r === "string") {
192
- const prefix = normalizePath(r);
193
- if (np === prefix || np.startsWith(`${prefix}/`)) return true;
194
- }
195
- }
196
- return false;
197
- };
198
- }
199
- async function discoverFontPreloads(clientOutDir) {
200
- const assetsDir = path.join(clientOutDir, "assets");
201
- let cssFiles = [];
202
- try {
203
- const entries = await fs.readdir(assetsDir);
204
- cssFiles = entries.filter((f) => f.endsWith(".css")).map((f) => path.join(assetsDir, f));
205
- } catch {
206
- return "";
207
- }
208
- const seen = /* @__PURE__ */ new Set();
209
- const woff2Re = /url\((["']?)(https?:\/\/[^"')]+\.woff2)\1\)/g;
210
- for (const file of cssFiles) {
211
- const css = await fs.readFile(file, "utf8");
212
- for (const [, , url] of css.matchAll(woff2Re)) {
213
- if (url !== "") seen.add(url);
214
- }
215
- }
216
- return [...seen].map((href) => `<link rel="preload" as="font" type="font/woff2" crossorigin href="${href}">`).join("\n");
217
- }
218
- function injectIntoTemplate(template, head, appHtml, fontPreloads, htmlAttrs = "") {
219
- let out = template;
220
- if (template.includes("<!--app-html-->")) {
221
- out = template.replace("<!--app-html-->", appHtml);
222
- } else if (template.includes('<div id="app"></div>')) {
223
- out = template.replace('<div id="app"></div>', `<div id="app">${appHtml}</div>`);
224
- }
225
- if (htmlAttrs) {
226
- const langMatch = htmlAttrs.match(/lang="([^"]*)"/);
227
- if (langMatch) {
228
- out = out.replace(/(<html[^>]*\s)lang="[^"]*"/, `$1lang="${langMatch[1]}"`);
229
- }
230
- }
231
- if (fontPreloads) {
232
- out = out.replace("</head>", `${fontPreloads}
233
- </head>`);
234
- }
235
- if (head) {
236
- const descTagRe = /<meta\s[^>]*name\s*=\s*["']description["'][^>]*>/gi;
237
- const descMatches = [...head.matchAll(descTagRe)];
238
- if (descMatches.length > 1) {
239
- for (let i = 0; i < descMatches.length - 1; i++) {
240
- head = head.replace(descMatches[i][0], "");
241
- }
242
- }
243
- if (/<meta\s[^>]*name\s*=\s*["']description["']/i.test(head)) {
244
- out = out.replace(/<meta\s[^>]*name\s*=\s*["']description["'][^>]*>/gi, "");
245
- }
246
- out = out.replace("</head>", `${head}
247
- </head>`);
248
- }
249
- return out;
250
- }
251
- function outFilePath(absClientDir, urlPath, mode) {
252
- const [pathname] = urlPath.split("?");
253
- const safe = pathname === "/" ? "/" : pathname;
254
- if (mode === "file") {
255
- if (safe === "/") return path.join(absClientDir, "index.html");
256
- return path.join(absClientDir, `${safe.slice(1)}.html`);
257
- }
258
- if (safe === "/") return path.join(absClientDir, "index.html");
259
- return path.join(absClientDir, safe.slice(1), "index.html");
260
- }
261
- function discoverInternalLinks(html) {
262
- const out = /* @__PURE__ */ new Set();
263
- const hrefRe = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
264
- let m;
265
- while ((m = hrefRe.exec(html)) !== null) {
266
- const raw = (m[1] ?? m[2] ?? "").trim();
267
- if (!raw) continue;
268
- if (raw.startsWith("mailto:") || raw.startsWith("tel:") || raw.startsWith("javascript:") || raw.startsWith("#")) {
269
- continue;
270
- }
271
- if (raw.startsWith("http://") || raw.startsWith("https://")) continue;
272
- if (/\.(?:pdf|png|jpe?g|gif|svg|webp|css|js|map|ico)(?:\?|$)/i.test(raw)) continue;
273
- const candidate = raw.startsWith("/") ? raw : `/${raw}`;
274
- out.add(candidate);
275
- }
276
- return [...out];
277
- }
278
- export {
279
- prerender as a,
280
- fetchCmsPrerenderPaths as f,
281
- polyfillBloxSsgGlobals as p
282
- };