





















@@ -167,6 +167,28 @@ function ensureDir(dirPath) {
167167fs.mkdirSync(dirPath, { recursive: true });
168168}
169169170+function walkMarkdownFiles(entryPath, out = []) {
171+if (!fs.existsSync(entryPath)) {
172+return out;
173+}
174+175+const stat = fs.statSync(entryPath);
176+if (stat.isFile()) {
177+if (/\.mdx?$/i.test(entryPath)) {
178+out.push(entryPath);
179+}
180+return out;
181+}
182+183+for (const entry of fs.readdirSync(entryPath, { withFileTypes: true })) {
184+if (entry.name === "node_modules" || entry.name === ".git") {
185+continue;
186+}
187+walkMarkdownFiles(path.join(entryPath, entry.name), out);
188+}
189+return out;
190+}
191+170192function readJson(filePath) {
171193return JSON.parse(fs.readFileSync(filePath, "utf8"));
172194}
@@ -262,6 +284,75 @@ function composeDocsConfig() {
262284};
263285}
264286287+function repairMintlifyAccordionIndentation(raw) {
288+const lines = raw.split(/\r?\n/u);
289+const accordionStack = [];
290+let inCodeFence = false;
291+let changed = false;
292+293+for (let index = 0; index < lines.length; index += 1) {
294+const line = lines[index];
295+if (/^\s*(```|~~~)/u.test(line)) {
296+inCodeFence = !inCodeFence;
297+continue;
298+}
299+if (inCodeFence) {
300+continue;
301+}
302+303+const openAccordion = line.match(/^(\s*)<Accordion\b/u);
304+if (openAccordion) {
305+accordionStack.push({
306+indent: openAccordion[1].length,
307+hasOutdentedListItem: false,
308+});
309+continue;
310+}
311+312+const listItem = line.match(/^(\s*)[-*+]\s+/u);
313+if (listItem) {
314+for (const accordion of accordionStack) {
315+if (listItem[1].length < accordion.indent) {
316+accordion.hasOutdentedListItem = true;
317+}
318+}
319+}
320+321+const closeAccordion = line.match(/^(\s*)<\/Accordion>/u);
322+if (!closeAccordion) {
323+continue;
324+}
325+326+const opening = accordionStack.pop();
327+if (opening && opening.hasOutdentedListItem && closeAccordion[1].length > opening.indent) {
328+lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeAccordion[1].length)}`;
329+changed = true;
330+}
331+}
332+333+return changed ? lines.join("\n") : raw;
334+}
335+336+function repairGeneratedLocaleDocs(targetDocsDir) {
337+let repaired = 0;
338+for (const locale of GENERATED_LOCALES) {
339+const localeDir = path.join(targetDocsDir, locale.dir);
340+for (const filePath of walkMarkdownFiles(localeDir)) {
341+const raw = fs.readFileSync(filePath, "utf8");
342+const repairedRaw = repairMintlifyAccordionIndentation(raw);
343+if (repairedRaw === raw) {
344+continue;
345+}
346+fs.writeFileSync(filePath, repairedRaw);
347+repaired += 1;
348+}
349+}
350+351+if (repaired > 0) {
352+console.log(`Repaired Mintlify accordion indentation in ${repaired} generated locale doc(s).`);
353+}
354+}
355+265356function syncDocsTree(targetRoot) {
266357const targetDocsDir = path.join(targetRoot, "docs");
267358ensureDir(targetDocsDir);
@@ -298,6 +389,7 @@ function syncDocsTree(targetRoot) {
298389}
299390}
300391392+repairGeneratedLocaleDocs(targetDocsDir);
301393writeJson(path.join(targetDocsDir, "docs.json"), composeDocsConfig());
302394}
303395此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。