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 = ...@@ -25,20 +25,35 @@ const token =
})(); })();
// Same post-ness rule as lib/blog.js (kept inline: that module is // Same post-ness rule as lib/blog.js (kept inline: that module is
// Next-bundler ESM, not importable from a bare node script). // Next-bundler ESM, not importable from a bare node script). Posts live
const slugs = fs // 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) .readdirSync(BLOG_ROOT)
.filter((f) => fs.statSync(path.join(BLOG_ROOT, f)).isDirectory()) .filter((f) => fs.statSync(path.join(BLOG_ROOT, f)).isDirectory())
.filter( .flatMap((f) => {
(f) => const dir = path.join(BLOG_ROOT, f);
fs.existsSync(path.join(BLOG_ROOT, f, 'meta.md')) || if (/^\d{4}$/.test(f)) {
LANGS.some((lang) => fs.existsSync(path.join(BLOG_ROOT, f, `${lang}.md`))), return fs
) .readdirSync(dir)
.filter((f) => { .filter((c) => fs.statSync(path.join(dir, c)).isDirectory())
const meta = fs.readFileSync(path.join(BLOG_ROOT, f, 'meta.md'), 'utf8'); .filter((c) => isPostDir(path.join(dir, c)))
return !/^draft:\s*true/m.test(meta); .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; let ok = 0;
for (const slug of slugs) { for (const slug of slugs) {
const res = await fetch(`${BASE}/posts/${slug}`, { const res = await fetch(`${BASE}/posts/${slug}`, {
......
...@@ -37,10 +37,23 @@ const NOISE_CONTEXT = [ ...@@ -37,10 +37,23 @@ const NOISE_CONTEXT = [
const targets = process.argv.slice(2); const targets = process.argv.slice(2);
const files = []; 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) { function collect(slugOrFile) {
if (slugOrFile.endsWith('.md')) return files.push(path.resolve(slugOrFile)); if (slugOrFile.endsWith('.md')) return files.push(path.resolve(slugOrFile));
const dir = path.isAbsolute(slugOrFile) ? slugOrFile : path.join(BLOG_ROOT, slugOrFile); const dir = path.isAbsolute(slugOrFile) ? slugOrFile : postDir(slugOrFile);
if (fs.existsSync(dir)) { if (dir) {
for (const f of fs.readdirSync(dir)) { for (const f of fs.readdirSync(dir)) {
if (/^(fr|en)\.md$/.test(f)) files.push(path.join(dir, f)); if (/^(fr|en)\.md$/.test(f)) files.push(path.join(dir, f));
} }
...@@ -51,9 +64,18 @@ function collect(slugOrFile) { ...@@ -51,9 +64,18 @@ function collect(slugOrFile) {
if (targets.length > 0) targets.forEach(collect); if (targets.length > 0) targets.forEach(collect);
else { else {
for (const slug of fs.readdirSync(BLOG_ROOT)) { for (const name of fs.readdirSync(BLOG_ROOT)) {
const dir = path.join(BLOG_ROOT, slug); const dir = path.join(BLOG_ROOT, name);
if (fs.statSync(dir).isDirectory()) collect(dir); 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