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/cli/index.js CHANGED
@@ -1889,6 +1889,20 @@ function listEnSlugs3(rootDir, contentDir) {
1889
1889
  if (!fs2.existsSync(dir)) return [];
1890
1890
  return fs2.readdirSync(dir).filter(isPublishableContentFile).map((f) => f.replace(/\.(md|mdx)$/, ""));
1891
1891
  }
1892
+ function validateDocumentMdxBody(issues, input) {
1893
+ const preparedBody = prepareTranslatedMdxBody(input.body).body;
1894
+ const mdxValidation = validateMdxBody(preparedBody);
1895
+ if (!mdxValidation.ok) {
1896
+ issues.push({
1897
+ level: "error",
1898
+ contentType: input.contentType,
1899
+ enSlug: input.enSlug,
1900
+ locale: input.locale,
1901
+ field: "body",
1902
+ message: `Invalid MDX: ${mdxValidation.error}`
1903
+ });
1904
+ }
1905
+ }
1892
1906
  function validateProject(config) {
1893
1907
  const issues = [];
1894
1908
  const project = createProject(config);
@@ -1947,6 +1961,12 @@ function validateProject(config) {
1947
1961
  })) {
1948
1962
  issues.push(issue);
1949
1963
  }
1964
+ validateDocumentMdxBody(issues, {
1965
+ contentType: type.id,
1966
+ enSlug,
1967
+ locale: config.defaultLocale,
1968
+ body: enDoc.content
1969
+ });
1950
1970
  for (const locale of config.locales) {
1951
1971
  if (locale === config.defaultLocale) continue;
1952
1972
  const row = getTranslation(db, type.id, enSlug, locale);
@@ -1972,17 +1992,12 @@ function validateProject(config) {
1972
1992
  })) {
1973
1993
  issues.push(issue);
1974
1994
  }
1975
- const mdxValidation = validateMdxBody(preparedBody);
1976
- if (!mdxValidation.ok) {
1977
- issues.push({
1978
- level: "error",
1979
- contentType: type.id,
1980
- enSlug,
1981
- locale,
1982
- field: "body",
1983
- message: `Invalid MDX: ${mdxValidation.error}`
1984
- });
1985
- }
1995
+ validateDocumentMdxBody(issues, {
1996
+ contentType: type.id,
1997
+ enSlug,
1998
+ locale,
1999
+ body: row.body
2000
+ });
1986
2001
  }
1987
2002
  }
1988
2003
  try {
@@ -2150,12 +2165,20 @@ function normalizeGeminiDisplayName(model) {
2150
2165
  // src/translate/gemini-client.ts
2151
2166
  var DEFAULT_MODEL = DEFAULT_GEMINI_MODEL;
2152
2167
  function extractJson(text) {
2153
- const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/);
2168
+ const trimmed = text.trim();
2169
+ const fenced = trimmed.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/);
2154
2170
  if (fenced?.[1]) return fenced[1].trim();
2155
- const start = text.indexOf("{");
2156
- const end = text.lastIndexOf("}");
2157
- if (start >= 0 && end > start) return text.slice(start, end + 1);
2158
- return text.trim();
2171
+ const start = trimmed.indexOf("{");
2172
+ const end = trimmed.lastIndexOf("}");
2173
+ if (start >= 0 && end > start) return trimmed.slice(start, end + 1);
2174
+ return trimmed;
2175
+ }
2176
+ function parseGeminiResponse(text) {
2177
+ try {
2178
+ return JSON.parse(text.trim());
2179
+ } catch {
2180
+ return JSON.parse(extractJson(text));
2181
+ }
2159
2182
  }
2160
2183
  async function translatePageWithGemini(input) {
2161
2184
  const apiKey = input.apiKey ?? process.env.GEMINI_API_KEY;
@@ -2176,7 +2199,7 @@ async function translatePageWithGemini(input) {
2176
2199
  }
2177
2200
  });
2178
2201
  const raw = response.text ?? "";
2179
- const parsed = JSON.parse(extractJson(raw));
2202
+ const parsed = parseGeminiResponse(raw);
2180
2203
  if (!parsed.frontmatter || typeof parsed.body !== "string") {
2181
2204
  throw new Error("Gemini response missing frontmatter/body");
2182
2205
  }