Skip to content

Commit 78c9faf

Browse files
committed
Add anchor and image validation checks
1 parent 5217951 commit 78c9faf

File tree

5 files changed

+229
-147
lines changed

5 files changed

+229
-147
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

locales.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export interface HelpLocales {
2+
docusaurus: string;
3+
crowdin: string;
4+
}
5+
6+
export const helpLocales = [
7+
{
8+
docusaurus: "de",
9+
crowdin: "de",
10+
},
11+
{
12+
docusaurus: "es",
13+
crowdin: "es-ES",
14+
},
15+
{
16+
docusaurus: "fr",
17+
crowdin: "fr",
18+
},
19+
{
20+
docusaurus: "pt-BR",
21+
crowdin: "pt-BR",
22+
},
23+
{
24+
docusaurus: "id",
25+
crowdin: "id",
26+
},
27+
] as HelpLocales[];

regex_validation.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export interface RegexValidation {
2+
expression: RegExp;
3+
message: string;
4+
filesToSkip?: string[];
5+
}
6+
7+
export const regexValidations: RegexValidation[] = [
8+
{
9+
expression: /^---\n(.*?)\n---/s,
10+
message: "front matter"
11+
},
12+
{
13+
expression: /(?:(?=)({#[\d\w]+}))/gs,
14+
message: "anchor",
15+
filesToSkip: ["Community-Checking/enable-community-checking.md", "Draft-Generation/generating-a-draft.md"]
16+
},
17+
{
18+
expression: /(?:(?=)(!\[\]\(\.\/[\d]+\.png\)))/gs,
19+
message: "image",
20+
filesToSkip: ["connect-paratext-project.md"] //["Draft-Generation/understanding-drafts.md"]
21+
}
22+
]

update.mts

Lines changed: 2 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// This doesn't fully solve the problem though, because metadata in the translated files may be different from the English files.
99

1010
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";
1213

1314
const projectId = Deno.env.get("CROWDIN_PROJECT_ID");
1415
const apiKey = Deno.env.get("CROWDIN_API_KEY");
@@ -112,29 +113,6 @@ async function saveLatestBuild() {
112113
}
113114
}
114115

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-
138116
async function copyDirContentsRecursive(
139117
source: string,
140118
dest: string
@@ -216,129 +194,6 @@ async function fetchNotionDocs() {
216194
}
217195
}
218196

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-
342197
try {
343198
console.log("--- Deleting existing files ---");
344199
await deleteExistingFiles();

0 commit comments

Comments
 (0)