|
8 | 8 | // This doesn't fully solve the problem though, because metadata in the translated files may be different from the English files. |
9 | 9 |
|
10 | 10 | import { copy, readerFromStreamReader } from "jsr:@std/io"; |
11 | | -import { walk } from "jsr:@std/fs/walk"; |
| 11 | +import { helpLocales } from "./locales.ts"; |
| 12 | +import { runChecks } from "./validate_docs.mts"; |
12 | 13 |
|
13 | 14 | const projectId = Deno.env.get("CROWDIN_PROJECT_ID"); |
14 | 15 | const apiKey = Deno.env.get("CROWDIN_API_KEY"); |
@@ -112,29 +113,6 @@ async function saveLatestBuild() { |
112 | 113 | } |
113 | 114 | } |
114 | 115 |
|
115 | | -const helpLocales = [ |
116 | | - { |
117 | | - docusaurus: "de", |
118 | | - crowdin: "de", |
119 | | - }, |
120 | | - { |
121 | | - docusaurus: "es", |
122 | | - crowdin: "es-ES", |
123 | | - }, |
124 | | - { |
125 | | - docusaurus: "fr", |
126 | | - crowdin: "fr", |
127 | | - }, |
128 | | - { |
129 | | - docusaurus: "pt-BR", |
130 | | - crowdin: "pt-BR", |
131 | | - }, |
132 | | - { |
133 | | - docusaurus: "id", |
134 | | - crowdin: "id", |
135 | | - }, |
136 | | -] as const; |
137 | | - |
138 | 116 | async function copyDirContentsRecursive( |
139 | 117 | source: string, |
140 | 118 | dest: string |
@@ -216,129 +194,6 @@ async function fetchNotionDocs() { |
216 | 194 | } |
217 | 195 | } |
218 | 196 |
|
219 | | -async function runChecks() { |
220 | | - // Check for malformed links in the i18n files |
221 | | - |
222 | | - for await (const dirEntry of walk(`${projectRoot}/i18n`)) { |
223 | | - if (dirEntry.isFile && dirEntry.name.endsWith(".md")) { |
224 | | - const file = await Deno.readTextFile(dirEntry.path); |
225 | | - for (const [index, line] of file.split("\n").entries()) { |
226 | | - // Look for Markdown links that had a space added between the closing parenthesis and the opening bracket |
227 | | - if (/\]\s+\(/.test(line)) { |
228 | | - console.log( |
229 | | - `%cFound malformed link in ${dirEntry.path} at line ${index + 1}`, |
230 | | - "color: red" |
231 | | - ); |
232 | | - console.log(line); |
233 | | - console.log( |
234 | | - " ".repeat(line.indexOf("]") + 1) + "%c^ Erroneous space", |
235 | | - "color: blue" |
236 | | - ); |
237 | | - } |
238 | | - } |
239 | | - } |
240 | | - } |
241 | | - |
242 | | - // Check that all original docs have a corresponding translation, and vice versa |
243 | | - const originalDocs = new Map<string, string>(); |
244 | | - const docsDir = `${projectRoot}/docs`; |
245 | | - for await (const dirEntry of walk(docsDir)) { |
246 | | - if (dirEntry.isFile && dirEntry.name.endsWith(".md")) { |
247 | | - if (dirEntry.path.indexOf(docsDir) !== 0) |
248 | | - throw new Error("Unexpected path"); |
249 | | - const relativePath = dirEntry.path.slice(docsDir.length + 1); |
250 | | - originalDocs.set(relativePath, await Deno.readTextFile(dirEntry.path)); |
251 | | - } |
252 | | - } |
253 | | - |
254 | | - for (const locale of helpLocales) { |
255 | | - const i18nDir = `${projectRoot}/i18n/${locale.docusaurus}/docusaurus-plugin-content-docs/current`; |
256 | | - |
257 | | - const foundLocalizations = new Set<string>(); |
258 | | - |
259 | | - for await (const dirEntry of walk(i18nDir)) { |
260 | | - if (dirEntry.isFile && dirEntry.name.endsWith(".md")) { |
261 | | - if (dirEntry.path.indexOf(i18nDir) !== 0) |
262 | | - throw new Error("Unexpected path"); |
263 | | - |
264 | | - const relativePath = dirEntry.path.slice(i18nDir.length + 1); |
265 | | - |
266 | | - foundLocalizations.add(relativePath); |
267 | | - |
268 | | - if (!originalDocs.has(relativePath)) { |
269 | | - console.log( |
270 | | - `%cNo original document found for i18n file ${dirEntry.path}`, |
271 | | - "color: red" |
272 | | - ); |
273 | | - } |
274 | | - } |
275 | | - } |
276 | | - for (const [relativePath, content] of originalDocs) { |
277 | | - if (!foundLocalizations.has(relativePath)) { |
278 | | - console.log( |
279 | | - `%cNo translation file found for ${relativePath} in ${i18nDir}`, |
280 | | - "color: red" |
281 | | - ); |
282 | | - } else { |
283 | | - // Check that the front matter matches |
284 | | - const translation = await Deno.readTextFile( |
285 | | - `${i18nDir}/${relativePath}` |
286 | | - ); |
287 | | - const frontMatterRegex = /^---\n(.*?)\n---/s; |
288 | | - const originalFrontMatterMatch = content.match(frontMatterRegex); |
289 | | - const translationFrontMatterMatch = translation.match(frontMatterRegex); |
290 | | - if (originalFrontMatterMatch == null) { |
291 | | - console.log( |
292 | | - `%cNo front matter found in original document ${relativePath}`, |
293 | | - "color: red" |
294 | | - ); |
295 | | - } |
296 | | - if (translationFrontMatterMatch == null) { |
297 | | - console.log( |
298 | | - `%cNo front matter found in translation ${relativePath}`, |
299 | | - "color: red" |
300 | | - ); |
301 | | - } |
302 | | - |
303 | | - if ( |
304 | | - originalFrontMatterMatch == null || |
305 | | - translationFrontMatterMatch == null |
306 | | - ) |
307 | | - continue; |
308 | | - |
309 | | - const originalFrontMatter = originalFrontMatterMatch[1].split("\n"); |
310 | | - const translationFrontMatter = |
311 | | - translationFrontMatterMatch[1].split("\n"); |
312 | | - |
313 | | - if (originalFrontMatter.length !== translationFrontMatter.length) { |
314 | | - console.log( |
315 | | - `%cFront matter length mismatch in ${relativePath} for locale ${locale.docusaurus}`, |
316 | | - "color: red" |
317 | | - ); |
318 | | - } |
319 | | - |
320 | | - for (const [index, line] of originalFrontMatter.entries()) { |
321 | | - // the title can change; everything else should match |
322 | | - if (line.indexOf("title: ") === 0) continue; |
323 | | - if (line !== translationFrontMatter[index]) { |
324 | | - console.log( |
325 | | - `%cFront matter mismatch in ${relativePath} for locale ${ |
326 | | - locale.docusaurus |
327 | | - } at line ${index + 1}`, |
328 | | - "color: red" |
329 | | - ); |
330 | | - console.log(`%cOriginal: ${line}`, "color: blue"); |
331 | | - console.log( |
332 | | - `%cTranslation: ${translationFrontMatter[index]}`, |
333 | | - "color: blue" |
334 | | - ); |
335 | | - } |
336 | | - } |
337 | | - } |
338 | | - } |
339 | | - } |
340 | | -} |
341 | | - |
342 | 197 | try { |
343 | 198 | console.log("--- Deleting existing files ---"); |
344 | 199 | await deleteExistingFiles(); |
|
0 commit comments