Synchronisation du contenu avec lemmy
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user