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.js CHANGED
@@ -2207,6 +2207,20 @@ function listEnSlugs3(rootDir, contentDir) {
2207
2207
  if (!fs2.existsSync(dir)) return [];
2208
2208
  return fs2.readdirSync(dir).filter(isPublishableContentFile).map((f) => f.replace(/\.(md|mdx)$/, ""));
2209
2209
  }
2210
+ function validateDocumentMdxBody(issues, input) {
2211
+ const preparedBody = prepareTranslatedMdxBody(input.body).body;
2212
+ const mdxValidation = validateMdxBody(preparedBody);
2213
+ if (!mdxValidation.ok) {
2214
+ issues.push({
2215
+ level: "error",
2216
+ contentType: input.contentType,
2217
+ enSlug: input.enSlug,
2218
+ locale: input.locale,
2219
+ field: "body",
2220
+ message: `Invalid MDX: ${mdxValidation.error}`
2221
+ });
2222
+ }
2223
+ }
2210
2224
  function validateProject(config) {
2211
2225
  const issues = [];
2212
2226
  const project = createProject(config);
@@ -2265,6 +2279,12 @@ function validateProject(config) {
2265
2279
  })) {
2266
2280
  issues.push(issue);
2267
2281
  }
2282
+ validateDocumentMdxBody(issues, {
2283
+ contentType: type.id,
2284
+ enSlug,
2285
+ locale: config.defaultLocale,
2286
+ body: enDoc.content
2287
+ });
2268
2288
  for (const locale of config.locales) {
2269
2289
  if (locale === config.defaultLocale) continue;
2270
2290
  const row = getTranslation(db, type.id, enSlug, locale);
@@ -2290,17 +2310,12 @@ function validateProject(config) {
2290
2310
  })) {
2291
2311
  issues.push(issue);
2292
2312
  }
2293
- const mdxValidation = validateMdxBody(preparedBody);
2294
- if (!mdxValidation.ok) {
2295
- issues.push({
2296
- level: "error",
2297
- contentType: type.id,
2298
- enSlug,
2299
- locale,
2300
- field: "body",
2301
- message: `Invalid MDX: ${mdxValidation.error}`
2302
- });
2303
- }
2313
+ validateDocumentMdxBody(issues, {
2314
+ contentType: type.id,
2315
+ enSlug,
2316
+ locale,
2317
+ body: row.body
2318
+ });
2304
2319
  }
2305
2320
  }
2306
2321
  try {
@@ -2449,12 +2464,20 @@ function normalizeGeminiDisplayName(model) {
2449
2464
  // src/translate/gemini-client.ts
2450
2465
  var DEFAULT_MODEL = DEFAULT_GEMINI_MODEL;
2451
2466
  function extractJson(text) {
2452
- const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/);
2467
+ const trimmed = text.trim();
2468
+ const fenced = trimmed.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/);
2453
2469
  if (fenced?.[1]) return fenced[1].trim();
2454
- const start = text.indexOf("{");
2455
- const end = text.lastIndexOf("}");
2456
- if (start >= 0 && end > start) return text.slice(start, end + 1);
2457
- return text.trim();
2470
+ const start = trimmed.indexOf("{");
2471
+ const end = trimmed.lastIndexOf("}");
2472
+ if (start >= 0 && end > start) return trimmed.slice(start, end + 1);
2473
+ return trimmed;
2474
+ }
2475
+ function parseGeminiResponse(text) {
2476
+ try {
2477
+ return JSON.parse(text.trim());
2478
+ } catch {
2479
+ return JSON.parse(extractJson(text));
2480
+ }
2458
2481
  }
2459
2482
  async function translatePageWithGemini(input) {
2460
2483
  const apiKey = input.apiKey ?? process.env.GEMINI_API_KEY;
@@ -2475,7 +2498,7 @@ async function translatePageWithGemini(input) {
2475
2498
  }
2476
2499
  });
2477
2500
  const raw = response.text ?? "";
2478
- const parsed = JSON.parse(extractJson(raw));
2501
+ const parsed = parseGeminiResponse(raw);
2479
2502
  if (!parsed.frontmatter || typeof parsed.body !== "string") {
2480
2503
  throw new Error("Gemini response missing frontmatter/body");
2481
2504
  }