scribe-cms 0.0.11 → 0.0.12

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/index.cjs CHANGED
@@ -2220,6 +2220,20 @@ function listEnSlugs3(rootDir, contentDir) {
2220
2220
  if (!fs2__default.default.existsSync(dir)) return [];
2221
2221
  return fs2__default.default.readdirSync(dir).filter(isPublishableContentFile).map((f) => f.replace(/\.(md|mdx)$/, ""));
2222
2222
  }
2223
+ function validateDocumentMdxBody(issues, input) {
2224
+ const preparedBody = prepareTranslatedMdxBody(input.body).body;
2225
+ const mdxValidation = validateMdxBody(preparedBody);
2226
+ if (!mdxValidation.ok) {
2227
+ issues.push({
2228
+ level: "error",
2229
+ contentType: input.contentType,
2230
+ enSlug: input.enSlug,
2231
+ locale: input.locale,
2232
+ field: "body",
2233
+ message: `Invalid MDX: ${mdxValidation.error}`
2234
+ });
2235
+ }
2236
+ }
2223
2237
  function validateProject(config) {
2224
2238
  const issues = [];
2225
2239
  const project = createProject(config);
@@ -2278,6 +2292,12 @@ function validateProject(config) {
2278
2292
  })) {
2279
2293
  issues.push(issue);
2280
2294
  }
2295
+ validateDocumentMdxBody(issues, {
2296
+ contentType: type.id,
2297
+ enSlug,
2298
+ locale: config.defaultLocale,
2299
+ body: enDoc.content
2300
+ });
2281
2301
  for (const locale of config.locales) {
2282
2302
  if (locale === config.defaultLocale) continue;
2283
2303
  const row = getTranslation(db, type.id, enSlug, locale);
@@ -2303,17 +2323,12 @@ function validateProject(config) {
2303
2323
  })) {
2304
2324
  issues.push(issue);
2305
2325
  }
2306
- const mdxValidation = validateMdxBody(preparedBody);
2307
- if (!mdxValidation.ok) {
2308
- issues.push({
2309
- level: "error",
2310
- contentType: type.id,
2311
- enSlug,
2312
- locale,
2313
- field: "body",
2314
- message: `Invalid MDX: ${mdxValidation.error}`
2315
- });
2316
- }
2326
+ validateDocumentMdxBody(issues, {
2327
+ contentType: type.id,
2328
+ enSlug,
2329
+ locale,
2330
+ body: row.body
2331
+ });
2317
2332
  }
2318
2333
  }
2319
2334
  try {
@@ -2462,12 +2477,20 @@ function normalizeGeminiDisplayName(model) {
2462
2477
  // src/translate/gemini-client.ts
2463
2478
  var DEFAULT_MODEL = DEFAULT_GEMINI_MODEL;
2464
2479
  function extractJson(text) {
2465
- const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/);
2480
+ const trimmed = text.trim();
2481
+ const fenced = trimmed.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/);
2466
2482
  if (fenced?.[1]) return fenced[1].trim();
2467
- const start = text.indexOf("{");
2468
- const end = text.lastIndexOf("}");
2469
- if (start >= 0 && end > start) return text.slice(start, end + 1);
2470
- return text.trim();
2483
+ const start = trimmed.indexOf("{");
2484
+ const end = trimmed.lastIndexOf("}");
2485
+ if (start >= 0 && end > start) return trimmed.slice(start, end + 1);
2486
+ return trimmed;
2487
+ }
2488
+ function parseGeminiResponse(text) {
2489
+ try {
2490
+ return JSON.parse(text.trim());
2491
+ } catch {
2492
+ return JSON.parse(extractJson(text));
2493
+ }
2471
2494
  }
2472
2495
  async function translatePageWithGemini(input) {
2473
2496
  const apiKey = input.apiKey ?? process.env.GEMINI_API_KEY;
@@ -2488,7 +2511,7 @@ async function translatePageWithGemini(input) {
2488
2511
  }
2489
2512
  });
2490
2513
  const raw = response.text ?? "";
2491
- const parsed = JSON.parse(extractJson(raw));
2514
+ const parsed = parseGeminiResponse(raw);
2492
2515
  if (!parsed.frontmatter || typeof parsed.body !== "string") {
2493
2516
  throw new Error("Gemini response missing frontmatter/body");
2494
2517
  }