1

Synchronisation du contenu avec lemmy

This commit is contained in:
2025-12-11 00:02:53 +01:00
parent a0e9a87e8d
commit 181223d3d9
10 changed files with 1268 additions and 50 deletions

View File

@@ -92,8 +92,53 @@ async function resolveMarkdownTargets(inputs, { rootDir = process.cwd(), skipInd
return Array.from(targets);
}
async function collectBundles(rootDir) {
const bundles = [];
await walk(rootDir, rootDir, bundles);
bundles.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
return bundles;
}
async function walk(rootDir, currentDir, bucket) {
let entries;
try {
entries = await fs.readdir(currentDir, { withFileTypes: true });
} catch (error) {
console.warn(`⚠️ Lecture impossible de ${currentDir}: ${error.message}`);
return;
}
let hasIndex = false;
for (const entry of entries) {
if (entry.isFile() && entry.name === "index.md") {
hasIndex = true;
break;
}
}
if (hasIndex) {
const relative = path.relative(rootDir, currentDir);
const parts = relative.split(path.sep).filter(Boolean);
const slug = parts[parts.length - 1] || path.basename(currentDir);
bucket.push({
dir: currentDir,
indexPath: path.join(currentDir, "index.md"),
relativePath: parts.join("/"),
parts,
slug,
});
}
for (const entry of entries) {
if (!entry.isDirectory()) continue;
if (entry.name === ".git" || entry.name === "node_modules") continue;
await walk(rootDir, path.join(currentDir, entry.name), bucket);
}
}
module.exports = {
collectMarkdownFiles,
collectSectionIndexDirs,
resolveMarkdownTargets,
collectBundles,
};