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.cjs +40 -17
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +40 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +40 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -17
- package/dist/index.js.map +1 -1
- package/dist/src/translate/gemini-client.d.ts +5 -0
- package/dist/src/translate/gemini-client.d.ts.map +1 -1
- package/dist/src/validate/validate-project.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -1906,6 +1906,20 @@ function listEnSlugs3(rootDir, contentDir) {
|
|
|
1906
1906
|
if (!fs2__default.default.existsSync(dir)) return [];
|
|
1907
1907
|
return fs2__default.default.readdirSync(dir).filter(isPublishableContentFile).map((f) => f.replace(/\.(md|mdx)$/, ""));
|
|
1908
1908
|
}
|
|
1909
|
+
function validateDocumentMdxBody(issues, input) {
|
|
1910
|
+
const preparedBody = prepareTranslatedMdxBody(input.body).body;
|
|
1911
|
+
const mdxValidation = validateMdxBody(preparedBody);
|
|
1912
|
+
if (!mdxValidation.ok) {
|
|
1913
|
+
issues.push({
|
|
1914
|
+
level: "error",
|
|
1915
|
+
contentType: input.contentType,
|
|
1916
|
+
enSlug: input.enSlug,
|
|
1917
|
+
locale: input.locale,
|
|
1918
|
+
field: "body",
|
|
1919
|
+
message: `Invalid MDX: ${mdxValidation.error}`
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1909
1923
|
function validateProject(config) {
|
|
1910
1924
|
const issues = [];
|
|
1911
1925
|
const project = createProject(config);
|
|
@@ -1964,6 +1978,12 @@ function validateProject(config) {
|
|
|
1964
1978
|
})) {
|
|
1965
1979
|
issues.push(issue);
|
|
1966
1980
|
}
|
|
1981
|
+
validateDocumentMdxBody(issues, {
|
|
1982
|
+
contentType: type.id,
|
|
1983
|
+
enSlug,
|
|
1984
|
+
locale: config.defaultLocale,
|
|
1985
|
+
body: enDoc.content
|
|
1986
|
+
});
|
|
1967
1987
|
for (const locale of config.locales) {
|
|
1968
1988
|
if (locale === config.defaultLocale) continue;
|
|
1969
1989
|
const row = getTranslation(db, type.id, enSlug, locale);
|
|
@@ -1989,17 +2009,12 @@ function validateProject(config) {
|
|
|
1989
2009
|
})) {
|
|
1990
2010
|
issues.push(issue);
|
|
1991
2011
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
locale,
|
|
1999
|
-
field: "body",
|
|
2000
|
-
message: `Invalid MDX: ${mdxValidation.error}`
|
|
2001
|
-
});
|
|
2002
|
-
}
|
|
2012
|
+
validateDocumentMdxBody(issues, {
|
|
2013
|
+
contentType: type.id,
|
|
2014
|
+
enSlug,
|
|
2015
|
+
locale,
|
|
2016
|
+
body: row.body
|
|
2017
|
+
});
|
|
2003
2018
|
}
|
|
2004
2019
|
}
|
|
2005
2020
|
try {
|
|
@@ -2167,12 +2182,20 @@ function normalizeGeminiDisplayName(model) {
|
|
|
2167
2182
|
// src/translate/gemini-client.ts
|
|
2168
2183
|
var DEFAULT_MODEL = DEFAULT_GEMINI_MODEL;
|
|
2169
2184
|
function extractJson(text) {
|
|
2170
|
-
const
|
|
2185
|
+
const trimmed = text.trim();
|
|
2186
|
+
const fenced = trimmed.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/);
|
|
2171
2187
|
if (fenced?.[1]) return fenced[1].trim();
|
|
2172
|
-
const start =
|
|
2173
|
-
const end =
|
|
2174
|
-
if (start >= 0 && end > start) return
|
|
2175
|
-
return
|
|
2188
|
+
const start = trimmed.indexOf("{");
|
|
2189
|
+
const end = trimmed.lastIndexOf("}");
|
|
2190
|
+
if (start >= 0 && end > start) return trimmed.slice(start, end + 1);
|
|
2191
|
+
return trimmed;
|
|
2192
|
+
}
|
|
2193
|
+
function parseGeminiResponse(text) {
|
|
2194
|
+
try {
|
|
2195
|
+
return JSON.parse(text.trim());
|
|
2196
|
+
} catch {
|
|
2197
|
+
return JSON.parse(extractJson(text));
|
|
2198
|
+
}
|
|
2176
2199
|
}
|
|
2177
2200
|
async function translatePageWithGemini(input) {
|
|
2178
2201
|
const apiKey = input.apiKey ?? process.env.GEMINI_API_KEY;
|
|
@@ -2193,7 +2216,7 @@ async function translatePageWithGemini(input) {
|
|
|
2193
2216
|
}
|
|
2194
2217
|
});
|
|
2195
2218
|
const raw = response.text ?? "";
|
|
2196
|
-
const parsed =
|
|
2219
|
+
const parsed = parseGeminiResponse(raw);
|
|
2197
2220
|
if (!parsed.frontmatter || typeof parsed.body !== "string") {
|
|
2198
2221
|
throw new Error("Gemini response missing frontmatter/body");
|
|
2199
2222
|
}
|