mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:01:01 +00:00
refactor: dedupe shared helpers
This commit is contained in:
@@ -4,6 +4,7 @@ import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { repairMintlifyAccordionIndentation } from "./lib/mintlify-accordion.mjs";
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT = path.resolve(HERE, "..");
|
||||
@@ -14,6 +15,10 @@ const SYNC_SUPPORT_FILES = [
|
||||
source: path.join(ROOT, "scripts", "check-docs-mdx.mjs"),
|
||||
target: path.join(".openclaw-sync", "check-docs-mdx.mjs"),
|
||||
},
|
||||
{
|
||||
source: path.join(ROOT, "scripts", "lib", "mintlify-accordion.mjs"),
|
||||
target: path.join(".openclaw-sync", "lib", "mintlify-accordion.mjs"),
|
||||
},
|
||||
{
|
||||
source: path.join(ROOT, ".github", "codex", "prompts", "docs-mdx-repair.md"),
|
||||
target: path.join(".openclaw-sync", "docs-mdx-repair.md"),
|
||||
@@ -284,55 +289,6 @@ function composeDocsConfig() {
|
||||
};
|
||||
}
|
||||
|
||||
function repairMintlifyAccordionIndentation(raw) {
|
||||
const lines = raw.split(/\r?\n/u);
|
||||
const accordionStack = [];
|
||||
let inCodeFence = false;
|
||||
let changed = false;
|
||||
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const line = lines[index];
|
||||
if (/^\s*(```|~~~)/u.test(line)) {
|
||||
inCodeFence = !inCodeFence;
|
||||
continue;
|
||||
}
|
||||
if (inCodeFence) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const openAccordion = line.match(/^(\s*)<Accordion\b/u);
|
||||
if (openAccordion) {
|
||||
accordionStack.push({
|
||||
indent: openAccordion[1].length,
|
||||
hasOutdentedListItem: false,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const listItem = line.match(/^(\s*)[-*+]\s+/u);
|
||||
if (listItem) {
|
||||
for (const accordion of accordionStack) {
|
||||
if (listItem[1].length < accordion.indent) {
|
||||
accordion.hasOutdentedListItem = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const closeAccordion = line.match(/^(\s*)<\/Accordion>/u);
|
||||
if (!closeAccordion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const opening = accordionStack.pop();
|
||||
if (opening && opening.hasOutdentedListItem && closeAccordion[1].length > opening.indent) {
|
||||
lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeAccordion[1].length)}`;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed ? lines.join("\n") : raw;
|
||||
}
|
||||
|
||||
function repairGeneratedLocaleDocs(targetDocsDir) {
|
||||
let repaired = 0;
|
||||
for (const locale of GENERATED_LOCALES) {
|
||||
|
||||
Reference in New Issue
Block a user