@bagelink/blox 1.17.6 → 1.18.6

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.
Files changed (39) hide show
  1. package/dist/{PreviewApp-BKrLRDBC.js → PreviewApp-9H9-jLVN.js} +1 -1
  2. package/dist/{PreviewApp-Kb3uTwtH.cjs → PreviewApp-D8ZBTG0j.cjs} +1 -1
  3. package/dist/{PreviewApp.vue_vue_type_style_index_0_lang-AC3W0NSJ.cjs → PreviewApp.vue_vue_type_style_index_0_lang-BYCayJs0.cjs} +1 -1
  4. package/dist/{PreviewApp.vue_vue_type_style_index_0_lang-BMGv1eSR.js → PreviewApp.vue_vue_type_style_index_0_lang-BwiLyRBw.js} +1 -1
  5. package/dist/{appRuntime-CWlPH_5r.js → appRuntime-DZSCSsnS.js} +39 -156
  6. package/dist/{appRuntime-BU2Ls-Y7.cjs → appRuntime-Z0AxTPxf.cjs} +17 -134
  7. package/dist/composables/useLocale.d.ts +3 -0
  8. package/dist/composables/useLocale.d.ts.map +1 -1
  9. package/dist/composables/useLocaleNav.d.ts.map +1 -1
  10. package/dist/createBloxApp.d.ts.map +1 -1
  11. package/dist/hydration.d.ts +2 -0
  12. package/dist/hydration.d.ts.map +1 -1
  13. package/dist/index.cjs +16 -9
  14. package/dist/index.mjs +44 -36
  15. package/dist/localeStrategy-OwRIn35C.cjs +207 -0
  16. package/dist/localeStrategy-hXlNof1E.js +208 -0
  17. package/dist/localeStrategy.d.ts +21 -0
  18. package/dist/localeStrategy.d.ts.map +1 -1
  19. package/dist/{shard-runner-DXjScXLk.cjs → shard-runner-DF3K3Ze_.cjs} +14 -7
  20. package/dist/{shard-runner-f05p1VMY.js → shard-runner-DFrc8d4O.js} +15 -8
  21. package/dist/ssg/cli.cjs +9 -2
  22. package/dist/ssg/cli.mjs +9 -2
  23. package/dist/ssg/cms-routes.d.ts +7 -0
  24. package/dist/ssg/cms-routes.d.ts.map +1 -1
  25. package/dist/ssg/index.cjs +4 -2
  26. package/dist/ssg/index.mjs +5 -3
  27. package/dist/ssg/prerender.d.ts +3 -1
  28. package/dist/ssg/prerender.d.ts.map +1 -1
  29. package/dist/ssg/render-resolved-page.d.ts +2 -0
  30. package/dist/ssg/render-resolved-page.d.ts.map +1 -1
  31. package/dist/ssg/seo.d.ts.map +1 -1
  32. package/dist/ssg/shard-runner.d.ts +3 -0
  33. package/dist/ssg/shard-runner.d.ts.map +1 -1
  34. package/dist/{validate-output-C94Qpxw3.cjs → validate-output-BymMbrA5.cjs} +45 -13
  35. package/dist/{validate-output-CuX33CnX.js → validate-output-yDJYYYzK.js} +41 -9
  36. package/package.json +125 -124
  37. package/LICENSE +0 -21
  38. package/dist/pageTitle-B1mtDJKn.js +0 -59
  39. package/dist/pageTitle-wobGhtiZ.cjs +0 -58
@@ -3,7 +3,7 @@ import fs, { readFile } from "node:fs/promises";
3
3
  import path, { resolve } from "node:path";
4
4
  import process$1 from "node:process";
5
5
  import { pathToFileURL } from "node:url";
6
- import { r as resolvePageTitle, p as primaryPageContext, c as contextPageTitle } from "./pageTitle-B1mtDJKn.js";
6
+ import { r as resolvePageTitle, p as primaryPageContext, c as contextPageTitle } from "./localeStrategy-hXlNof1E.js";
7
7
  class BloxBuildResponseError extends Error {
8
8
  constructor(status, url, statusText) {
9
9
  super(`Build API ${status} ${statusText}: ${url}`);
@@ -72,6 +72,24 @@ async function bloxBuildJson(input, init = {}, options = {}) {
72
72
  if (response.status === 204) return null;
73
73
  return response.json();
74
74
  }
75
+ function buildPageSlugMap(localizedBundles, defaultLocale) {
76
+ var _a;
77
+ const map = {};
78
+ const defaultPages = ((_a = localizedBundles.find((result) => result.locale === defaultLocale)) == null ? void 0 : _a.bundle.pages) ?? [];
79
+ const canonicalById = new Map(
80
+ defaultPages.flatMap((page) => page.id && page.slug && !page.slug.includes(":") ? [[page.id, page.slug]] : [])
81
+ );
82
+ for (const { locale, bundle } of localizedBundles) {
83
+ for (const page of bundle.pages) {
84
+ if (!page.slug || page.slug.includes(":") || page.status && page.status !== "published") continue;
85
+ const canonical = page.id ? canonicalById.get(page.id) : void 0;
86
+ if (!canonical) continue;
87
+ const entry = map[canonical] ?? (map[canonical] = { [defaultLocale]: canonical });
88
+ entry[locale] = page.slug;
89
+ }
90
+ }
91
+ return map;
92
+ }
75
93
  function localizePath(slug, locale, defaultLocale) {
76
94
  if (locale === defaultLocale) return slug === "" ? "/" : slug;
77
95
  const s = slug === "" || slug === "/" ? "" : slug;
@@ -118,7 +136,7 @@ async function fetchCmsSiteData(apiBase, websiteName, requestOptions = {}) {
118
136
  return [{
119
137
  from_path: fromPath,
120
138
  to_path: localizePath(page.slug, locale, defaultLocale2),
121
- status_code: 302
139
+ status_code: 301
122
140
  }];
123
141
  });
124
142
  });
@@ -132,6 +150,7 @@ async function fetchCmsSiteData(apiBase, websiteName, requestOptions = {}) {
132
150
  website: website2,
133
151
  paths: paths2,
134
152
  pageSlugs: [...new Set(localizedBundles.flatMap((result) => result.bundle.pages.flatMap((page) => page.slug ? [localizePath(page.slug, result.locale, defaultLocale2)] : [])))],
153
+ pageSlugMap: buildPageSlugMap(localizedBundles, defaultLocale2),
135
154
  redirects: redirects2,
136
155
  collections: extractCollectionRefs(localizedBundles.flatMap((result) => result.bundle.pages)),
137
156
  collectionItems
@@ -175,7 +194,7 @@ async function fetchCmsSiteData(apiBase, websiteName, requestOptions = {}) {
175
194
  return [{
176
195
  from_path: fromPath,
177
196
  to_path: localizePath(page.slug, locale, defaultLocale),
178
- status_code: 302
197
+ status_code: 301
179
198
  }];
180
199
  });
181
200
  });
@@ -191,7 +210,18 @@ async function fetchCmsSiteData(apiBase, websiteName, requestOptions = {}) {
191
210
  const pages = localizedPages.flatMap((result) => result.pages);
192
211
  const collections = extractCollectionRefs(pages);
193
212
  const pageSlugs = [...new Set(localizedPages.flatMap((result) => result.pages.flatMap((page) => page.slug ? [localizePath(page.slug, result.locale, defaultLocale)] : [])))];
194
- return { websiteId: site.id, website, paths, pageSlugs, redirects, collections };
213
+ return {
214
+ websiteId: site.id,
215
+ website,
216
+ paths,
217
+ pageSlugs,
218
+ pageSlugMap: buildPageSlugMap(
219
+ localizedPages.map((result) => ({ locale: result.locale, bundle: { pages: result.pages } })),
220
+ defaultLocale
221
+ ),
222
+ redirects,
223
+ collections
224
+ };
195
225
  }
196
226
  async function expandRoutes(apiBase, pages, requestOptions, locale, collectItems) {
197
227
  const routes = [];
@@ -654,7 +684,7 @@ function generateSitemapArtifacts(options) {
654
684
  function generateRobotsTxt(options) {
655
685
  const { robotsTxt, canonicalBase, noindex } = options;
656
686
  const base = (canonicalBase || "").replace(/\/$/, "");
657
- const sitemapLine = base && !noindex ? `
687
+ const sitemapLine = base ? `
658
688
  Sitemap: ${base}/sitemap.xml
659
689
  ` : "";
660
690
  if (robotsTxt) {
@@ -667,7 +697,7 @@ ${sitemapLine}`;
667
697
  if (noindex) {
668
698
  return `User-agent: *
669
699
  Disallow: /
670
- `;
700
+ ${sitemapLine}`;
671
701
  }
672
702
  return `User-agent: *
673
703
  Allow: /
@@ -992,6 +1022,7 @@ async function prerender({
992
1022
  website = null,
993
1023
  websiteId = "",
994
1024
  redirects = [],
1025
+ pageSlugMap = {},
995
1026
  llm = {}
996
1027
  } = {}) {
997
1028
  var _a, _b, _c, _d, _e, _f;
@@ -1099,6 +1130,7 @@ async function prerender({
1099
1130
  template,
1100
1131
  website,
1101
1132
  websiteId,
1133
+ pageSlugMap,
1102
1134
  resolveCache,
1103
1135
  llm
1104
1136
  });
@@ -1148,8 +1180,8 @@ async function prerender({
1148
1180
  }
1149
1181
  const canonicalBase = (((_a = website == null ? void 0 : website.seo) == null ? void 0 : _a.canonical_base_url) || (website == null ? void 0 : website.domain) || "").replace(/\/$/, "");
1150
1182
  if (writeSharedAssets) {
1151
- const sitemapPaths = rendered.filter((p) => !noindexPaths.has(p));
1152
- if (!((_b = website == null ? void 0 : website.seo) == null ? void 0 : _b.noindex) && canonicalBase && sitemapPaths.length > 0) {
1183
+ const sitemapPaths = ((_b = website == null ? void 0 : website.seo) == null ? void 0 : _b.noindex) ? rendered : rendered.filter((p) => !noindexPaths.has(p));
1184
+ if (canonicalBase && sitemapPaths.length > 0) {
1153
1185
  const artifacts = generateSitemapArtifacts({
1154
1186
  routes: sitemapPaths.map((routePath) => ({
1155
1187
  path: routePath,
@@ -1573,7 +1605,7 @@ async function validateSsgOutput(options) {
1573
1605
  if (!htmlFiles.length) failures.push("output contains no HTML files");
1574
1606
  if (!hydratedFiles) failures.push("output contains no prerendered Blox hydration state");
1575
1607
  const siteNoindex = await readSiteNoindex(outDir);
1576
- const optionalWhenNoindex = /* @__PURE__ */ new Set(["sitemap.xml", "llms.txt", "llms-full.txt"]);
1608
+ const optionalWhenNoindex = /* @__PURE__ */ new Set(["llms.txt", "llms-full.txt"]);
1577
1609
  for (const required of requiredFiles) {
1578
1610
  if (siteNoindex && optionalWhenNoindex.has(required)) continue;
1579
1611
  try {
package/package.json CHANGED
@@ -1,125 +1,126 @@
1
1
  {
2
- "name": "@bagelink/blox",
3
- "type": "module",
4
- "version": "1.17.6",
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": [
34
- "**/*.css",
35
- "**/*.vue"
36
- ],
37
- "exports": {
38
- "./package.json": "./package.json",
39
- "./vite": {
40
- "types": "./dist/vite-plugin.d.ts",
41
- "import": "./dist/vite-plugin.mjs"
42
- },
43
- ".": {
44
- "types": "./dist/index.d.ts",
45
- "require": "./dist/index.cjs",
46
- "import": "./dist/index.mjs"
47
- },
48
- "./ssg": {
49
- "types": "./dist/ssg/index.d.ts",
50
- "import": "./dist/ssg/index.mjs"
51
- },
52
- "./ssg/client": {
53
- "types": "./dist/ssg/client.d.ts",
54
- "import": "./dist/ssg/client.mjs"
55
- },
56
- "./ssg/build-grant": {
57
- "types": "./dist/ssg/build-grant.d.ts",
58
- "import": "./dist/ssg/build-grant.mjs"
59
- },
60
- "./style.css": "./dist/style.css",
61
- "./dist/style.css": "./dist/style.css"
62
- },
63
- "main": "./dist/index.cjs",
64
- "module": "./dist/index.mjs",
65
- "types": "./dist/index.d.ts",
66
- "typesVersions": {
67
- "*": {
68
- "*": [
69
- "./dist/*",
70
- "./dist/index.d.ts"
71
- ]
72
- }
73
- },
74
- "files": [
75
- "dist",
76
- "core",
77
- "components",
78
- "config",
79
- "ssg",
80
- "utils",
81
- "views",
82
- "setup.ts",
83
- "index.ts",
84
- "README.md"
85
- ],
86
- "publishConfig": {
87
- "access": "public"
88
- },
89
- "peerDependencies": {
90
- "@bagelink/vue": "*",
91
- "happy-dom": ">=14.0.0",
92
- "vite": ">=5.0.0",
93
- "vue": "^3.3.0",
94
- "vue-router": "^4.0.0"
95
- },
96
- "peerDependenciesMeta": {
97
- "happy-dom": {
98
- "optional": true
99
- },
100
- "vite": {
101
- "optional": true
102
- }
103
- },
104
- "devDependencies": {
105
- "@vitejs/plugin-vue": "^5.2.4",
106
- "@vue/tsconfig": "^0.7.0",
107
- "typescript": "^5.9.3",
108
- "vite": "^5.4.21",
109
- "vite-plugin-dts": "^4.5.4",
110
- "vite-tsconfig-paths": "^5.1.4",
111
- "vitest": "^3.2.7",
112
- "vue": "^3.5.43",
113
- "vue-router": "^4.6.4",
114
- "vue-tsc": "^2.2.12"
115
- },
116
- "dependencies": {
117
- "magic-string": "^0.30.21",
118
- "pinia": "^3.0.4"
119
- },
120
- "scripts": {
121
- "dev": "vite build --watch",
122
- "build": "vite build",
123
- "typecheck": "vue-tsc --noEmit"
124
- }
125
- }
2
+ "name": "@bagelink/blox",
3
+ "type": "module",
4
+ "version": "1.18.6",
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": [
34
+ "**/*.css",
35
+ "**/*.vue"
36
+ ],
37
+ "exports": {
38
+ "./package.json": "./package.json",
39
+ "./vite": {
40
+ "types": "./dist/vite-plugin.d.ts",
41
+ "import": "./dist/vite-plugin.mjs"
42
+ },
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "require": "./dist/index.cjs",
46
+ "import": "./dist/index.mjs"
47
+ },
48
+ "./ssg": {
49
+ "types": "./dist/ssg/index.d.ts",
50
+ "import": "./dist/ssg/index.mjs"
51
+ },
52
+ "./ssg/client": {
53
+ "types": "./dist/ssg/client.d.ts",
54
+ "import": "./dist/ssg/client.mjs"
55
+ },
56
+ "./ssg/build-grant": {
57
+ "types": "./dist/ssg/build-grant.d.ts",
58
+ "import": "./dist/ssg/build-grant.mjs"
59
+ },
60
+ "./style.css": "./dist/style.css",
61
+ "./dist/style.css": "./dist/style.css"
62
+ },
63
+ "main": "./dist/index.cjs",
64
+ "module": "./dist/index.mjs",
65
+ "types": "./dist/index.d.ts",
66
+ "typesVersions": {
67
+ "*": {
68
+ "*": [
69
+ "./dist/*",
70
+ "./dist/index.d.ts"
71
+ ]
72
+ }
73
+ },
74
+ "files": [
75
+ "dist",
76
+ "core",
77
+ "components",
78
+ "config",
79
+ "ssg",
80
+ "utils",
81
+ "views",
82
+ "setup.ts",
83
+ "index.ts",
84
+ "README.md"
85
+ ],
86
+ "scripts": {
87
+ "prepublishOnly": "pnpm build",
88
+ "dev": "vite build --watch",
89
+ "build": "vite build",
90
+ "typecheck": "vue-tsc --noEmit"
91
+ },
92
+ "publishConfig": {
93
+ "access": "public"
94
+ },
95
+ "peerDependencies": {
96
+ "@bagelink/vue": "*",
97
+ "happy-dom": ">=14.0.0",
98
+ "vite": ">=5.0.0",
99
+ "vue": "^3.3.0",
100
+ "vue-router": "^4.0.0"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "happy-dom": {
104
+ "optional": true
105
+ },
106
+ "vite": {
107
+ "optional": true
108
+ }
109
+ },
110
+ "devDependencies": {
111
+ "@vitejs/plugin-vue": "^5.2.4",
112
+ "@vue/tsconfig": "^0.7.0",
113
+ "typescript": "^5.9.3",
114
+ "vite": "^5.4.21",
115
+ "vite-plugin-dts": "^4.5.4",
116
+ "vite-tsconfig-paths": "^5.1.4",
117
+ "vitest": "^3.2.7",
118
+ "vue": "^3.5.43",
119
+ "vue-router": "^4.6.4",
120
+ "vue-tsc": "^2.2.12"
121
+ },
122
+ "dependencies": {
123
+ "magic-string": "^0.30.21",
124
+ "pinia": "^3.0.4"
125
+ }
126
+ }
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,59 +0,0 @@
1
- const PREFERRED_CONTEXT_KEYS = ["$page", "$post", "$item", "$article", "$product", "$event", "$author"];
2
- const TITLE_FIELDS = ["meta_title", "metaTitle", "title", "name", "productName", "displayName"];
3
- function primaryPageContext(contexts) {
4
- if (!contexts) return null;
5
- const keys = [
6
- ...PREFERRED_CONTEXT_KEYS.filter((key) => key in contexts),
7
- ...Object.keys(contexts).filter((key) => key !== "$website" && !PREFERRED_CONTEXT_KEYS.includes(key)).sort()
8
- ];
9
- for (const key of keys) {
10
- const ctx = contexts[key];
11
- if (ctx != null && typeof ctx === "object") return { key, ctx };
12
- }
13
- return null;
14
- }
15
- function contextPageTitle(context) {
16
- if (!context) return null;
17
- for (const field of TITLE_FIELDS) {
18
- const value = context[field];
19
- if (typeof value === "string" && value.trim()) return value.trim();
20
- }
21
- return null;
22
- }
23
- function siteNameFromContexts(contexts) {
24
- const website = contexts == null ? void 0 : contexts.$website;
25
- const seo = website == null ? void 0 : website.seo;
26
- const siteName = seo && typeof seo === "object" ? seo.site_name : website == null ? void 0 : website.site_name;
27
- return typeof siteName === "string" && siteName.trim() ? siteName.trim() : null;
28
- }
29
- function withSiteName(title, siteName) {
30
- if (!siteName || title.includes(siteName)) return title;
31
- return `${title} · ${siteName}`;
32
- }
33
- function resolvePageTitle(resolved, options = {}) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h;
35
- const hasBinding = !!((_a = resolved.page) == null ? void 0 : _a.data_bindings) && Object.keys(resolved.page.data_bindings).length > 0;
36
- const contextTitle = hasBinding ? contextPageTitle((_b = primaryPageContext(resolved.contexts)) == null ? void 0 : _b.ctx) : null;
37
- const overrideTitle = (_c = options.override) == null ? void 0 : _c.trim();
38
- if (overrideTitle) return overrideTitle;
39
- if (contextTitle) return withSiteName(contextTitle, options.siteName);
40
- if ((_e = (_d = resolved.page) == null ? void 0 : _d.meta_title) == null ? void 0 : _e.trim()) return resolved.page.meta_title.trim();
41
- if ((_g = (_f = resolved.page) == null ? void 0 : _f.title) == null ? void 0 : _g.trim()) return withSiteName(resolved.page.title.trim(), options.siteName);
42
- if ((_h = options.defaultTitle) == null ? void 0 : _h.trim()) return options.defaultTitle.trim();
43
- if (options.siteName) return options.siteName;
44
- return null;
45
- }
46
- function preserveCurrentSiteSuffix(title, currentTitle) {
47
- const separator = " · ";
48
- const suffixIndex = currentTitle.lastIndexOf(separator);
49
- if (suffixIndex < 0) return title;
50
- const siteName = currentTitle.slice(suffixIndex + separator.length).trim();
51
- return withSiteName(title, siteName);
52
- }
53
- export {
54
- preserveCurrentSiteSuffix as a,
55
- contextPageTitle as c,
56
- primaryPageContext as p,
57
- resolvePageTitle as r,
58
- siteNameFromContexts as s
59
- };
@@ -1,58 +0,0 @@
1
- "use strict";
2
- const PREFERRED_CONTEXT_KEYS = ["$page", "$post", "$item", "$article", "$product", "$event", "$author"];
3
- const TITLE_FIELDS = ["meta_title", "metaTitle", "title", "name", "productName", "displayName"];
4
- function primaryPageContext(contexts) {
5
- if (!contexts) return null;
6
- const keys = [
7
- ...PREFERRED_CONTEXT_KEYS.filter((key) => key in contexts),
8
- ...Object.keys(contexts).filter((key) => key !== "$website" && !PREFERRED_CONTEXT_KEYS.includes(key)).sort()
9
- ];
10
- for (const key of keys) {
11
- const ctx = contexts[key];
12
- if (ctx != null && typeof ctx === "object") return { key, ctx };
13
- }
14
- return null;
15
- }
16
- function contextPageTitle(context) {
17
- if (!context) return null;
18
- for (const field of TITLE_FIELDS) {
19
- const value = context[field];
20
- if (typeof value === "string" && value.trim()) return value.trim();
21
- }
22
- return null;
23
- }
24
- function siteNameFromContexts(contexts) {
25
- const website = contexts == null ? void 0 : contexts.$website;
26
- const seo = website == null ? void 0 : website.seo;
27
- const siteName = seo && typeof seo === "object" ? seo.site_name : website == null ? void 0 : website.site_name;
28
- return typeof siteName === "string" && siteName.trim() ? siteName.trim() : null;
29
- }
30
- function withSiteName(title, siteName) {
31
- if (!siteName || title.includes(siteName)) return title;
32
- return `${title} · ${siteName}`;
33
- }
34
- function resolvePageTitle(resolved, options = {}) {
35
- var _a, _b, _c, _d, _e, _f, _g, _h;
36
- const hasBinding = !!((_a = resolved.page) == null ? void 0 : _a.data_bindings) && Object.keys(resolved.page.data_bindings).length > 0;
37
- const contextTitle = hasBinding ? contextPageTitle((_b = primaryPageContext(resolved.contexts)) == null ? void 0 : _b.ctx) : null;
38
- const overrideTitle = (_c = options.override) == null ? void 0 : _c.trim();
39
- if (overrideTitle) return overrideTitle;
40
- if (contextTitle) return withSiteName(contextTitle, options.siteName);
41
- if ((_e = (_d = resolved.page) == null ? void 0 : _d.meta_title) == null ? void 0 : _e.trim()) return resolved.page.meta_title.trim();
42
- if ((_g = (_f = resolved.page) == null ? void 0 : _f.title) == null ? void 0 : _g.trim()) return withSiteName(resolved.page.title.trim(), options.siteName);
43
- if ((_h = options.defaultTitle) == null ? void 0 : _h.trim()) return options.defaultTitle.trim();
44
- if (options.siteName) return options.siteName;
45
- return null;
46
- }
47
- function preserveCurrentSiteSuffix(title, currentTitle) {
48
- const separator = " · ";
49
- const suffixIndex = currentTitle.lastIndexOf(separator);
50
- if (suffixIndex < 0) return title;
51
- const siteName = currentTitle.slice(suffixIndex + separator.length).trim();
52
- return withSiteName(title, siteName);
53
- }
54
- exports.contextPageTitle = contextPageTitle;
55
- exports.preserveCurrentSiteSuffix = preserveCurrentSiteSuffix;
56
- exports.primaryPageContext = primaryPageContext;
57
- exports.resolvePageTitle = resolvePageTitle;
58
- exports.siteNameFromContexts = siteNameFromContexts;