@conloca/content-api 0.1.15 → 0.1.16

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 (187) hide show
  1. package/dist/asset-manifest.d.ts +23 -0
  2. package/dist/asset-manifest.d.ts.map +1 -0
  3. package/dist/asset-manifest.js +73 -0
  4. package/dist/asset-operations.d.ts +159 -0
  5. package/dist/asset-operations.d.ts.map +1 -0
  6. package/dist/asset-operations.js +736 -0
  7. package/dist/asset-types.d.ts +56 -0
  8. package/dist/asset-types.d.ts.map +1 -0
  9. package/dist/asset-types.js +7 -0
  10. package/dist/base-content-index.d.ts +57 -0
  11. package/dist/base-content-index.d.ts.map +1 -0
  12. package/dist/base-content-index.js +179 -0
  13. package/dist/block-index.d.ts +9 -0
  14. package/dist/block-index.d.ts.map +1 -0
  15. package/dist/block-index.js +11 -0
  16. package/dist/blocks.d.ts +16 -0
  17. package/dist/blocks.d.ts.map +1 -0
  18. package/dist/blocks.js +103 -0
  19. package/dist/cf-access.d.ts +31 -0
  20. package/dist/cf-access.d.ts.map +1 -0
  21. package/dist/cf-access.js +66 -0
  22. package/dist/component-registry.d.ts +50 -0
  23. package/dist/component-registry.d.ts.map +1 -0
  24. package/dist/component-registry.js +120 -0
  25. package/dist/{component-registry.types-CBGONnYn.d.mts → component-registry.types-C0ctF9nh.d.mts} +1 -1
  26. package/dist/component-registry.types-C0ctF9nh.d.mts.map +1 -0
  27. package/dist/component-registry.types.d.ts +11 -0
  28. package/dist/component-registry.types.d.ts.map +1 -0
  29. package/dist/component-registry.types.js +1 -0
  30. package/dist/content-api.interface.d.ts +64 -0
  31. package/dist/content-api.interface.d.ts.map +1 -0
  32. package/dist/content-api.interface.js +1 -0
  33. package/dist/content-filters.d.ts +31 -0
  34. package/dist/content-filters.d.ts.map +1 -0
  35. package/dist/content-filters.js +246 -0
  36. package/dist/content-index-D092_vk1.mjs +629 -0
  37. package/dist/content-index-D092_vk1.mjs.map +1 -0
  38. package/dist/content-index-D6IVMmAB.d.mts +127 -0
  39. package/dist/content-index-D6IVMmAB.d.mts.map +1 -0
  40. package/dist/content-index.d.ts +126 -0
  41. package/dist/content-index.d.ts.map +1 -0
  42. package/dist/content-index.js +418 -0
  43. package/dist/content-operations-DIbsxG5A.d.mts +354 -0
  44. package/dist/content-operations-DIbsxG5A.d.mts.map +1 -0
  45. package/dist/content-operations.d.ts +93 -0
  46. package/dist/content-operations.d.ts.map +1 -0
  47. package/dist/content-operations.js +275 -0
  48. package/dist/content-reader.d.ts +10 -0
  49. package/dist/content-reader.d.ts.map +1 -0
  50. package/dist/content-reader.js +13 -0
  51. package/dist/content-utils-fWNHTrPy.mjs +280 -0
  52. package/dist/content-utils-fWNHTrPy.mjs.map +1 -0
  53. package/dist/content-utils.d.ts +132 -0
  54. package/dist/content-utils.d.ts.map +1 -0
  55. package/dist/content-utils.js +352 -0
  56. package/dist/content-watcher.d.ts +43 -0
  57. package/dist/content-watcher.d.ts.map +1 -0
  58. package/dist/content-watcher.js +83 -0
  59. package/dist/{data-Db1Iv9T0.mjs → data-DquNIEnQ.mjs} +4 -2
  60. package/dist/{data-Db1Iv9T0.mjs.map → data-DquNIEnQ.mjs.map} +1 -1
  61. package/dist/data-index.d.ts +8 -0
  62. package/dist/data-index.d.ts.map +1 -0
  63. package/dist/data-index.js +7 -0
  64. package/dist/data.d.ts +43 -0
  65. package/dist/data.d.ts.map +1 -0
  66. package/dist/data.js +103 -0
  67. package/dist/etag-utils.d.ts +77 -0
  68. package/dist/etag-utils.d.ts.map +1 -0
  69. package/dist/etag-utils.js +160 -0
  70. package/dist/filesystem-content-api-B1KIQJfk.mjs +2 -0
  71. package/dist/{filesystem-content-api-kxKY5IUw.mjs → filesystem-content-api-C0HIhqZi.mjs} +172 -1230
  72. package/dist/filesystem-content-api-C0HIhqZi.mjs.map +1 -0
  73. package/dist/{filesystem-content-api-C1TM0GLo.d.mts → filesystem-content-api-DCdNi-co.d.mts} +19 -4
  74. package/dist/filesystem-content-api-DCdNi-co.d.mts.map +1 -0
  75. package/dist/filesystem-content-api.d.ts +135 -0
  76. package/dist/filesystem-content-api.d.ts.map +1 -0
  77. package/dist/filesystem-content-api.js +2181 -0
  78. package/dist/git-operations.d.ts +49 -0
  79. package/dist/git-operations.d.ts.map +1 -0
  80. package/dist/git-operations.js +252 -0
  81. package/dist/header-parser.d.ts +37 -0
  82. package/dist/header-parser.d.ts.map +1 -0
  83. package/dist/header-parser.js +286 -0
  84. package/dist/in-memory-content-api.d.ts +35 -0
  85. package/dist/in-memory-content-api.d.ts.map +1 -0
  86. package/dist/in-memory-content-api.js +591 -0
  87. package/dist/index-DxVTFK66.d.mts +105 -0
  88. package/dist/index-DxVTFK66.d.mts.map +1 -0
  89. package/dist/index.d.mts +6 -5
  90. package/dist/index.d.mts.map +1 -1
  91. package/dist/index.d.ts +19 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +16 -0
  94. package/dist/index.mjs +37 -6
  95. package/dist/index.mjs.map +1 -1
  96. package/dist/indexing.d.mts +152 -0
  97. package/dist/indexing.d.mts.map +1 -0
  98. package/dist/indexing.d.ts +5 -0
  99. package/dist/indexing.d.ts.map +1 -0
  100. package/dist/indexing.js +7 -0
  101. package/dist/indexing.mjs +255 -0
  102. package/dist/indexing.mjs.map +1 -0
  103. package/dist/json-whitespace-view.d.ts +32 -0
  104. package/dist/json-whitespace-view.d.ts.map +1 -0
  105. package/dist/json-whitespace-view.js +152 -0
  106. package/dist/middleware.d.ts +20 -0
  107. package/dist/middleware.d.ts.map +1 -0
  108. package/dist/middleware.js +1031 -0
  109. package/dist/node.d.mts +10 -15
  110. package/dist/node.d.mts.map +1 -1
  111. package/dist/node.d.ts +25 -0
  112. package/dist/node.d.ts.map +1 -0
  113. package/dist/node.js +24 -0
  114. package/dist/node.mjs +89 -135
  115. package/dist/node.mjs.map +1 -1
  116. package/dist/reader.d.mts +5 -8
  117. package/dist/reader.d.mts.map +1 -1
  118. package/dist/reader.d.ts +15 -0
  119. package/dist/reader.d.ts.map +1 -0
  120. package/dist/reader.js +13 -0
  121. package/dist/reader.mjs +8 -8
  122. package/dist/reader.mjs.map +1 -1
  123. package/dist/schemas/index.d.mts +2 -90
  124. package/dist/schemas/index.d.ts +102 -0
  125. package/dist/schemas/index.d.ts.map +1 -0
  126. package/dist/schemas/index.js +87 -0
  127. package/dist/schemas/index.mjs +2 -70
  128. package/dist/schemas-CFRD0FIQ.mjs +84 -0
  129. package/dist/schemas-CFRD0FIQ.mjs.map +1 -0
  130. package/dist/{site-vNtJ5jCh.mjs → site-8oaj1Q60.mjs} +21 -193
  131. package/dist/site-8oaj1Q60.mjs.map +1 -0
  132. package/dist/site-index-B_254bCc.d.mts +136 -0
  133. package/dist/site-index-B_254bCc.d.mts.map +1 -0
  134. package/dist/site-index.d.ts +60 -0
  135. package/dist/site-index.d.ts.map +1 -0
  136. package/dist/site-index.js +287 -0
  137. package/dist/site.d.ts +21 -0
  138. package/dist/site.d.ts.map +1 -0
  139. package/dist/site.js +168 -0
  140. package/dist/{types-DWt912tu.mjs → types-DOdldbfD.mjs} +3 -2
  141. package/dist/types-DOdldbfD.mjs.map +1 -0
  142. package/dist/types-DjfhS272.d.mts +456 -0
  143. package/dist/types-DjfhS272.d.mts.map +1 -0
  144. package/dist/types.d.ts +453 -0
  145. package/dist/types.d.ts.map +1 -0
  146. package/dist/types.js +36 -0
  147. package/dist/url-safe-base64.d.ts +12 -0
  148. package/dist/url-safe-base64.d.ts.map +1 -0
  149. package/dist/url-safe-base64.js +40 -0
  150. package/dist/url-validation.d.ts +14 -0
  151. package/dist/url-validation.d.ts.map +1 -0
  152. package/dist/url-validation.js +81 -0
  153. package/dist/utils/atomic-write.d.ts +6 -0
  154. package/dist/utils/atomic-write.d.ts.map +1 -0
  155. package/dist/utils/atomic-write.js +20 -0
  156. package/dist/utils.d.ts +46 -0
  157. package/dist/utils.d.ts.map +1 -0
  158. package/dist/utils.js +70 -0
  159. package/dist/vite-plugin.d.ts +12 -0
  160. package/dist/vite-plugin.d.ts.map +1 -0
  161. package/dist/vite-plugin.js +29 -0
  162. package/dist/vxjson-qHrgLGip.mjs +555 -0
  163. package/dist/vxjson-qHrgLGip.mjs.map +1 -0
  164. package/dist/vxjson-serialize-geF6qvpn.mjs +34 -0
  165. package/dist/vxjson-serialize-geF6qvpn.mjs.map +1 -0
  166. package/dist/vxjson-serialize.d.mts +17 -0
  167. package/dist/vxjson-serialize.d.mts.map +1 -0
  168. package/dist/vxjson-serialize.d.ts +14 -0
  169. package/dist/vxjson-serialize.d.ts.map +1 -0
  170. package/dist/vxjson-serialize.js +50 -0
  171. package/dist/vxjson-serialize.mjs +2 -0
  172. package/dist/vxjson.d.ts +112 -0
  173. package/dist/vxjson.d.ts.map +1 -0
  174. package/dist/vxjson.js +391 -0
  175. package/dist/xxhash.d.ts +10 -0
  176. package/dist/xxhash.d.ts.map +1 -0
  177. package/dist/xxhash.js +31 -0
  178. package/package.json +79 -17
  179. package/dist/component-registry.types-CBGONnYn.d.mts.map +0 -1
  180. package/dist/content-operations-Dv67amz3.d.mts +0 -852
  181. package/dist/content-operations-Dv67amz3.d.mts.map +0 -1
  182. package/dist/filesystem-content-api-C1TM0GLo.d.mts.map +0 -1
  183. package/dist/filesystem-content-api-kxKY5IUw.mjs.map +0 -1
  184. package/dist/schemas/index.d.mts.map +0 -1
  185. package/dist/schemas/index.mjs.map +0 -1
  186. package/dist/site-vNtJ5jCh.mjs.map +0 -1
  187. package/dist/types-DWt912tu.mjs.map +0 -1
@@ -1,29 +1,12 @@
1
- import { E as Blocks, T as serializeMdxWithFrontmatter, a as buildPathnameHistory, b as mapLocales, c as validateAndPrepareMetadata, f as generateContentId, h as isContentPublished, i as buildLocaleVersion, l as validateCreateContent, n as UPDATE_SCOPE, o as shouldUpdateModifiedTimestamp, r as analyzeUpdateScope, s as updatePublishDates, t as Site, w as resolvePublishDate, x as mapSiteNames, y as localesOf } from "./site-vNtJ5jCh.mjs";
2
- import { t as Data } from "./data-Db1Iv9T0.mjs";
1
+ import { a as buildPathnameHistory, c as validateAndPrepareMetadata, i as buildLocaleVersion, l as validateCreateContent, n as UPDATE_SCOPE, o as shouldUpdateModifiedTimestamp, r as analyzeUpdateScope, s as updatePublishDates, t as Site, u as Blocks } from "./site-8oaj1Q60.mjs";
2
+ import { _ as serializeMdxWithFrontmatter, f as mapSiteNames, g as resolvePublishDate, o as isContentPublished, r as generateContentId, u as localesOf } from "./content-utils-fWNHTrPy.mjs";
3
+ import { t as ContentIndex } from "./content-index-D092_vk1.mjs";
4
+ import { a as xxh64, i as parseDualEtag, n as calculateEtagsFromMdxBuffer, r as findMdxContentStartPosition, t as VXJSON } from "./vxjson-qHrgLGip.mjs";
5
+ import { t as Data } from "./data-DquNIEnQ.mjs";
3
6
  import sortKeys from "sort-keys";
4
- import { mkdir, open, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
5
- import { xxh3 } from "@node-rs/xxhash";
6
7
  import matter from "gray-matter";
8
+ import { mkdir, open, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
7
9
  import { dirname, join, resolve } from "path";
8
- import { createHash } from "crypto";
9
-
10
- //#region \0rolldown/runtime.js
11
- var __defProp = Object.defineProperty;
12
- var __exportAll = (all, no_symbols) => {
13
- let target = {};
14
- for (var name in all) {
15
- __defProp(target, name, {
16
- get: all[name],
17
- enumerable: true
18
- });
19
- }
20
- if (!no_symbols) {
21
- __defProp(target, Symbol.toStringTag, { value: "Module" });
22
- }
23
- return target;
24
- };
25
-
26
- //#endregion
27
10
  //#region src/utils/atomic-write.ts
28
11
  /**
29
12
  * Write file atomically via temp file + rename to prevent corruption on crash.
@@ -42,7 +25,6 @@ async function atomicWriteFile(filePath, content) {
42
25
  throw error;
43
26
  }
44
27
  }
45
-
46
28
  //#endregion
47
29
  //#region src/content-filters.ts
48
30
  /**
@@ -115,1178 +97,15 @@ function* filterContentWithIndexes(contentIndex, filters, sitesConfig) {
115
97
  yield manifest;
116
98
  }
117
99
  }
118
-
119
- //#endregion
120
- //#region src/base-content-index.ts
121
- /**
122
- * Base class for content indexes (blocks, data)
123
- * Maintains collection->name->locale lookups with V8-optimized structures
124
- */
125
- var BaseContentIndex = class {
126
- index = /* @__PURE__ */ new Map();
127
- contentCache = /* @__PURE__ */ new Map();
128
- nameIndex = /* @__PURE__ */ new Map();
129
- collections = /* @__PURE__ */ new Set();
130
- /**
131
- * Add or update content in the index
132
- * Merges manifest locales and updates content cache if provided
133
- */
134
- addContent(identity, localeVersion, content) {
135
- const existing = this.index.get(identity.id);
136
- const locale = localeVersion.locale;
137
- if (existing) {
138
- const existingLocale = existing.locales[locale];
139
- if (!existingLocale || existingLocale.etag !== localeVersion.etag) existing.locales[locale] = localeVersion;
140
- } else {
141
- const newManifest = {
142
- id: identity.id,
143
- type: identity.type,
144
- kind: identity.kind,
145
- site: identity.site,
146
- collection: identity.collection,
147
- locales: { [locale]: localeVersion }
148
- };
149
- this.index.set(identity.id, newManifest);
150
- this.collections.add(identity.collection);
151
- }
152
- if (content !== void 0) {
153
- const existingCache = this.contentCache.get(identity.id);
154
- if (existingCache) existingCache[locale] = content;
155
- else this.contentCache.set(identity.id, { [locale]: content });
156
- }
157
- const manifestToIndex = existing || this.index.get(identity.id);
158
- if (localeVersion.name) {
159
- if (!this.nameIndex.has(identity.collection)) this.nameIndex.set(identity.collection, /* @__PURE__ */ new Map());
160
- this.nameIndex.get(identity.collection).set(localeVersion.name, manifestToIndex);
161
- }
162
- }
163
- /**
164
- * Remove a specific locale from an entry
165
- */
166
- removeLocale(id, locale) {
167
- const manifest = this.index.get(id);
168
- if (!manifest || !manifest.locales[locale]) return;
169
- manifest.locales[locale] = void 0;
170
- const contentCache = this.contentCache.get(id);
171
- if (contentCache) delete contentCache[locale];
172
- if (Object.values(manifest.locales).filter((v) => v !== void 0).length === 0) this.removeEntry(id);
173
- }
174
- /**
175
- * Remove an entry from the index
176
- */
177
- removeEntry(id) {
178
- const manifest = this.index.get(id);
179
- if (!manifest) return;
180
- for (const localeVersion of localesOf(manifest)) if (localeVersion.name) {
181
- const collectionMap = this.nameIndex.get(manifest.collection);
182
- if (collectionMap) collectionMap.delete(localeVersion.name);
183
- break;
184
- }
185
- this.index.delete(id);
186
- this.contentCache.delete(id);
187
- }
188
- /**
189
- * Get cached content for a specific locale
190
- */
191
- getCachedContent(id, locale) {
192
- return this.contentCache.get(id)?.[locale] || null;
193
- }
194
- /**
195
- * Get content manifest
196
- */
197
- getManifest(id) {
198
- return this.index.get(id) || null;
199
- }
200
- /**
201
- * Find entry by name
202
- */
203
- getByName(collection, name, locale) {
204
- const collectionMap = this.nameIndex.get(collection);
205
- if (!collectionMap) return null;
206
- const manifest = collectionMap.get(name);
207
- if (!manifest) return null;
208
- if (locale && !manifest.locales[locale]) return null;
209
- return manifest;
210
- }
211
- /**
212
- * Generator for all manifests
213
- */
214
- *getAllManifests() {
215
- for (const manifest of this.index.values()) yield manifest;
216
- }
217
- /**
218
- * Generator for manifests by locale
219
- */
220
- *getManifestsByLocale(locale) {
221
- for (const manifest of this.index.values()) if (manifest.locales[locale]) yield manifest;
222
- }
223
- /**
224
- * Generator for manifests by collection
225
- */
226
- *getManifestsByCollection(collection) {
227
- for (const manifest of this.index.values()) if (manifest.collection === collection) yield manifest;
228
- }
229
- /**
230
- * Get the count of indexed content entries (unique IDs)
231
- */
232
- get entryCount() {
233
- return this.index.size;
234
- }
235
- /**
236
- * Clear all indexes
237
- */
238
- clear() {
239
- this.index.clear();
240
- this.contentCache.clear();
241
- this.nameIndex.clear();
242
- this.collections.clear();
243
- }
244
- };
245
-
246
- //#endregion
247
- //#region src/block-index.ts
248
- /**
249
- * V8-optimized index for blocks
250
- * Maintains collection->name->locale lookups
251
- */
252
- var BlockIndex = class extends BaseContentIndex {
253
- constructor(locales) {
254
- super();
255
- }
256
- };
257
-
258
- //#endregion
259
- //#region src/data-index.ts
260
- /**
261
- * V8-optimized index for data collections
262
- * Maintains collection->name->locale lookups
263
- */
264
- var DataIndex = class extends BaseContentIndex {};
265
-
266
- //#endregion
267
- //#region src/site-index.ts
268
- /**
269
- * V8-optimized index for a single site
270
- * Maintains pathname lookups and collections for one site only
271
- */
272
- var SiteIndex = class {
273
- index = /* @__PURE__ */ new Map();
274
- contentCache = /* @__PURE__ */ new Map();
275
- pathnameIndex;
276
- previousPathnameIndex;
277
- collections = /* @__PURE__ */ new Set();
278
- constructor(siteName, locales) {
279
- this.locales = locales;
280
- this.pathnameIndex = mapLocales(locales, () => /* @__PURE__ */ new Map());
281
- this.previousPathnameIndex = mapLocales(locales, () => /* @__PURE__ */ new Map());
282
- }
283
- /**
284
- * Add or update content in the index
285
- * Merges manifest locales and updates content cache if provided
286
- */
287
- addContent(identity, localeVersion, content) {
288
- const existing = this.index.get(identity.id);
289
- const locale = localeVersion.locale;
290
- if (existing) {
291
- const existingLocale = existing.locales[locale];
292
- let oldPathname;
293
- for (const [pathname, indexedManifest] of this.pathnameIndex[locale].entries()) if (indexedManifest === existing && pathname !== localeVersion.pathname) {
294
- oldPathname = pathname;
295
- break;
296
- }
297
- if (!oldPathname && existingLocale?.pathname && existingLocale.pathname !== localeVersion.pathname) oldPathname = existingLocale.pathname;
298
- const hadExistingLocale = !!existingLocale;
299
- let deletedOldPathname = false;
300
- let addedNewPathname = false;
301
- const addedPreviousPathnames = [];
302
- if (!existingLocale || existingLocale.etag !== localeVersion.etag || existingLocale.modified !== localeVersion.modified || oldPathname && oldPathname !== localeVersion.pathname) try {
303
- existing.locales[locale] = localeVersion;
304
- if (localeVersion.pathname) {
305
- if (oldPathname && oldPathname !== localeVersion.pathname) {
306
- this.pathnameIndex[locale].delete(oldPathname);
307
- deletedOldPathname = true;
308
- if (isContentPublished(localeVersion)) {
309
- this.previousPathnameIndex[locale].set(oldPathname, existing);
310
- addedPreviousPathnames.push(oldPathname);
311
- }
312
- }
313
- this.pathnameIndex[locale].set(localeVersion.pathname, existing);
314
- addedNewPathname = true;
315
- }
316
- if (localeVersion.previousPathnames) {
317
- for (const prevPath of Object.keys(localeVersion.previousPathnames)) if (!this.previousPathnameIndex[locale].has(prevPath)) {
318
- this.previousPathnameIndex[locale].set(prevPath, existing);
319
- addedPreviousPathnames.push(prevPath);
320
- }
321
- }
322
- } catch (error) {
323
- if (hadExistingLocale) existing.locales[locale] = existingLocale;
324
- else existing.locales[locale] = void 0;
325
- if (deletedOldPathname && oldPathname) this.pathnameIndex[locale].set(oldPathname, existing);
326
- if (addedNewPathname && localeVersion.pathname) this.pathnameIndex[locale].delete(localeVersion.pathname);
327
- for (const prevPath of addedPreviousPathnames) this.previousPathnameIndex[locale].delete(prevPath);
328
- throw error;
329
- }
330
- } else {
331
- const newManifest = {
332
- id: identity.id,
333
- type: identity.type,
334
- kind: identity.kind,
335
- site: identity.site,
336
- collection: identity.collection,
337
- locales: { [locale]: localeVersion }
338
- };
339
- this.index.set(identity.id, newManifest);
340
- this.collections.add(identity.collection);
341
- if (localeVersion.pathname) this.pathnameIndex[locale].set(localeVersion.pathname, newManifest);
342
- if (localeVersion.previousPathnames) for (const prevPath of Object.keys(localeVersion.previousPathnames)) this.previousPathnameIndex[locale].set(prevPath, newManifest);
343
- }
344
- if (content !== void 0) {
345
- const existingCache = this.contentCache.get(identity.id);
346
- if (existingCache) existingCache[locale] = content;
347
- else this.contentCache.set(identity.id, { [locale]: content });
348
- }
349
- }
350
- /**
351
- * Remove a specific locale from an entry
352
- */
353
- removeLocale(id, locale) {
354
- const manifest = this.index.get(id);
355
- if (!manifest || !manifest.locales[locale]) return;
356
- const localeVersion = manifest.locales[locale];
357
- if (localeVersion.pathname) this.pathnameIndex[locale].delete(localeVersion.pathname);
358
- if (localeVersion.previousPathnames) for (const prevPath of Object.keys(localeVersion.previousPathnames)) this.previousPathnameIndex[locale].delete(prevPath);
359
- manifest.locales[locale] = void 0;
360
- const contentCache = this.contentCache.get(id);
361
- if (contentCache) delete contentCache[locale];
362
- if (Object.keys(manifest.locales).length === 0) this.removeEntry(id);
363
- }
364
- /**
365
- * Remove an entry from the index
366
- */
367
- removeEntry(id) {
368
- const manifest = this.index.get(id);
369
- if (!manifest) return;
370
- for (const localeVersion of localesOf(manifest)) {
371
- const { locale } = localeVersion;
372
- if (localeVersion.pathname) this.pathnameIndex[locale].delete(localeVersion.pathname);
373
- if (localeVersion.previousPathnames) for (const prevPath of Object.keys(localeVersion.previousPathnames)) this.previousPathnameIndex[locale].delete(prevPath);
374
- }
375
- this.index.delete(id);
376
- this.contentCache.delete(id);
377
- }
378
- /**
379
- * Get cached content for a specific locale
380
- */
381
- getCachedContent(id, locale) {
382
- return this.contentCache.get(id)?.[locale] || null;
383
- }
384
- /**
385
- * Get content manifest
386
- */
387
- getManifest(id) {
388
- return this.index.get(id) || null;
389
- }
390
- /**
391
- * Find content by pathname
392
- */
393
- getByPathname(pathname, locale) {
394
- if (locale) return this.pathnameIndex[locale]?.get(pathname) || null;
395
- for (const locale of this.locales) {
396
- const manifest = this.pathnameIndex[locale].get(pathname);
397
- if (manifest) return manifest;
398
- }
399
- return null;
400
- }
401
- /**
402
- * Find content by previous pathname (for redirects)
403
- */
404
- getByPreviousPathname(pathname, locale) {
405
- if (locale) return this.previousPathnameIndex[locale]?.get(pathname) || null;
406
- for (const locale of this.locales) {
407
- const manifest = this.previousPathnameIndex[locale].get(pathname);
408
- if (manifest) return manifest;
409
- }
410
- return null;
411
- }
412
- /**
413
- * Generator for all manifests
414
- */
415
- *getAllManifests() {
416
- for (const manifest of this.index.values()) yield manifest;
417
- }
418
- /**
419
- * Generator for manifests by locale
420
- */
421
- *getManifestsByLocale(locale) {
422
- for (const manifest of this.index.values()) if (manifest.locales[locale]) yield manifest;
423
- }
424
- /**
425
- * Get the count of indexed content entries (unique IDs)
426
- */
427
- get entryCount() {
428
- return this.index.size;
429
- }
430
- /**
431
- * Clear all indexes
432
- */
433
- clear() {
434
- this.index.clear();
435
- this.contentCache.clear();
436
- for (const locale of this.locales) {
437
- this.pathnameIndex[locale].clear();
438
- this.previousPathnameIndex[locale].clear();
439
- }
440
- this.collections.clear();
441
- }
442
- };
443
-
444
- //#endregion
445
- //#region src/content-index.ts
446
- /**
447
- * ContentIndex coordinates between per-site indexes and the block index
448
- * This provides efficient filtering by routing to the appropriate specialized index
449
- */
450
- const globalCache = globalThis.__CONLOCA_CONTENT_INDEX_CACHE__ || {};
451
- if (!globalThis.__CONLOCA_CONTENT_INDEX_CACHE__) globalThis.__CONLOCA_CONTENT_INDEX_CACHE__ = globalCache;
452
- var ContentIndex = class ContentIndex {
453
- static get cache() {
454
- return globalCache;
455
- }
456
- siteIndexes;
457
- blockIndex;
458
- dataIndex;
459
- constructor(sitesConfig) {
460
- this.sitesConfig = sitesConfig;
461
- this.blockIndex = new BlockIndex(sitesConfig.globalLocales);
462
- this.dataIndex = new DataIndex();
463
- this.siteIndexes = mapSiteNames(sitesConfig, (siteName) => {
464
- const siteConfig = sitesConfig.sites[siteName];
465
- return new SiteIndex(siteName, siteConfig.locales);
466
- });
467
- }
468
- /**
469
- * Get cached index or create a new one
470
- */
471
- static async getCachedOrCreate(contentRoot, sitesConfig) {
472
- if (!ContentIndex.cache[contentRoot]) ContentIndex.cache[contentRoot] = new ContentIndex(sitesConfig);
473
- return ContentIndex.cache[contentRoot];
474
- }
475
- /**
476
- * Clear all cached indexes
477
- */
478
- static clearCache() {
479
- Object.keys(globalCache).forEach((key) => delete globalCache[key]);
480
- }
481
- /**
482
- * Create a new index without caching - for testing
483
- */
484
- static createUncached(sitesConfig) {
485
- return new ContentIndex(sitesConfig);
486
- }
487
- /**
488
- * Add or update content in the appropriate index
489
- * Updates a single locale's manifest and content cache if provided
490
- */
491
- addContent(identity, localeVersion, content) {
492
- if ((identity.kind === "block" || identity.kind === "data") && identity.site) throw new Error(`${identity.kind} cannot have a site property`);
493
- if (identity.kind === "page" && !identity.site) throw new Error("Pages must have a site property");
494
- if (identity.kind === "block") this.blockIndex.addContent(identity, localeVersion, content);
495
- else if (identity.kind === "data") this.dataIndex.addContent(identity, localeVersion, content);
496
- else {
497
- const siteIndex = this.siteIndexes[identity.site];
498
- if (siteIndex) siteIndex.addContent(identity, localeVersion, content);
499
- }
500
- }
501
- /**
502
- * Remove a specific locale from content
503
- */
504
- removeLocale(id, locale) {
505
- const manifest = this.getManifest(id);
506
- if (!manifest) return;
507
- if (manifest.kind === "block") this.blockIndex.removeLocale(id, locale);
508
- else if (manifest.kind === "data") this.dataIndex.removeLocale(id, locale);
509
- else {
510
- const siteIndex = this.siteIndexes[manifest.site];
511
- if (siteIndex) siteIndex.removeLocale(id, locale);
512
- }
513
- }
514
- /**
515
- * Get cached content
516
- */
517
- getCachedContent(id, locale) {
518
- const manifest = this.getManifest(id);
519
- if (!manifest) return null;
520
- if (manifest.kind === "block") return this.blockIndex.getCachedContent(id, locale);
521
- if (manifest.kind === "data") return this.dataIndex.getCachedContent(id, locale);
522
- const siteIndex = this.siteIndexes[manifest.site];
523
- return siteIndex ? siteIndex.getCachedContent(id, locale) : null;
524
- }
525
- /**
526
- * Remove an entry from all indexes
527
- */
528
- removeEntry(id) {
529
- this.blockIndex.removeEntry(id);
530
- this.dataIndex.removeEntry(id);
531
- for (const site in this.siteIndexes) {
532
- const siteIndex = this.siteIndexes[site];
533
- if (siteIndex) siteIndex.removeEntry(id);
534
- }
535
- }
536
- /**
537
- * Get content manifest for a content ID
538
- */
539
- getManifest(id) {
540
- let manifest = this.blockIndex.getManifest(id);
541
- if (manifest) return manifest;
542
- manifest = this.dataIndex.getManifest(id);
543
- if (manifest) return manifest;
544
- for (const site in this.siteIndexes) {
545
- const siteIndex = this.siteIndexes[site];
546
- if (siteIndex) {
547
- manifest = siteIndex.getManifest(id);
548
- if (manifest) return manifest;
549
- }
550
- }
551
- return null;
552
- }
553
- /**
554
- * Get a specific locale manifest
555
- */
556
- getLocaleVersion(id, locale) {
557
- const manifest = this.getManifest(id);
558
- if (!manifest) return null;
559
- return manifest.locales[locale] || null;
560
- }
561
- /**
562
- * Get site index
563
- */
564
- getSiteIndex(site) {
565
- return this.siteIndexes[site] || null;
566
- }
567
- /**
568
- * Get block index
569
- */
570
- getBlockIndex() {
571
- return this.blockIndex;
572
- }
573
- /**
574
- * Find content by pathname (delegates to site indexes)
575
- */
576
- getByPathname(site, pathname, locale) {
577
- const siteIndex = this.siteIndexes[site];
578
- return siteIndex ? siteIndex.getByPathname(pathname, locale) : null;
579
- }
580
- /**
581
- * Find content by previous pathname (for redirects)
582
- */
583
- getByPreviousPathname(site, pathname, locale) {
584
- const siteIndex = this.siteIndexes[site];
585
- return siteIndex ? siteIndex.getByPreviousPathname(pathname, locale) : null;
586
- }
587
- /**
588
- * Find block by name
589
- */
590
- getBlockByName(collection, name, locale) {
591
- return this.blockIndex.getByName(collection, name, locale);
592
- }
593
- /**
594
- * Get data index
595
- */
596
- getDataIndex() {
597
- return this.dataIndex;
598
- }
599
- /**
600
- * Find data entry by name
601
- */
602
- getDataByName(collection, name, locale) {
603
- return this.dataIndex.getByName(collection, name, locale);
604
- }
605
- /**
606
- * Get all collections for data
607
- */
608
- getDataCollections() {
609
- return this.dataIndex.collections;
610
- }
611
- /**
612
- * List all content (for iteration)
613
- */
614
- *listAllContent() {
615
- yield* this.blockIndex.getAllManifests();
616
- yield* this.dataIndex.getAllManifests();
617
- for (const site in this.siteIndexes) {
618
- const siteIndex = this.siteIndexes[site];
619
- if (siteIndex) yield* siteIndex.getAllManifests();
620
- }
621
- }
622
- /**
623
- * Generator for all sites
624
- */
625
- *allSites() {
626
- for (const site in this.siteIndexes) if (this.siteIndexes[site]) yield site;
627
- }
628
- /**
629
- * Get all collections for a site
630
- */
631
- getCollectionsForSite(site) {
632
- const siteIndex = this.siteIndexes[site];
633
- return siteIndex ? siteIndex.collections : /* @__PURE__ */ new Set();
634
- }
635
- /**
636
- * Get all collections for blocks
637
- */
638
- getBlockCollections() {
639
- return this.blockIndex.collections;
640
- }
641
- /**
642
- * Get default locale for a site
643
- */
644
- getDefaultLocale(site) {
645
- if (!site) return this.sitesConfig.globalLocales[0];
646
- return this.sitesConfig.sites[site]?.defaultLocale || this.sitesConfig.globalLocales[0];
647
- }
648
- /**
649
- * Find content missing a specific locale
650
- */
651
- *findUntranslatedContent(targetLocale, options) {
652
- for (const manifest of this.blockIndex.getAllManifests()) if (!manifest.locales[targetLocale]) {
653
- if (!options?.includeUnpublished) {
654
- let hasPublishedLocale = false;
655
- for (const locale of localesOf(manifest)) if (!locale.unpublishAt || new Date(locale.unpublishAt) > /* @__PURE__ */ new Date()) {
656
- hasPublishedLocale = true;
657
- break;
658
- }
659
- if (!hasPublishedLocale) continue;
660
- }
661
- yield manifest;
662
- }
663
- for (const siteName in this.siteIndexes) {
664
- const siteIndex = this.siteIndexes[siteName];
665
- if (!siteIndex || options?.excludeSites?.includes(siteName)) continue;
666
- for (const manifest of siteIndex.getAllManifests()) if (!manifest.locales[targetLocale]) {
667
- if (!options?.includeUnpublished) {
668
- let hasPublishedLocale = false;
669
- for (const locale of localesOf(manifest)) if (!locale.unpublishAt || new Date(locale.unpublishAt) > /* @__PURE__ */ new Date()) {
670
- hasPublishedLocale = true;
671
- break;
672
- }
673
- if (!hasPublishedLocale) continue;
674
- }
675
- yield manifest;
676
- }
677
- }
678
- }
679
- /**
680
- * Generators for efficient filtering
681
- */
682
- *getManifestsForKind(kind) {
683
- if (kind === "block") yield* this.blockIndex.getAllManifests();
684
- else if (kind === "data") yield* this.dataIndex.getAllManifests();
685
- else for (const site in this.siteIndexes) {
686
- const siteIndex = this.siteIndexes[site];
687
- if (siteIndex) yield* siteIndex.getAllManifests();
688
- }
689
- }
690
- *getManifestsForSite(site) {
691
- const siteIndex = this.siteIndexes[site];
692
- if (siteIndex) yield* siteIndex.getAllManifests();
693
- }
694
- *getManifestsForSiteLocale(site, locale) {
695
- const siteIndex = this.siteIndexes[site];
696
- if (siteIndex) yield* siteIndex.getManifestsByLocale(locale);
697
- }
698
- *getManifestsForSiteCollection(site, collection) {
699
- const siteIndex = this.siteIndexes[site];
700
- if (siteIndex) {
701
- for (const manifest of siteIndex.getAllManifests()) if (manifest.collection === collection) yield manifest;
702
- }
703
- }
704
- *getManifestsForLocale(locale) {
705
- yield* this.blockIndex.getManifestsByLocale(locale);
706
- yield* this.dataIndex.getManifestsByLocale(locale);
707
- for (const site in this.siteIndexes) {
708
- const siteIndex = this.siteIndexes[site];
709
- if (siteIndex) yield* siteIndex.getManifestsByLocale(locale);
710
- }
711
- }
712
- *getManifestsForCollection(collection) {
713
- yield* this.blockIndex.getManifestsByCollection(collection);
714
- yield* this.dataIndex.getManifestsByCollection(collection);
715
- for (const site in this.siteIndexes) {
716
- const siteIndex = this.siteIndexes[site];
717
- if (siteIndex) {
718
- for (const manifest of siteIndex.getAllManifests()) if (manifest.collection === collection) yield manifest;
719
- }
720
- }
721
- }
722
- /**
723
- * Get the count of indexed content entries
724
- */
725
- get entryCount() {
726
- let count = this.blockIndex.entryCount;
727
- count += this.dataIndex.entryCount;
728
- for (const site in this.siteIndexes) {
729
- const siteIndex = this.siteIndexes[site];
730
- if (siteIndex) count += siteIndex.entryCount;
731
- }
732
- return count;
733
- }
734
- /**
735
- * Clear all indexes
736
- */
737
- clear() {
738
- this.blockIndex.clear();
739
- this.dataIndex.clear();
740
- for (const site in this.siteIndexes) {
741
- const siteIndex = this.siteIndexes[site];
742
- if (siteIndex) siteIndex.clear();
743
- }
744
- }
745
- };
746
-
747
- //#endregion
748
- //#region src/json-whitespace-view.ts
749
- /**
750
- * Zero-allocation JSON whitespace-skipping stream transform
751
- * Skips whitespace outside of JSON strings, preserving whitespace inside strings
752
- * Optimized to process multiple bytes at once when possible
753
- */
754
- var JsonWhitespaceSkippingView = class {
755
- inString = false;
756
- escaped = false;
757
- singleByte = new Uint8Array(1);
758
- constructor(downstream) {
759
- this.downstream = downstream;
760
- }
761
- /**
762
- * Process a single byte from JSON stream
763
- * @param byte - The byte to process
764
- */
765
- updateByte(byte) {
766
- let shouldInclude = false;
767
- if (this.inString) {
768
- shouldInclude = true;
769
- if (this.escaped) this.escaped = false;
770
- else if (byte === 92) this.escaped = true;
771
- else if (byte === 34) this.inString = false;
772
- } else if (byte === 34) {
773
- this.inString = true;
774
- shouldInclude = true;
775
- } else if (byte !== 9 && byte !== 32 && byte !== 10 && byte !== 13) shouldInclude = true;
776
- if (shouldInclude) {
777
- this.singleByte[0] = byte;
778
- this.downstream.update(this.singleByte);
779
- }
780
- }
781
- /**
782
- * Process a buffer range with simple batching
783
- * Collects consecutive bytes that should be included
784
- * @param buffer - The buffer to process
785
- * @param start - Start position (inclusive)
786
- * @param end - End position (exclusive)
787
- */
788
- updateBuffer(buffer, start = 0, end = buffer.length) {
789
- let pos = start;
790
- let runStart = start;
791
- while (pos < end) {
792
- const byte = buffer[pos];
793
- let shouldInclude = false;
794
- if (this.inString) {
795
- shouldInclude = true;
796
- if (this.escaped) this.escaped = false;
797
- else if (byte === 92) this.escaped = true;
798
- else if (byte === 34) this.inString = false;
799
- else {
800
- pos++;
801
- let searchPos = pos;
802
- while (searchPos < end) {
803
- const quotePos = buffer.indexOf(34, searchPos);
804
- if (quotePos === -1 || quotePos >= end) {
805
- pos = end;
806
- break;
807
- }
808
- let backslashCount = 0;
809
- let checkPos = quotePos - 1;
810
- while (checkPos >= 0 && buffer[checkPos] === 92) {
811
- backslashCount++;
812
- checkPos--;
813
- }
814
- if (backslashCount % 2 === 0) {
815
- pos = quotePos + 1;
816
- this.inString = false;
817
- break;
818
- }
819
- searchPos = quotePos + 1;
820
- }
821
- continue;
822
- }
823
- } else if (byte === 34) {
824
- this.inString = true;
825
- shouldInclude = true;
826
- } else if (byte !== 9 && byte !== 32 && byte !== 10 && byte !== 13) shouldInclude = true;
827
- if (shouldInclude) pos++;
828
- else {
829
- if (pos > runStart) this.downstream.update(buffer.subarray(runStart, pos));
830
- pos++;
831
- runStart = pos;
832
- }
833
- }
834
- if (pos > runStart) this.downstream.update(buffer.subarray(runStart, pos));
835
- }
836
- /**
837
- * Reset the parser state
838
- */
839
- reset() {
840
- this.inString = false;
841
- this.escaped = false;
842
- }
843
- };
844
-
845
- //#endregion
846
- //#region src/url-safe-base64.ts
847
- /**
848
- * Convert bytes to URL-safe base64
849
- * Replaces + with -, / with _, and removes = padding
850
- */
851
- function toUrlSafeBase64(bytes) {
852
- const b64 = Buffer.from(bytes).toString("base64");
853
- const buf = Buffer.from(b64, "ascii");
854
- let write = 0;
855
- for (let read = 0; read < buf.length; read++) {
856
- const c = buf[read];
857
- if (c === 43) buf[write++] = 45;
858
- else if (c === 47) buf[write++] = 95;
859
- else if (c === 61) {} else buf[write++] = c;
860
- }
861
- return buf.subarray(0, write).toString("ascii");
862
- }
863
- /**
864
- * Convert BigInt to URL-safe base64
865
- * @param value - The BigInt value to convert
866
- * @returns URL-safe base64 string representation
867
- */
868
- function bigintToUrlSafeBase64(value) {
869
- const hashBuffer = new Uint8Array(8);
870
- new DataView(hashBuffer.buffer).setBigUint64(0, value, false);
871
- return toUrlSafeBase64(hashBuffer);
872
- }
873
-
874
- //#endregion
875
- //#region src/etag-utils.ts
876
- /**
877
- * Calculate content ETag using SHA256 from buffer view
878
- * @param buffer - The file buffer view
879
- * @param start - Start position (inclusive)
880
- * @param end - End position (exclusive), or -1 for entire buffer
881
- */
882
- function calculateContentEtagFromBuffer(buffer, start = 0, end = -1) {
883
- const actualEnd = end === -1 ? buffer.length : end;
884
- const hasher = createHash("sha256");
885
- new JsonWhitespaceSkippingView(hasher).updateBuffer(buffer, start, actualEnd);
886
- return toUrlSafeBase64(hasher.digest());
887
- }
888
- const dashCode = "-".charCodeAt(0);
889
- const newlineCode = "\n".charCodeAt(0);
890
- /**
891
- * Find the content start position in MDX buffer (after second ---)
892
- * @param buffer - The MDX content buffer
893
- * @returns Position where content starts, or -1 if not found
894
- */
895
- function findMdxContentStartPosition(buffer) {
896
- let dashCount = 0;
897
- let i = 0;
898
- while (i < buffer.length - 4) if (buffer[i] === dashCode && buffer[i + 1] === dashCode && buffer[i + 2] === dashCode && buffer[i + 3] === newlineCode) {
899
- dashCount++;
900
- if (dashCount === 2) {
901
- i += 4;
902
- if (i < buffer.length && buffer[i] === newlineCode) return i + 1;
903
- return i;
904
- }
905
- i += 4;
906
- } else {
907
- const nextDashPos = buffer.indexOf(dashCode, i + 1);
908
- if (nextDashPos === -1) break;
909
- i = nextDashPos;
910
- }
911
- return -1;
912
- }
913
- /**
914
- * Calculate both ETags from an MDX buffer
915
- *
916
- * MDX files use YAML frontmatter which has different characteristics than JSON:
917
- * - YAML does not require quotes around keys or string values
918
- * - YAML allows multiple formatting styles (flow vs block style)
919
- * - YAML field order is not significant for parsing
920
- *
921
- * Unlike VXJSON which requires "content" to be the last field and needs special
922
- * parsing to validate structure, YAML frontmatter can be hashed as-is because:
923
- * 1. The frontmatter boundaries are clearly delimited by ---
924
- * 2. Different YAML formatting of the same data SHOULD produce different hashes
925
- * (e.g., flow style [a,b] vs block style with dashes)
926
- * 3. There's no requirement to validate field ordering
927
- *
928
- * This means we can directly hash the YAML bytes without any whitespace
929
- * normalization or parsing, which is both simpler and more correct.
930
- *
931
- * @param buffer - The complete file buffer
932
- * @param contentStartPos - Position where content starts (after second ---), or -1 if no content
933
- */
934
- function calculateEtagsFromMdxBuffer(buffer, contentStartPos) {
935
- if (contentStartPos === -1) {
936
- const hasher = xxh3.Xxh3.withSeed(0n);
937
- hasher.update(buffer);
938
- return {
939
- metaEtag: bigintToUrlSafeBase64(hasher.digest()),
940
- contentEtag: calculateContentEtagFromBuffer(new Uint8Array(0))
941
- };
942
- }
943
- const metaHasher = xxh3.Xxh3.withSeed(0n);
944
- metaHasher.update(buffer.subarray(0, contentStartPos));
945
- const metaEtag = bigintToUrlSafeBase64(metaHasher.digest());
946
- const contentHasher = createHash("sha256");
947
- contentHasher.update(buffer.subarray(contentStartPos));
948
- return {
949
- metaEtag,
950
- contentEtag: toUrlSafeBase64(contentHasher.digest())
951
- };
952
- }
953
- /**
954
- * Parse dual ETags from query string: "meta.content"
955
- */
956
- function parseDualEtag(etag) {
957
- const parts = etag.split(".");
958
- if (parts.length !== 2) return null;
959
- return {
960
- meta: parts[0],
961
- content: parts[1]
962
- };
963
- }
964
-
965
- //#endregion
966
- //#region src/vxjson.ts
967
- const textDecoder$1 = new TextDecoder();
968
- const CONTENT_MARKER = new TextEncoder().encode("\"content\":");
969
- /**
970
- * Calculate metadata ETag using xxHash from buffer view
971
- * @param buffer - The file buffer view
972
- * @param start - Start position (inclusive)
973
- * @param end - End position (exclusive), or -1 for entire buffer
974
- */
975
- function calculateMetaEtagFromBuffer(buffer, start = 0, end = -1) {
976
- const actualEnd = end === -1 ? buffer.length : end;
977
- const hasher = xxh3.Xxh3.withSeed(0n);
978
- new JsonWhitespaceSkippingView(hasher).updateBuffer(buffer, start, actualEnd);
979
- return bigintToUrlSafeBase64(hasher.digest());
980
- }
981
- /**
982
- * Calculate both ETags from a VXJSON buffer using views
983
- * Finds the "content" field position and validates it's the last field
984
- * @param buffer - The complete file buffer
985
- * @returns Result with ETags or validation error
986
- */
987
- function calculateEtagsFromVXJSONBuffer(buffer, allowTruncated = false) {
988
- let pos = 0;
989
- let depth = 0;
990
- let inString = false;
991
- let escaped = false;
992
- let contentStartPos = -1;
993
- let foundContentAtRoot = false;
994
- let expectingKey = false;
995
- let expectingValue = false;
996
- let keyStart = -1;
997
- while (pos < buffer.length && (buffer[pos] === 32 || buffer[pos] === 9 || buffer[pos] === 10 || buffer[pos] === 13)) pos++;
998
- if (pos >= buffer.length || buffer[pos] !== 123) return {
999
- success: false,
1000
- error: "invalid_json"
1001
- };
1002
- depth = 1;
1003
- expectingKey = true;
1004
- pos++;
1005
- while (pos < buffer.length && depth > 0) {
1006
- const byte = buffer[pos];
1007
- if (inString) {
1008
- if (escaped) escaped = false;
1009
- else if (byte === 92) escaped = true;
1010
- else if (byte === 34) {
1011
- inString = false;
1012
- if (depth === 1 && expectingKey && keyStart >= 0) {
1013
- const keyLength = pos - keyStart + 1;
1014
- if (foundContentAtRoot) {
1015
- if (keyLength === 9) {
1016
- let isContent = true;
1017
- for (let i = 0; i < 7; i++) if (buffer[keyStart + 1 + i] !== CONTENT_MARKER[i + 1]) {
1018
- isContent = false;
1019
- break;
1020
- }
1021
- if (isContent) return {
1022
- success: false,
1023
- error: "invalid_json"
1024
- };
1025
- }
1026
- return {
1027
- success: false,
1028
- error: "content_not_last"
1029
- };
1030
- }
1031
- if (keyLength === 9) {
1032
- let isContent = true;
1033
- for (let i = 0; i < 7; i++) if (buffer[keyStart + 1 + i] !== CONTENT_MARKER[i + 1]) {
1034
- isContent = false;
1035
- break;
1036
- }
1037
- if (isContent) {
1038
- foundContentAtRoot = true;
1039
- contentStartPos = keyStart;
1040
- }
1041
- }
1042
- expectingKey = false;
1043
- expectingValue = true;
1044
- keyStart = -1;
1045
- }
1046
- }
1047
- } else if (byte === 34) {
1048
- inString = true;
1049
- if (depth === 1 && expectingKey) keyStart = pos;
1050
- } else if (byte === 123 || byte === 91) {
1051
- depth++;
1052
- if (depth === 1 && expectingValue) expectingValue = false;
1053
- } else if (byte === 125 || byte === 93) {
1054
- depth--;
1055
- if (depth === 0) break;
1056
- } else if (byte === 58 && depth === 1) {
1057
- if (!expectingValue) return {
1058
- success: false,
1059
- error: "invalid_json"
1060
- };
1061
- } else if (byte === 44 && depth === 1) {
1062
- expectingKey = true;
1063
- expectingValue = false;
1064
- } else if (depth === 1 && expectingValue && byte !== 32 && byte !== 9 && byte !== 10 && byte !== 13) expectingValue = false;
1065
- pos++;
1066
- }
1067
- const isTruncated = depth !== 0;
1068
- if (isTruncated && !allowTruncated) return {
1069
- success: false,
1070
- error: "invalid_json"
1071
- };
1072
- if (contentStartPos === -1) return {
1073
- success: true,
1074
- metaEtag: calculateMetaEtagFromBuffer(buffer),
1075
- contentStartPos: -1
1076
- };
1077
- if (isTruncated) return {
1078
- success: true,
1079
- metaEtag: calculateMetaEtagFromBuffer(buffer, 0, contentStartPos),
1080
- contentStartPos
1081
- };
1082
- let metaEnd = contentStartPos - 1;
1083
- while (metaEnd > 0) {
1084
- const byte = buffer[metaEnd];
1085
- if (byte === 44 || byte === 32 || byte === 9 || byte === 10 || byte === 13) metaEnd--;
1086
- else break;
1087
- }
1088
- const metaHasher = xxh3.Xxh3.withSeed(0n);
1089
- const metaView = new JsonWhitespaceSkippingView(metaHasher);
1090
- const openBrace = new Uint8Array([123]);
1091
- const closeBrace = new Uint8Array([125]);
1092
- metaHasher.update(openBrace);
1093
- metaView.updateBuffer(buffer, 1, metaEnd);
1094
- metaHasher.update(closeBrace);
1095
- const metaEtag = bigintToUrlSafeBase64(metaHasher.digest());
1096
- const contentHasher = createHash("sha256");
1097
- const contentView = new JsonWhitespaceSkippingView(contentHasher);
1098
- contentHasher.update(openBrace);
1099
- contentView.updateBuffer(buffer, contentStartPos, buffer.length - 1);
1100
- contentHasher.update(closeBrace);
1101
- return {
1102
- success: true,
1103
- metaEtag,
1104
- contentEtag: toUrlSafeBase64(contentHasher.digest()),
1105
- contentStartPos
1106
- };
1107
- }
1108
- /**
1109
- * VXJSON (Variant JSON) module for parsing and serializing VXJSON files
1110
- *
1111
- * VXJSON is a specialized JSON format that guarantees:
1112
- * 1. The root is always an object (never an array or primitive)
1113
- * 2. The "content" field always comes last in the object
1114
- * 3. Field order is deterministic for consistent ETag calculation
1115
- * 4. Metadata fits within 4085 bytes, ensuring "content" field is found within first 4KB
1116
- * 5. First 4KB must either be complete JSON OR end exactly with '"content":'
1117
- *
1118
- * This format enables efficient 4KB parsing where only the first 4KB of a file
1119
- * needs to be read to extract all metadata and locate the content position.
1120
- * The constraint that 4KB reads must end with '"content":' ensures reliable parsing.
1121
- *
1122
- * This module centralizes all VXJSON-specific logic including:
1123
- * - Parsing partial buffers (first 4KB for indexing)
1124
- * - Finding content position for ETag calculation
1125
- * - Serializing with proper field ordering and size validation
1126
- * - Calculating ETags from buffers
1127
- */
1128
- /**
1129
- * VXJSON static utilities for parsing and validating VXJSON files
1130
- */
1131
- var VXJSON = class VXJSON {
1132
- /**
1133
- * Parse first 4KB of VXJSON content from buffer
1134
- * Used during indexing to extract metadata without loading full content
1135
- *
1136
- * VXJSON format requirement: first 4KB must either be complete JSON OR end with '"content":'
1137
- * This ensures reliable parsing and validation.
1138
- */
1139
- static parse4KB(buffer, bytesRead) {
1140
- if (bytesRead < 4096 || buffer[bytesRead - 1] === 125) {
1141
- const partialContent = textDecoder$1.decode(buffer.subarray(0, bytesRead));
1142
- const data = JSON.parse(partialContent);
1143
- let contentStartPos = -1;
1144
- if (data.content !== void 0) {
1145
- const etagResult = calculateEtagsFromVXJSONBuffer(buffer.subarray(0, bytesRead));
1146
- if (etagResult.success) contentStartPos = etagResult.contentStartPos;
1147
- }
1148
- return {
1149
- id: data.id,
1150
- created: data.created,
1151
- modified: data.modified,
1152
- publishAt: data.publishAt,
1153
- unpublishAt: data.unpublishAt,
1154
- previousPathnames: data.previousPathnames,
1155
- pathname: data.pathname,
1156
- name: data.name,
1157
- meta: data.meta || {},
1158
- content: data.content,
1159
- contentStartPos
1160
- };
1161
- }
1162
- const etagResult = calculateEtagsFromVXJSONBuffer(buffer.subarray(0, bytesRead), true);
1163
- if (!etagResult.success) throw new Error(`Invalid VXJSON format: ${etagResult.error}. This violates the VXJSON specification.`);
1164
- const contentStartPos = etagResult.contentStartPos;
1165
- let metadataEnd = contentStartPos;
1166
- while (metadataEnd > 0) {
1167
- const byte = buffer[metadataEnd - 1];
1168
- if (byte === 44) {
1169
- metadataEnd--;
1170
- break;
1171
- }
1172
- if (byte === 32 || byte === 9 || byte === 10 || byte === 13) metadataEnd--;
1173
- else break;
1174
- }
1175
- const metadataBuffer = new Uint8Array(metadataEnd + 1);
1176
- metadataBuffer.set(buffer.subarray(0, metadataEnd));
1177
- metadataBuffer[metadataEnd] = 125;
1178
- const partialContent = textDecoder$1.decode(metadataBuffer);
1179
- const data = JSON.parse(partialContent);
1180
- return {
1181
- id: data.id,
1182
- created: data.created,
1183
- modified: data.modified,
1184
- publishAt: data.publishAt,
1185
- unpublishAt: data.unpublishAt,
1186
- previousPathnames: data.previousPathnames,
1187
- pathname: data.pathname,
1188
- name: data.name,
1189
- meta: data.meta || {},
1190
- contentStartPos
1191
- };
1192
- }
1193
- /**
1194
- * Find the position of the "content" field in a VXJSON buffer
1195
- * Returns -1 if not found
1196
- */
1197
- static findContentPosition(buffer) {
1198
- const etagResult = calculateEtagsFromVXJSONBuffer(buffer);
1199
- if (etagResult.success) return etagResult.contentStartPos;
1200
- return -1;
1201
- }
1202
- /**
1203
- * Calculate ETags for a VXJSON buffer
1204
- * Returns null if the buffer is not valid VXJSON
1205
- */
1206
- static calculateEtagsOnly(buffer) {
1207
- const result = calculateEtagsFromVXJSONBuffer(buffer);
1208
- if (!result.success) return null;
1209
- return {
1210
- metaEtag: result.metaEtag,
1211
- contentEtag: result.contentEtag
1212
- };
1213
- }
1214
- /**
1215
- * Create a dual ETag string from a VXJSON buffer
1216
- * Returns null if the buffer is not valid VXJSON
1217
- */
1218
- static createEtag(buffer) {
1219
- const etags = VXJSON.calculateEtagsOnly(buffer);
1220
- if (!etags) return null;
1221
- return etags.contentEtag ? `${etags.metaEtag}.${etags.contentEtag}` : etags.metaEtag;
1222
- }
1223
- /**
1224
- * Validate that a VXJSON buffer has the correct structure
1225
- * (content field must be last)
1226
- */
1227
- static isValid(buffer) {
1228
- return calculateEtagsFromVXJSONBuffer(buffer).success;
1229
- }
1230
- /**
1231
- * Parse a complete VXJSON file from string
1232
- */
1233
- static parse(content) {
1234
- return JSON.parse(content);
1235
- }
1236
- /**
1237
- * Parse a complete VXJSON file from buffer
1238
- */
1239
- static parseBuffer(buffer) {
1240
- const content = textDecoder$1.decode(buffer);
1241
- return VXJSON.parse(content);
1242
- }
1243
- /**
1244
- * Calculate both ETags from a VXJSON buffer using views
1245
- * Finds the "content" field position and validates it's the last field
1246
- * @param buffer - The complete file buffer
1247
- * @returns Result with ETags or validation error
1248
- */
1249
- static calculateETags = calculateEtagsFromVXJSONBuffer;
1250
- /**
1251
- * Calculate a simple single etag from the entire buffer
1252
- * Used for data files that don't follow the content-last convention
1253
- */
1254
- static calculateSimpleEtag(buffer) {
1255
- return calculateMetaEtagFromBuffer(buffer);
1256
- }
1257
- /**
1258
- * Serialize a VXJSONFile to VXJSON format string
1259
- * Ensures content field is last and enforces 4KB constraint efficiently
1260
- */
1261
- static serialize(data) {
1262
- const { content, ...metadataFields } = data;
1263
- if (content === void 0 || content === null) throw new Error("VXJSON format requires a \"content\" field");
1264
- const sortedMetadata = sortKeys(metadataFields, { deep: true });
1265
- const metadataJson = JSON.stringify(sortedMetadata, (_key, value) => {
1266
- if (value === "") return;
1267
- return value;
1268
- }, " ");
1269
- const wrappedContent = JSON.stringify({ c: sortKeys(content, { deep: true }) }, null, " ");
1270
- const contentJson = wrappedContent.slice(wrappedContent.indexOf(": ") + 2, -2);
1271
- const metadataWithoutClosing = metadataJson.slice(0, -2);
1272
- const contentFieldPrefix = ",\n \"content\": ";
1273
- const contentKeyPosition = metadataWithoutClosing.length + 1 + 2;
1274
- const maxContentKeyPosition = 4086;
1275
- if (contentKeyPosition > maxContentKeyPosition) throw new Error(`VXJSON format violation: metadata too large. "content" field would start at position ${contentKeyPosition}, but must start within ${maxContentKeyPosition} bytes. Reduce metadata size by ${contentKeyPosition - maxContentKeyPosition} bytes.`);
1276
- return `${metadataWithoutClosing}${contentFieldPrefix}${contentJson}\n}`;
1277
- }
1278
- };
1279
-
1280
100
  //#endregion
1281
101
  //#region src/filesystem-content-api.ts
1282
- var filesystem_content_api_exports = /* @__PURE__ */ __exportAll({ FileSystemContentAPI: () => FileSystemContentAPI });
1283
102
  function ensureError(error) {
1284
103
  if (error instanceof Error) return error;
1285
104
  return new Error(String(error));
1286
105
  }
1287
106
  const textDecoder = new TextDecoder();
1288
107
  function parse4KBMDX(buffer, bytesRead) {
1289
- const { data: frontmatter } = matter(textDecoder.decode(buffer.subarray(0, bytesRead)));
108
+ const { data: frontmatter } = matter(textDecoder.decode(buffer.subarray(0, bytesRead)), {});
1290
109
  const delimiter = new TextEncoder().encode("---");
1291
110
  let delimiterCount = 0;
1292
111
  let contentStartPos = -1;
@@ -1343,6 +162,43 @@ function parse4KBMDX(buffer, bytesRead) {
1343
162
  * - Full content is loaded on demand
1344
163
  * - ETags are calculated using streaming for efficiency
1345
164
  */
165
+ /**
166
+ * Read and validate `<contentRoot>/sites.json`. Returns a safe default
167
+ * (`{ sites: {}, globalLocales: ['en'] }`) when the file is missing or
168
+ * has invalid structure, with a warning logged in each case.
169
+ *
170
+ * Exported standalone so the Astro integration (and any other tooling
171
+ * that needs to inspect per-site config at startup time) can read the
172
+ * config without spinning up a full content-api instance.
173
+ */
174
+ async function readSitesConfig(contentRoot) {
175
+ const sitesPath = join(resolve(contentRoot), "sites.json");
176
+ try {
177
+ const content = await readFile(sitesPath, "utf-8");
178
+ const parsed = JSON.parse(content);
179
+ if (!parsed.sites || typeof parsed.sites !== "object") {
180
+ console.warn(`Warning: sites.json has invalid structure at ${sitesPath}. Expected 'sites' property. Using default configuration.`);
181
+ return {
182
+ sites: {},
183
+ globalLocales: ["en"]
184
+ };
185
+ }
186
+ if (!parsed.globalLocales || !Array.isArray(parsed.globalLocales)) {
187
+ console.warn(`Warning: sites.json is missing 'globalLocales' array at ${sitesPath}. Using default global locales.`);
188
+ return {
189
+ sites: parsed.sites,
190
+ globalLocales: ["en"]
191
+ };
192
+ }
193
+ return parsed;
194
+ } catch {
195
+ console.warn(`Warning: sites.json is missing at ${sitesPath}. Using empty configuration.`);
196
+ return {
197
+ sites: {},
198
+ globalLocales: ["en"]
199
+ };
200
+ }
201
+ }
1346
202
  var FileSystemContentAPI = class FileSystemContentAPI {
1347
203
  contentRoot;
1348
204
  absoluteContentRoot;
@@ -1351,16 +207,41 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1351
207
  blocks;
1352
208
  data;
1353
209
  sites;
210
+ absoluteMdxPagesRoot;
211
+ mdxPagesDefaultLocale = "en";
212
+ mdxPagesSite = "default";
213
+ mdxPagesCollection = "pages";
214
+ availableLocales;
1354
215
  get normalizedContentRoot() {
1355
216
  return this.contentRoot;
1356
217
  }
1357
- constructor(contentRoot, canvasDir, sitesConfig, contentIndex) {
218
+ constructor(contentRoot, canvasDir, sitesConfig, contentIndex, mdxPagesOptions, localeOptions) {
1358
219
  if (contentRoot.startsWith("./")) this.contentRoot = contentRoot.slice(2);
1359
220
  else if (contentRoot.startsWith("/")) this.contentRoot = contentRoot;
1360
221
  else this.contentRoot = contentRoot;
1361
222
  this.absoluteContentRoot = resolve(this.contentRoot);
1362
223
  this.sitesConfig = sitesConfig;
1363
224
  this.contentIndex = contentIndex;
225
+ const siteNames = Object.keys(sitesConfig.sites);
226
+ const firstSiteName = siteNames[0];
227
+ const firstSiteWithMdxPages = siteNames.find((name) => sitesConfig.sites[name]?.mdxPages);
228
+ this.mdxPagesSite = mdxPagesOptions?.site ?? firstSiteWithMdxPages ?? firstSiteName ?? "default";
229
+ const sitesJsonMdxPages = sitesConfig.sites[this.mdxPagesSite]?.mdxPages;
230
+ const resolvedMdxPages = mdxPagesOptions?.root ?? sitesJsonMdxPages;
231
+ if (resolvedMdxPages) {
232
+ const normalizedMdxPages = resolvedMdxPages.startsWith("./") ? resolvedMdxPages.slice(2) : resolvedMdxPages;
233
+ this.absoluteMdxPagesRoot = resolve(normalizedMdxPages);
234
+ }
235
+ const siteConfig = sitesConfig.sites[this.mdxPagesSite];
236
+ this.mdxPagesDefaultLocale = localeOptions?.defaultLocale ?? mdxPagesOptions?.defaultLocale ?? siteConfig?.defaultLocale ?? sitesConfig.globalLocales[0] ?? "en";
237
+ const merged = /* @__PURE__ */ new Set();
238
+ if (localeOptions?.availableLocales && localeOptions.availableLocales.length > 0) for (const loc of localeOptions.availableLocales) merged.add(loc);
239
+ else {
240
+ for (const loc of sitesConfig.globalLocales) merged.add(loc);
241
+ if (siteConfig?.locales) for (const loc of siteConfig.locales) merged.add(loc);
242
+ }
243
+ merged.add(this.mdxPagesDefaultLocale);
244
+ this.availableLocales = merged;
1364
245
  this.blocks = new Blocks(this, this.contentIndex.getBlockIndex());
1365
246
  this.data = new Data(this, this.contentIndex.getDataIndex());
1366
247
  this.sites = mapSiteNames(sitesConfig, (siteName) => {
@@ -1372,34 +253,34 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1372
253
  static async create(options) {
1373
254
  const { canvasDir } = options;
1374
255
  const contentRoot = options.contentRoot;
1375
- const sitesPath = join(resolve(contentRoot), "sites.json");
1376
- let sitesConfig;
1377
- try {
1378
- const content = await readFile(sitesPath, "utf-8");
1379
- const parsed = JSON.parse(content);
1380
- if (!parsed.sites || typeof parsed.sites !== "object") {
1381
- console.warn(`Warning: sites.json has invalid structure at ${sitesPath}. Expected 'sites' property. Using default configuration.`);
1382
- sitesConfig = {
1383
- sites: {},
1384
- globalLocales: ["en"]
1385
- };
1386
- } else if (!parsed.globalLocales || !Array.isArray(parsed.globalLocales)) {
1387
- console.warn(`Warning: sites.json is missing 'globalLocales' array at ${sitesPath}. Using default global locales.`);
1388
- sitesConfig = {
1389
- sites: parsed.sites,
1390
- globalLocales: ["en"]
1391
- };
1392
- } else sitesConfig = parsed;
1393
- } catch (error) {
1394
- console.warn(`Warning: sites.json is missing at ${sitesPath}. Using empty configuration.`);
256
+ let sitesConfig = await readSitesConfig(contentRoot);
257
+ if (options.availableLocales && options.availableLocales.length > 0) {
258
+ const optionDefaultLocale = options.defaultLocale ?? options.availableLocales[0];
259
+ const optionSite = options.mdxPagesSite ?? Object.keys(sitesConfig.sites)[0] ?? "default";
260
+ const existingSite = sitesConfig.sites[optionSite];
1395
261
  sitesConfig = {
1396
- sites: {},
1397
- globalLocales: ["en"]
262
+ sites: {
263
+ ...sitesConfig.sites,
264
+ [optionSite]: {
265
+ locales: options.availableLocales,
266
+ defaultLocale: optionDefaultLocale,
267
+ ...existingSite?.domains && { domains: existingSite.domains },
268
+ ...existingSite?.mdxPages && { mdxPages: existingSite.mdxPages }
269
+ }
270
+ },
271
+ globalLocales: Array.from(/* @__PURE__ */ new Set([...sitesConfig.globalLocales, ...options.availableLocales]))
1398
272
  };
1399
273
  }
1400
274
  const normalizedContentRoot = contentRoot.startsWith("./") ? contentRoot.slice(2) : contentRoot;
1401
275
  const contentIndex = await ContentIndex.getCachedOrCreate(normalizedContentRoot, sitesConfig);
1402
- const api = new FileSystemContentAPI(contentRoot, canvasDir, sitesConfig, contentIndex);
276
+ const api = new FileSystemContentAPI(contentRoot, canvasDir, sitesConfig, contentIndex, {
277
+ root: options.mdxPagesRoot,
278
+ defaultLocale: options.mdxPagesDefaultLocale,
279
+ site: options.mdxPagesSite
280
+ }, {
281
+ availableLocales: options.availableLocales,
282
+ defaultLocale: options.defaultLocale
283
+ });
1403
284
  if (contentIndex.entryCount === 0) await api.indexAllContent();
1404
285
  return api;
1405
286
  }
@@ -1415,7 +296,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1415
296
  const OPTIMAL_BATCH_SIZE = 1e3;
1416
297
  console.debug(`Indexing ${files.length} content files...`);
1417
298
  const bufferCount = Math.min(files.length, OPTIMAL_BATCH_SIZE);
1418
- const buffers = Array.from({ length: bufferCount }, () => new Uint8Array(4096));
299
+ const buffers = Array.from({ length: bufferCount }, () => /* @__PURE__ */ new Uint8Array(4096));
1419
300
  for (let i = 0; i < files.length; i += OPTIMAL_BATCH_SIZE) {
1420
301
  const batch = files.slice(i, i + OPTIMAL_BATCH_SIZE);
1421
302
  await Promise.all(batch.map(async (filePath, index) => {
@@ -1454,7 +335,24 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1454
335
  let pathname;
1455
336
  let parsedData = {};
1456
337
  let kind;
1457
- if (parts[0] === "blocks") {
338
+ if (this.absoluteMdxPagesRoot && filePath.startsWith(this.absoluteMdxPagesRoot + "/")) {
339
+ kind = "page";
340
+ site = this.mdxPagesSite;
341
+ collection = this.mdxPagesCollection;
342
+ const mdxParts = filePath.replace(this.absoluteMdxPagesRoot + "/", "").split("/");
343
+ const noLocaleMatch = mdxParts[mdxParts.length - 1].match(/^(.+)\.mdx$/);
344
+ if (!noLocaleMatch) return null;
345
+ mdxParts[mdxParts.length - 1] = noLocaleMatch[1];
346
+ if (mdxParts.length > 1 && this.availableLocales.has(mdxParts[0])) {
347
+ locale = mdxParts[0];
348
+ const slugParts = mdxParts.slice(1);
349
+ pathname = slugParts[slugParts.length - 1] === "index" ? "/" + slugParts.slice(0, -1).join("/") || "/" : "/" + slugParts.join("/");
350
+ } else {
351
+ locale = this.mdxPagesDefaultLocale;
352
+ pathname = mdxParts[mdxParts.length - 1] === "index" ? "/" + mdxParts.slice(0, -1).join("/") || "/" : "/" + mdxParts.join("/");
353
+ }
354
+ parsedData = parse4KBMDX(buffer, bytesRead);
355
+ } else if (parts[0] === "blocks") {
1458
356
  kind = "block";
1459
357
  if (parts.length === 2) {
1460
358
  collection = "general";
@@ -1554,13 +452,14 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1554
452
  site = parts[0];
1555
453
  collection = parts[1];
1556
454
  const pathParts = parts.slice(2);
1557
- const match = pathParts[pathParts.length - 1].match(/^(.+)\.(\w+)\.vxjson$/);
455
+ const match = pathParts[pathParts.length - 1].match(/^(.+)\.(\w+)\.(vxjson|mdx)$/);
1558
456
  if (match) {
1559
457
  locale = match[2];
1560
458
  pathParts[pathParts.length - 1] = match[1];
1561
459
  pathname = pathParts[pathParts.length - 1] === "index" ? "/" + pathParts.slice(0, -1).join("/") || "/" : "/" + pathParts.join("/");
1562
460
  }
1563
- parsedData = VXJSON.parse4KB(buffer, bytesRead);
461
+ if (filePath.endsWith(".mdx")) parsedData = parse4KBMDX(buffer, bytesRead);
462
+ else parsedData = VXJSON.parse4KB(buffer, bytesRead);
1564
463
  }
1565
464
  const needsRepair = !parsedData.id || !parsedData.created || !parsedData.modified;
1566
465
  const id = parsedData.id || generateContentId();
@@ -1604,7 +503,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1604
503
  }
1605
504
  if (bytesRead < 4096 || filePath.endsWith(".vxjson") && buffer[bytesRead - 1] === 125 || filePath.endsWith(".json") && buffer[bytesRead - 1] === 125) {
1606
505
  if (filePath.endsWith(".mdx")) {
1607
- const { content: mdx } = matter(textDecoder.decode(buffer.subarray(0, bytesRead)));
506
+ const { content: mdx } = matter(textDecoder.decode(buffer.subarray(0, bytesRead)), {});
1608
507
  content = { mdx };
1609
508
  } else if (filePath.endsWith(".json")) {
1610
509
  const fullContent = textDecoder.decode(buffer.subarray(0, bytesRead));
@@ -1661,7 +560,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1661
560
  const now = (/* @__PURE__ */ new Date()).toISOString();
1662
561
  let needsWrite = false;
1663
562
  if (manifest.type === "mdx") {
1664
- const parsed = matter(await readFile(filePath, "utf-8"));
563
+ const parsed = matter(await readFile(filePath, "utf-8"), {});
1665
564
  if (!parsed.data.id) {
1666
565
  parsed.data.id = manifest.id;
1667
566
  needsWrite = true;
@@ -1675,13 +574,13 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1675
574
  needsWrite = true;
1676
575
  }
1677
576
  if (needsWrite) {
1678
- const updatedContent = matter.stringify(parsed.content, parsed.data);
577
+ const updatedContent = matter.stringify(parsed, parsed.data);
1679
578
  await writeFile(filePath, updatedContent);
1680
579
  console.log(`Repaired MDX file: ${filePath} (added missing fields)`);
1681
580
  const etags = calculateEtagsFromMdxBuffer(Buffer.from(updatedContent, "utf-8"), updatedContent.indexOf("\n---\n") + 5);
1682
581
  const etag = `${etags.metaEtag}.${etags.contentEtag}`;
1683
582
  return {
1684
- content: { mdx: parsed.content },
583
+ content: { mdx: parsed.content.replace(/^\n+/, "") },
1685
584
  etag,
1686
585
  modified: parsed.data.modified || now
1687
586
  };
@@ -1756,6 +655,19 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1756
655
  } catch (error) {}
1757
656
  }
1758
657
  await scan(this.absoluteContentRoot);
658
+ if (this.absoluteMdxPagesRoot && this.absoluteMdxPagesRoot !== this.absoluteContentRoot && !this.absoluteMdxPagesRoot.startsWith(this.absoluteContentRoot + "/")) {
659
+ async function scanMdxPages(dir) {
660
+ try {
661
+ const entries = await readdir(dir, { withFileTypes: true });
662
+ for (const entry of entries) {
663
+ const fullPath = join(dir, entry.name);
664
+ if (entry.isDirectory()) await scanMdxPages(fullPath);
665
+ else if (entry.isFile() && entry.name.endsWith(".mdx")) files.push(fullPath);
666
+ }
667
+ } catch (error) {}
668
+ }
669
+ await scanMdxPages(this.absoluteMdxPagesRoot);
670
+ }
1759
671
  return files;
1760
672
  }
1761
673
  getFilePath(manifest, { locale, name, pathname }) {
@@ -1764,9 +676,13 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1764
676
  return join(this.absoluteContentRoot, "blocks", manifest.collection, `${name}.${locale}.${ext}`);
1765
677
  }
1766
678
  if (manifest.kind === "data") return join(this.absoluteContentRoot, "data", manifest.collection, `${name}.${locale}.json`);
1767
- if (manifest.kind === "page" && pathname && manifest.site) {
679
+ if (manifest.kind === "page" && pathname) {
1768
680
  const basePath = pathname.replace(/^\//, "").replace(/\/$/, "") || "index";
1769
- return join(this.absoluteContentRoot, manifest.site, manifest.collection, `${basePath}.${locale}.vxjson`);
681
+ if (manifest.type === "mdx" && this.absoluteMdxPagesRoot) return locale === this.mdxPagesDefaultLocale ? join(this.absoluteMdxPagesRoot, `${basePath}.mdx`) : join(this.absoluteMdxPagesRoot, locale, `${basePath}.mdx`);
682
+ if (manifest.site) {
683
+ const ext = manifest.type === "mdx" ? "mdx" : "vxjson";
684
+ return join(this.absoluteContentRoot, manifest.site, manifest.collection, `${basePath}.${locale}.${ext}`);
685
+ }
1770
686
  }
1771
687
  throw new Error(`Invalid manifest: ${JSON.stringify(manifest, null, 2)}`);
1772
688
  }
@@ -1775,6 +691,30 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1775
691
  * Returns null if the path doesn't match expected patterns
1776
692
  */
1777
693
  parseFilePath(filePath) {
694
+ if (this.absoluteMdxPagesRoot && filePath.startsWith(this.absoluteMdxPagesRoot + "/")) {
695
+ const mdxParts = filePath.replace(this.absoluteMdxPagesRoot + "/", "").split("/");
696
+ const mdxFilename = mdxParts[mdxParts.length - 1];
697
+ let locale;
698
+ let pathname;
699
+ const noLocaleMatch = mdxFilename.match(/^(.+)\.mdx$/);
700
+ if (!noLocaleMatch) return null;
701
+ mdxParts[mdxParts.length - 1] = noLocaleMatch[1];
702
+ if (mdxParts.length > 1 && this.availableLocales.has(mdxParts[0])) {
703
+ locale = mdxParts[0];
704
+ const slugParts = mdxParts.slice(1);
705
+ pathname = slugParts[slugParts.length - 1] === "index" ? "/" + slugParts.slice(0, -1).join("/") || "/" : "/" + slugParts.join("/");
706
+ } else {
707
+ locale = this.mdxPagesDefaultLocale;
708
+ pathname = mdxParts[mdxParts.length - 1] === "index" ? "/" + mdxParts.slice(0, -1).join("/") || "/" : "/" + mdxParts.join("/");
709
+ }
710
+ return {
711
+ kind: "page",
712
+ site: this.mdxPagesSite,
713
+ collection: this.mdxPagesCollection,
714
+ pathname,
715
+ locale
716
+ };
717
+ }
1778
718
  const parts = filePath.replace(this.absoluteContentRoot + "/", "").split("/");
1779
719
  const filename = parts[parts.length - 1];
1780
720
  if (parts[0] === "data" && parts.length === 3) {
@@ -1869,7 +809,8 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1869
809
  const buffer = await readFile(filePath);
1870
810
  const content = textDecoder.decode(buffer);
1871
811
  if (filePath.endsWith(".mdx")) {
1872
- const { data: frontmatter } = matter(content);
812
+ const { data: frontmatter, content: rawBody } = matter(content, {});
813
+ const body = rawBody.replace(/^\n+/, "");
1873
814
  const etags = calculateEtagsFromMdxBuffer(buffer, findMdxContentStartPosition(buffer));
1874
815
  const etag = `${etags.metaEtag}.${etags.contentEtag}`;
1875
816
  const { id, created, modified, publishAt, unpublishAt, name, ...metaFields } = frontmatter;
@@ -1879,7 +820,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
1879
820
  created,
1880
821
  modified,
1881
822
  meta: metaFields,
1882
- content: { mdx: content }
823
+ content: { mdx: body }
1883
824
  };
1884
825
  if (frontmatter.publishAt !== void 0) result.publishAt = frontmatter.publishAt;
1885
826
  if (frontmatter.unpublishAt !== void 0) result.unpublishAt = frontmatter.unpublishAt;
@@ -2199,9 +1140,10 @@ var FileSystemContentAPI = class FileSystemContentAPI {
2199
1140
  };
2200
1141
  let mdxContentPart = newContent.mdx || "";
2201
1142
  if (mdxContentPart.startsWith("---")) {
2202
- const { content: contentOnly } = matter(mdxContentPart);
1143
+ const { content: contentOnly } = matter(mdxContentPart, {});
2203
1144
  mdxContentPart = contentOnly;
2204
1145
  }
1146
+ if (/\n---\r?\n[\s\S]*?\r?\n---(\r?\n|$)/.test(mdxContentPart)) console.warn(`[content-api] Embedded frontmatter-shaped block detected in body for ${targetFilePath}. This indicates a load-path regression or client-side leak.`);
2205
1147
  const mdxContent = serializeMdxWithFrontmatter(frontmatterData, mdxContentPart);
2206
1148
  await atomicWriteFile(targetFilePath, mdxContent);
2207
1149
  } else if (targetFilePath.endsWith(".json")) {
@@ -2477,7 +1419,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
2477
1419
  continue;
2478
1420
  }
2479
1421
  currentEtag = etagResult.contentEtag ? `${etagResult.metaEtag}.${etagResult.contentEtag}` : etagResult.metaEtag;
2480
- } else if (filePath.endsWith(".json")) currentEtag = xxh3.xxh64(buffer).toString(16);
1422
+ } else if (filePath.endsWith(".json")) currentEtag = xxh64(buffer).toString(16);
2481
1423
  else {
2482
1424
  filesSkipped++;
2483
1425
  continue;
@@ -2491,7 +1433,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
2491
1433
  }
2492
1434
  else filesToIndex.push(filePath);
2493
1435
  }
2494
- const buffers = Array.from({ length: Math.min(filesToIndex.length, 100) }, () => new Uint8Array(4096));
1436
+ const buffers = Array.from({ length: Math.min(filesToIndex.length, 100) }, () => /* @__PURE__ */ new Uint8Array(4096));
2495
1437
  for (let i = 0; i < filesToIndex.length; i++) {
2496
1438
  const filePath = filesToIndex[i];
2497
1439
  const bufferIndex = i % buffers.length;
@@ -2672,7 +1614,7 @@ var FileSystemContentAPI = class FileSystemContentAPI {
2672
1614
  };
2673
1615
  }
2674
1616
  };
2675
-
2676
1617
  //#endregion
2677
- export { findMdxContentStartPosition as a, atomicWriteFile as c, calculateEtagsFromMdxBuffer as i, filesystem_content_api_exports as n, ContentIndex as o, VXJSON as r, filterContentWithIndexes as s, FileSystemContentAPI as t };
2678
- //# sourceMappingURL=filesystem-content-api-kxKY5IUw.mjs.map
1618
+ export { atomicWriteFile as i, readSitesConfig as n, filterContentWithIndexes as r, FileSystemContentAPI as t };
1619
+
1620
+ //# sourceMappingURL=filesystem-content-api-C0HIhqZi.mjs.map