Commit 9742bd8d by PLN (Algolia)

comments-sync & prose: l'énumération descend dans les groupes d'année comme le…

comments-sync & prose: l'énumération descend dans les groupes d'année comme le walker de lib/blog.js — sinon plus aucun post whitelisté (comments-sync) ni linté (prose, y compris l'argument slug résolu à travers les années)
parent 4d73f6dc
......@@ -25,20 +25,35 @@ const token =
})();
// Same post-ness rule as lib/blog.js (kept inline: that module is
// Next-bundler ESM, not importable from a bare node script).
const slugs = fs
// Next-bundler ESM, not importable from a bare node script). Posts live
// under year groups: a 4-digit directory is descended into, any other
// directory is a leaf; the slug is the folder basename either way.
const isPostDir = (dir) =>
fs.existsSync(path.join(dir, 'meta.md')) ||
LANGS.some((lang) => fs.existsSync(path.join(dir, `${lang}.md`)));
const posts = fs
.readdirSync(BLOG_ROOT)
.filter((f) => fs.statSync(path.join(BLOG_ROOT, f)).isDirectory())
.filter(
(f) =>
fs.existsSync(path.join(BLOG_ROOT, f, 'meta.md')) ||
LANGS.some((lang) => fs.existsSync(path.join(BLOG_ROOT, f, `${lang}.md`))),
)
.filter((f) => {
const meta = fs.readFileSync(path.join(BLOG_ROOT, f, 'meta.md'), 'utf8');
return !/^draft:\s*true/m.test(meta);
.flatMap((f) => {
const dir = path.join(BLOG_ROOT, f);
if (/^\d{4}$/.test(f)) {
return fs
.readdirSync(dir)
.filter((c) => fs.statSync(path.join(dir, c)).isDirectory())
.filter((c) => isPostDir(path.join(dir, c)))
.map((c) => ({ slug: c, dir: path.join(dir, c) }));
}
return isPostDir(dir) ? [{ slug: f, dir }] : [];
});
const slugs = posts
.filter(({ dir }) => {
const meta = fs.readFileSync(path.join(dir, 'meta.md'), 'utf8');
return !/^draft:\s*true/m.test(meta);
})
.map(({ slug }) => slug);
let ok = 0;
for (const slug of slugs) {
const res = await fetch(`${BASE}/posts/${slug}`, {
......
......@@ -37,10 +37,23 @@ const NOISE_CONTEXT = [
const targets = process.argv.slice(2);
const files = [];
/** Folder of a post slug — posts live under year groups, so check the root
level first, then each 4-digit year group. Null when nowhere. */
function postDir(slug) {
const rootLevel = path.join(BLOG_ROOT, slug);
if (fs.existsSync(rootLevel)) return rootLevel;
for (const name of fs.readdirSync(BLOG_ROOT)) {
if (!/^\d{4}$/.test(name)) continue;
const candidate = path.join(BLOG_ROOT, name, slug);
if (fs.existsSync(candidate)) return candidate;
}
return null;
}
function collect(slugOrFile) {
if (slugOrFile.endsWith('.md')) return files.push(path.resolve(slugOrFile));
const dir = path.isAbsolute(slugOrFile) ? slugOrFile : path.join(BLOG_ROOT, slugOrFile);
if (fs.existsSync(dir)) {
const dir = path.isAbsolute(slugOrFile) ? slugOrFile : postDir(slugOrFile);
if (dir) {
for (const f of fs.readdirSync(dir)) {
if (/^(fr|en)\.md$/.test(f)) files.push(path.join(dir, f));
}
......@@ -51,9 +64,18 @@ function collect(slugOrFile) {
if (targets.length > 0) targets.forEach(collect);
else {
for (const slug of fs.readdirSync(BLOG_ROOT)) {
const dir = path.join(BLOG_ROOT, slug);
if (fs.statSync(dir).isDirectory()) collect(dir);
for (const name of fs.readdirSync(BLOG_ROOT)) {
const dir = path.join(BLOG_ROOT, name);
if (!fs.statSync(dir).isDirectory()) continue;
// Year group: the posts live one level down, slug = basename.
if (/^\d{4}$/.test(name)) {
for (const child of fs.readdirSync(dir)) {
const childDir = path.join(dir, child);
if (fs.statSync(childDir).isDirectory()) collect(childDir);
}
} else {
collect(dir);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment