qarpeo 0.1.2 → 0.1.4

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/dist/module.mjs CHANGED
@@ -19,7 +19,7 @@ import 'drizzle-orm/node-sqlite';
19
19
  import 'node:process';
20
20
  import 'node:readline/promises';
21
21
 
22
- const version = "0.1.2";
22
+ const version = "0.1.4";
23
23
 
24
24
  function ensureDevEnv(rootDir) {
25
25
  const envPath = join(rootDir, ".env");
@@ -240,7 +240,7 @@ async function discoverSources(contentDir) {
240
240
  const fullPath = resolve(currentDir, entry.name);
241
241
  if (entry.isDirectory()) {
242
242
  await walk(fullPath);
243
- } else if (entry.isFile() && entry.name === ".sources.json") {
243
+ } else if (entry.isFile() && (entry.name === ".sources.json" || entry.name === "_sources.json")) {
244
244
  try {
245
245
  const raw = await readFile(fullPath, "utf8");
246
246
  const parsed = JSON.parse(raw);
@@ -279,7 +279,7 @@ async function resolveAllCmsSources(options) {
279
279
  await downloadTemplate(src.from, {
280
280
  dir: targetDir,
281
281
  preferOffline: true,
282
- auth: process.env.GITHUB_TOKEN || process.env.GH_TOKEN
282
+ auth: src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
283
283
  });
284
284
  resolvedDir = targetDir;
285
285
  } catch (err) {
@@ -323,7 +323,7 @@ async function resolveAllCmsSources(options) {
323
323
  await downloadTemplate(src.from, {
324
324
  dir: targetDir,
325
325
  preferOffline: true,
326
- auth: process.env.GITHUB_TOKEN || process.env.GH_TOKEN
326
+ auth: src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
327
327
  });
328
328
  resolvedDir = targetDir;
329
329
  } catch (err) {
@@ -439,14 +439,17 @@ async function scanContentEntries(options) {
439
439
  if (navMeta.private === true || navMeta.draft === true || navMeta.exclude === true) {
440
440
  return;
441
441
  }
442
- const isTopLevelSection = Boolean(relBase && !relBase.includes("/"));
443
- const currentSectionNavMeta = sectionNavMeta || (isTopLevelSection ? {
444
- title: navMeta.title || stripOrderPrefix(relBase).charAt(0).toUpperCase() + stripOrderPrefix(relBase).slice(1).replace(/-/g, " "),
442
+ const relSegments = relBase ? relBase.split("/").filter(Boolean) : [];
443
+ const isTopLevelSection = Boolean(
444
+ relSegments.length === 1 || relSegments.length === 2 && (relSegments[0].includes("docs") || collectionsConfig[stripOrderPrefix(relSegments[0])])
445
+ );
446
+ const currentSectionNavMeta = isTopLevelSection ? {
447
+ title: navMeta.title || stripOrderPrefix(relSegments[relSegments.length - 1]).charAt(0).toUpperCase() + stripOrderPrefix(relSegments[relSegments.length - 1]).slice(1).replace(/-/g, " "),
445
448
  icon: navMeta.icon,
446
- order: navMeta.order ?? extractOrderPrefix(relBase),
449
+ order: navMeta.order ?? extractOrderPrefix(relSegments[relSegments.length - 1]),
447
450
  navigation: navMeta.navigation,
448
451
  hidden: navMeta.hidden
449
- } : void 0);
452
+ } : sectionNavMeta;
450
453
  for (const item of dirItems) {
451
454
  if (item.name.startsWith(".") || item.name.startsWith("_")) continue;
452
455
  const subRel = relBase ? `${relBase}/${item.name}` : item.name;
@@ -526,7 +529,7 @@ async function scanContentEntries(options) {
526
529
  const itemOrder = typeof fm.order === "number" ? fm.order : isIndex ? 0 : fileNum != null ? fileNum : 100 + orderCounter++;
527
530
  const groupOrderOffset = typeof groupMeta?.order === "number" ? groupMeta.order * 100 : 0;
528
531
  const finalOrder = folderOrder + subfolderOffset + groupOrderOffset + itemOrder;
529
- const itemTitle = fm.title || (isIndex ? navMeta.title || title : title);
532
+ const itemTitle = fm.navigation?.title || fm.title || (isIndex ? navMeta.title || title : title);
530
533
  const effectiveSection = currentSectionNavMeta?.title ? { title: currentSectionNavMeta.title, icon: currentSectionNavMeta.icon } : navMeta.title ? { title: navMeta.title, icon: navMeta.icon } : void 0;
531
534
  const isDraft = Boolean(
532
535
  fm.draft === true || fm.private === true || fm.status === "draft" || navMeta.draft === true || navMeta.private === true
@@ -570,6 +573,54 @@ async function scanContentEntries(options) {
570
573
  created_at: now,
571
574
  updated_at: now
572
575
  });
576
+ } else if (item.isFile() && (item.name.endsWith(".json") || item.name.endsWith(".yaml") || item.name.endsWith(".yml"))) {
577
+ if (item.name.startsWith(".navigation.") || item.name === ".sources.json") continue;
578
+ const filePath = `${dir}/${item.name}`;
579
+ let rawContent = "";
580
+ try {
581
+ rawContent = await readFile(filePath, "utf8");
582
+ } catch {
583
+ continue;
584
+ }
585
+ const fileHash = computeContentHash(rawContent);
586
+ let parsed = {};
587
+ if (item.name.endsWith(".json")) {
588
+ try {
589
+ parsed = JSON.parse(rawContent);
590
+ } catch {
591
+ }
592
+ } else {
593
+ try {
594
+ parsed = parse(rawContent) || {};
595
+ } catch {
596
+ }
597
+ }
598
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
599
+ const colId = item.name.replace(/\.(json|ya?ml)$/, "").toLowerCase();
600
+ const slug = parsed.slug || colId;
601
+ const entryPath = `/${colId}`;
602
+ const title = parsed.title || colId.charAt(0).toUpperCase() + colId.slice(1);
603
+ const description = parsed.description || null;
604
+ entries.push({
605
+ collection_id: colId,
606
+ slug,
607
+ path: entryPath,
608
+ title,
609
+ description,
610
+ cover_image: parsed.coverImage || parsed.cover_image || null,
611
+ tags: Array.isArray(parsed.tags) ? parsed.tags.join(",") : parsed.tags || null,
612
+ order: typeof parsed.order === "number" ? parsed.order : 0,
613
+ content_md: "",
614
+ content_html: "",
615
+ metadata_json: JSON.stringify(parsed),
616
+ status: "published",
617
+ source: "file",
618
+ file_path: filePath,
619
+ content_hash: fileHash,
620
+ published_at: now,
621
+ created_at: now,
622
+ updated_at: now
623
+ });
573
624
  }
574
625
  }
575
626
  };
@@ -3306,8 +3357,15 @@ export default queueHandler;
3306
3357
  sources: resolvedSources,
3307
3358
  exclude: cmsConfig.exclude
3308
3359
  });
3309
- return `export const manifestEntries = ${JSON.stringify(entries)};
3310
- export const manifestCollections = ${JSON.stringify(cmsConfig.collections || {})};
3360
+ const payload = JSON.stringify({
3361
+ entries,
3362
+ collections: cmsConfig.collections || {}
3363
+ });
3364
+ const b64 = Buffer.from(payload).toString("base64");
3365
+ return `const raw = /*#__PURE__*/ Buffer.from("${b64}", "base64").toString("utf-8");
3366
+ const parsed = JSON.parse(raw);
3367
+ export const manifestEntries = parsed.entries;
3368
+ export const manifestCollections = parsed.collections;
3311
3369
  `;
3312
3370
  } catch (err) {
3313
3371
  console.warn("[qarpeo:cms] Error scanning CMS manifest at build time:", err);
@@ -3318,9 +3376,39 @@ export const manifestCollections = ${JSON.stringify(cmsConfig.collections || {})
3318
3376
  }
3319
3377
  });
3320
3378
  nuxt.options.alias["#qarpeo/cms/manifest"] = cmsManifestTemplate.dst;
3321
- nuxt.hook("nitro:config", (nitroConfig) => {
3379
+ nuxt.hook("nitro:config", async (nitroConfig) => {
3322
3380
  nitroConfig.alias = nitroConfig.alias || {};
3323
3381
  nitroConfig.alias["#qarpeo/cms/manifest"] = cmsManifestTemplate.dst;
3382
+ const routeRules = nuxt.options.routeRules || {};
3383
+ const prerenderPatterns = Object.entries(routeRules).filter(([_, rule]) => rule?.prerender === true).map(([pattern]) => pattern);
3384
+ if (prerenderPatterns.length > 0) {
3385
+ try {
3386
+ const entries = await scanContentEntries({
3387
+ contentDir: resolvedContentDir,
3388
+ collectionsConfig: cmsConfig.collections,
3389
+ sources: resolvedSources,
3390
+ exclude: cmsConfig.exclude
3391
+ });
3392
+ const matchingRoutes = entries.map((e) => e.path).filter((p) => Boolean(p) && matchPathPatterns(p, prerenderPatterns));
3393
+ if (matchingRoutes.length > 0) {
3394
+ nitroConfig.prerender = nitroConfig.prerender || {};
3395
+ nitroConfig.prerender.autoSubfolderIndex = true;
3396
+ nitroConfig.prerender.routes = Array.from(
3397
+ /* @__PURE__ */ new Set([...nitroConfig.prerender.routes || [], ...matchingRoutes])
3398
+ );
3399
+ nitroConfig.hooks = nitroConfig.hooks || {};
3400
+ const prevHook = nitroConfig.hooks["prerender:generate"];
3401
+ nitroConfig.hooks["prerender:generate"] = async (route, nitro) => {
3402
+ if (prevHook) await prevHook(route, nitro);
3403
+ if (route.fileName && !route.fileName.includes(".")) {
3404
+ route.fileName = `${route.fileName}/index.html`;
3405
+ }
3406
+ };
3407
+ }
3408
+ } catch (err) {
3409
+ console.warn("[qarpeo:cms] Error configuring SSG prerender routes:", err);
3410
+ }
3411
+ }
3324
3412
  });
3325
3413
  addNitroPlugin(resolver.resolve("./runtime/server/plugins/cms"));
3326
3414
  addServerHandler({
@@ -135,7 +135,7 @@ export function queryCollection(collection) {
135
135
  _path = p;
136
136
  if (_targetCollection === "content") {
137
137
  const parts = p.replace(/^\//, "").split("/");
138
- if (parts.length > 1 && parts[0]) {
138
+ if (parts.length >= 1 && parts[0]) {
139
139
  _targetCollection = parts[0];
140
140
  }
141
141
  }
@@ -8,7 +8,11 @@ import { fireCMSWebhooks, fireCMSDeployTrigger } from "./cms-events.mjs";
8
8
  import { getQarpeoConfig } from "./config.mjs";
9
9
  import { getAuthContext } from "./context.mjs";
10
10
  function getCMSDb(event) {
11
- return getD1Binding("DB", event);
11
+ try {
12
+ return getD1Binding("DB", event);
13
+ } catch {
14
+ return null;
15
+ }
12
16
  }
13
17
  function nanoid(size = 21) {
14
18
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -582,12 +586,36 @@ function rowToCollection(row, config) {
582
586
  };
583
587
  }
584
588
  export async function listCMSCollections(event) {
585
- await ensureCMSSynced(event);
589
+ await ensureCMSSynced(event).catch(() => {
590
+ });
586
591
  const db = getCMSDb(event);
587
- const results = await db.prepare('SELECT * FROM _qarpeo_cms_collections ORDER BY "order" ASC, name ASC').all();
588
- return (results.results || []).map(
589
- (r) => rowToCollection(r)
590
- );
592
+ if (db) {
593
+ try {
594
+ const results = await db.prepare('SELECT * FROM _qarpeo_cms_collections ORDER BY "order" ASC, name ASC').all();
595
+ return (results.results || []).map(
596
+ (r) => rowToCollection(r)
597
+ );
598
+ } catch {
599
+ }
600
+ }
601
+ try {
602
+ const { manifestCollections } = await import("#qarpeo/cms/manifest");
603
+ if (manifestCollections) {
604
+ return Object.entries(manifestCollections).map(([id, cfg]) => ({
605
+ id,
606
+ name: cfg.name || id.charAt(0).toUpperCase() + id.slice(1).replace(/-/g, " "),
607
+ description: cfg.description,
608
+ schemaJson: JSON.stringify(cfg.fields || {}),
609
+ fields: cfg.fields || {},
610
+ source: "config",
611
+ order: cfg.order ?? 0,
612
+ createdAt: 0,
613
+ updatedAt: 0
614
+ }));
615
+ }
616
+ } catch {
617
+ }
618
+ return [];
591
619
  }
592
620
  export async function createCMSCollection(event, data) {
593
621
  const db = getCMSDb(event);
@@ -1701,6 +1729,7 @@ export async function verifyPreviewToken(event, collection, slugOrId, token, exp
1701
1729
  }
1702
1730
  export async function ensureCMSTables(event) {
1703
1731
  const db = getCMSDb(event);
1732
+ if (!db) return;
1704
1733
  const statements = [
1705
1734
  `CREATE TABLE IF NOT EXISTS _qarpeo_cms_collections (id TEXT PRIMARY KEY, tenant_id TEXT, name TEXT NOT NULL, description TEXT, schema_json TEXT NOT NULL DEFAULT '{}', source TEXT NOT NULL DEFAULT 'db', "order" INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);`,
1706
1735
  `CREATE TABLE IF NOT EXISTS _qarpeo_cms_entries (id TEXT PRIMARY KEY, tenant_id TEXT, collection_id TEXT NOT NULL, slug TEXT NOT NULL, title TEXT NOT NULL, description TEXT, cover_image TEXT, tags TEXT, "order" INTEGER NOT NULL DEFAULT 0, content_md TEXT NOT NULL DEFAULT '', content_html TEXT NOT NULL DEFAULT '', metadata_json TEXT DEFAULT '{}', status TEXT NOT NULL DEFAULT 'draft', source TEXT NOT NULL DEFAULT 'db', path TEXT, file_path TEXT, content_hash TEXT, author_id TEXT, locale TEXT NOT NULL DEFAULT 'en', version TEXT NOT NULL DEFAULT 'latest', published_at INTEGER, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);`,
@@ -1821,6 +1850,8 @@ async function _runCMSSync(event) {
1821
1850
  }
1822
1851
  let prodTablesChecked = false;
1823
1852
  export async function ensureCMSSynced(event) {
1853
+ const db = getCMSDb(event);
1854
+ if (!db) return;
1824
1855
  if (process.env.NODE_ENV !== "production" || import.meta.dev) {
1825
1856
  if (!hasInitialSynced) {
1826
1857
  if (!syncPromise) {
@@ -2720,27 +2751,30 @@ export async function getCMSEntryByPath(event, collectionId, path, locale, optio
2720
2751
  if (auth?.user && config.roles.some((r) => r === auth.role || auth.isAdmin)) {
2721
2752
  allowDraft = true;
2722
2753
  }
2723
- if (!allowDraft) {
2754
+ if (!allowDraft && db) {
2724
2755
  const token = options.previewToken || cookieObj?.token;
2725
2756
  const expires = options.previewExpires || cookieObj?.expires;
2726
2757
  if (token && expires) {
2727
- const candidate = await db.prepare(
2728
- `SELECT id, slug, collection_id FROM _qarpeo_cms_entries WHERE (collection_id = ? OR ? = 'content') AND (path = ? OR path = ?) ${tenantClause} LIMIT 1`
2729
- ).bind(collectionId, collectionId, cleanPath, `${cleanPath}/`).first();
2730
- if (candidate) {
2731
- allowDraft = await verifyPreviewToken(
2732
- event,
2733
- candidate.collection_id,
2734
- candidate.id,
2735
- token,
2736
- expires
2737
- ) || await verifyPreviewToken(
2738
- event,
2739
- candidate.collection_id,
2740
- candidate.slug,
2741
- token,
2742
- expires
2743
- );
2758
+ try {
2759
+ const candidate = await db.prepare(
2760
+ `SELECT id, slug, collection_id FROM _qarpeo_cms_entries WHERE (collection_id = ? OR ? = 'content') AND (path = ? OR path = ?) ${tenantClause} LIMIT 1`
2761
+ ).bind(collectionId, collectionId, cleanPath, `${cleanPath}/`).first();
2762
+ if (candidate) {
2763
+ allowDraft = await verifyPreviewToken(
2764
+ event,
2765
+ candidate.collection_id,
2766
+ candidate.id,
2767
+ token,
2768
+ expires
2769
+ ) || await verifyPreviewToken(
2770
+ event,
2771
+ candidate.collection_id,
2772
+ candidate.slug,
2773
+ token,
2774
+ expires
2775
+ );
2776
+ }
2777
+ } catch {
2744
2778
  }
2745
2779
  }
2746
2780
  }
@@ -2748,30 +2782,35 @@ export async function getCMSEntryByPath(event, collectionId, path, locale, optio
2748
2782
  const statusFilter = allowDraft ? "status IN ('draft', 'published', 'scheduled')" : "status = 'published'";
2749
2783
  const statusOrder = allowDraft ? "CASE WHEN status = 'draft' THEN 1 WHEN status = 'scheduled' THEN 2 ELSE 3 END," : "";
2750
2784
  let row = null;
2751
- if (locale) {
2752
- const bindsLocale = tenantId ? [collectionId, cleanPath, `${cleanPath}/`, locale, tenantId] : [collectionId, cleanPath, `${cleanPath}/`, locale];
2753
- row = await db.prepare(
2754
- `SELECT * FROM _qarpeo_cms_entries WHERE collection_id = ? AND (path = ? OR path = ?) AND locale = ? AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} created_at DESC LIMIT 1`
2755
- ).bind(...bindsLocale).first();
2756
- }
2757
- const binds1 = tenantId ? [collectionId, cleanPath, `${cleanPath}/`, tenantId] : [collectionId, cleanPath, `${cleanPath}/`];
2758
- if (!row) {
2759
- row = await db.prepare(
2760
- `SELECT * FROM _qarpeo_cms_entries WHERE collection_id = ? AND (path = ? OR path = ?) AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} CASE WHEN locale = 'en' THEN 1 ELSE 2 END LIMIT 1`
2761
- ).bind(...binds1).first();
2762
- }
2763
- if (!row && cleanPath.startsWith(`/${collectionId}`)) {
2764
- const unPrefixed = cleanPath.slice(`/${collectionId}`.length) || "/";
2765
- const binds2 = tenantId ? [collectionId, unPrefixed, `${unPrefixed}/`, tenantId] : [collectionId, unPrefixed, `${unPrefixed}/`];
2766
- row = await db.prepare(
2767
- `SELECT * FROM _qarpeo_cms_entries WHERE collection_id = ? AND (path = ? OR path = ?) AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} created_at DESC LIMIT 1`
2768
- ).bind(...binds2).first();
2769
- }
2770
- if (!row) {
2771
- const binds3 = tenantId ? [cleanPath, `${cleanPath}/`, tenantId] : [cleanPath, `${cleanPath}/`];
2772
- row = await db.prepare(
2773
- `SELECT * FROM _qarpeo_cms_entries WHERE (path = ? OR path = ?) AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} created_at DESC LIMIT 1`
2774
- ).bind(...binds3).first();
2785
+ if (db) {
2786
+ try {
2787
+ if (locale) {
2788
+ const bindsLocale = tenantId ? [collectionId, cleanPath, `${cleanPath}/`, locale, tenantId] : [collectionId, cleanPath, `${cleanPath}/`, locale];
2789
+ row = await db.prepare(
2790
+ `SELECT * FROM _qarpeo_cms_entries WHERE collection_id = ? AND (path = ? OR path = ?) AND locale = ? AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} created_at DESC LIMIT 1`
2791
+ ).bind(...bindsLocale).first();
2792
+ }
2793
+ const binds1 = tenantId ? [collectionId, cleanPath, `${cleanPath}/`, tenantId] : [collectionId, cleanPath, `${cleanPath}/`];
2794
+ if (!row) {
2795
+ row = await db.prepare(
2796
+ `SELECT * FROM _qarpeo_cms_entries WHERE collection_id = ? AND (path = ? OR path = ?) AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} CASE WHEN locale = 'en' THEN 1 ELSE 2 END LIMIT 1`
2797
+ ).bind(...binds1).first();
2798
+ }
2799
+ if (!row && cleanPath.startsWith(`/${collectionId}`)) {
2800
+ const unPrefixed = cleanPath.slice(`/${collectionId}`.length) || "/";
2801
+ const binds2 = tenantId ? [collectionId, unPrefixed, `${unPrefixed}/`, tenantId] : [collectionId, unPrefixed, `${unPrefixed}/`];
2802
+ row = await db.prepare(
2803
+ `SELECT * FROM _qarpeo_cms_entries WHERE collection_id = ? AND (path = ? OR path = ?) AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} created_at DESC LIMIT 1`
2804
+ ).bind(...binds2).first();
2805
+ }
2806
+ if (!row) {
2807
+ const binds3 = tenantId ? [cleanPath, `${cleanPath}/`, tenantId] : [cleanPath, `${cleanPath}/`];
2808
+ row = await db.prepare(
2809
+ `SELECT * FROM _qarpeo_cms_entries WHERE (path = ? OR path = ?) AND ${statusFilter}${tenantClause} ORDER BY ${statusOrder} created_at DESC LIMIT 1`
2810
+ ).bind(...binds3).first();
2811
+ }
2812
+ } catch {
2813
+ }
2775
2814
  }
2776
2815
  if (!row) {
2777
2816
  try {
@@ -2846,6 +2885,7 @@ export async function getCMSEntrySurroundings(event, collectionId, path, fields
2846
2885
  } catch (err) {
2847
2886
  console.warn("[qarpeo:cms] getCMSEntrySurroundings navTree lookup failed:", err);
2848
2887
  }
2888
+ if (!db) return [null, null];
2849
2889
  const tenantId = getCMSTenantId(event);
2850
2890
  const tenantClause = tenantId ? " AND (tenant_id = ? OR tenant_id IS NULL)" : "";
2851
2891
  const binds = tenantId ? [collectionId, tenantId] : [collectionId];
@@ -2935,8 +2975,29 @@ export async function getCMSNavigationTree(event, collectionId, options) {
2935
2975
  rootBinds.push(navRootTenantId);
2936
2976
  }
2937
2977
  rootSql += ' ORDER BY "order" ASC';
2938
- const rootEntries = await db.prepare(rootSql).bind(...rootBinds).all();
2939
- const rows2 = rootEntries.results || [];
2978
+ let rows2 = [];
2979
+ if (db) {
2980
+ try {
2981
+ const rootEntries = await db.prepare(rootSql).bind(...rootBinds).all();
2982
+ rows2 = rootEntries.results || [];
2983
+ } catch {
2984
+ }
2985
+ }
2986
+ if (!rows2.length) {
2987
+ try {
2988
+ const { manifestEntries } = await import("#qarpeo/cms/manifest");
2989
+ rows2 = (manifestEntries || []).filter((e) => e.collection_id === "content").map((e) => ({
2990
+ id: e.id,
2991
+ slug: e.slug,
2992
+ path: e.path,
2993
+ title: e.title,
2994
+ order: e.order ?? 0,
2995
+ metadata_json: typeof e.metadata_json === "string" ? e.metadata_json : JSON.stringify(e.metadata || {}),
2996
+ status: e.status || "published"
2997
+ }));
2998
+ } catch {
2999
+ }
3000
+ }
2940
3001
  for (const r of rows2) {
2941
3002
  let meta = {};
2942
3003
  try {
@@ -2991,8 +3052,28 @@ export async function getCMSNavigationTree(event, collectionId, options) {
2991
3052
  binds.push(searchPath, `${searchPath}/%`);
2992
3053
  }
2993
3054
  sql += ' ORDER BY "order" ASC';
2994
- const all = await db.prepare(sql).bind(...binds).all();
2995
- const rows = all.results || [];
3055
+ let rows = [];
3056
+ if (db) {
3057
+ try {
3058
+ const all = await db.prepare(sql).bind(...binds).all();
3059
+ rows = all.results || [];
3060
+ } catch {
3061
+ }
3062
+ }
3063
+ if (!rows.length) {
3064
+ try {
3065
+ const { manifestEntries } = await import("#qarpeo/cms/manifest");
3066
+ rows = (manifestEntries || []).filter((e) => e.collection_id === collectionId).map((e) => ({
3067
+ id: e.id,
3068
+ slug: e.slug,
3069
+ path: e.path,
3070
+ title: e.title,
3071
+ order: e.order ?? 0,
3072
+ metadata_json: typeof e.metadata_json === "string" ? e.metadata_json : JSON.stringify(e.metadata || {})
3073
+ }));
3074
+ } catch {
3075
+ }
3076
+ }
2996
3077
  const sectionsMap = /* @__PURE__ */ new Map();
2997
3078
  for (const r of rows) {
2998
3079
  let meta = {};
@@ -3013,8 +3094,9 @@ export async function getCMSNavigationTree(event, collectionId, options) {
3013
3094
  const sectionPath = segments.length >= 2 ? `/${segments[0]}/${segments[1]}` : entryPath;
3014
3095
  const defaultSectionTitle = segments.length >= 2 ? segments[1].charAt(0).toUpperCase() + segments[1].slice(1).replace(/-/g, " ") : r.title;
3015
3096
  if (!sectionsMap.has(sectionPath)) {
3097
+ const initialTitle = sectionMeta.title && sectionMeta.title !== "Docs" ? sectionMeta.title : defaultSectionTitle;
3016
3098
  sectionsMap.set(sectionPath, {
3017
- title: sectionMeta.title || defaultSectionTitle,
3099
+ title: initialTitle,
3018
3100
  path: sectionPath,
3019
3101
  icon: sectionMeta.icon,
3020
3102
  children: [],
@@ -3022,8 +3104,17 @@ export async function getCMSNavigationTree(event, collectionId, options) {
3022
3104
  });
3023
3105
  }
3024
3106
  const section = sectionsMap.get(sectionPath);
3025
- const itemTitle = meta._itemTitle || r.title;
3026
- if (sectionMeta.title) {
3107
+ const itemTitle = meta.navigation?.title || meta._itemTitle || r.title;
3108
+ if (entryPath === sectionPath) {
3109
+ const explicitNavTitle = meta.navigation?.title || meta._nav?.title;
3110
+ if (explicitNavTitle) {
3111
+ section.title = explicitNavTitle;
3112
+ }
3113
+ const explicitIcon = meta.navigation?.icon || meta._nav?.icon;
3114
+ if (explicitIcon) {
3115
+ section.icon = explicitIcon;
3116
+ }
3117
+ } else if (sectionMeta.title && sectionMeta.title !== "Docs" && !meta._group && (!section.title || section.title === defaultSectionTitle)) {
3027
3118
  section.title = sectionMeta.title;
3028
3119
  if (sectionMeta.icon) section.icon = sectionMeta.icon;
3029
3120
  }
package/dist/types.d.ts CHANGED
@@ -1846,6 +1846,8 @@ export interface CMSSourceConfig {
1846
1846
  include?: string;
1847
1847
  /** Glob exclude pattern (e.g. "_drafts/*") */
1848
1848
  exclude?: string;
1849
+ /** GitHub / Git provider auth token for private repositories */
1850
+ token?: string;
1849
1851
  /** Human-readable label for debugging / devtools display */
1850
1852
  label?: string;
1851
1853
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qarpeo",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Zero-config Cloudflare Edge Platform for Nuxt",
5
5
  "keywords": [
6
6
  "analytics-engine",