1

Page de statistiques

This commit is contained in:
2025-11-28 01:47:10 +01:00
parent 38926267a3
commit fd27dc7fb6
47 changed files with 3278 additions and 86 deletions

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env node
const { DateTime } = require("luxon");
const { loadArticles } = require("../lib/stats/articles");
async function computeMostProlificMonth(contentDir) {
const articles = await loadArticles(contentDir);
const counts = new Map();
for (const article of articles) {
if (!article.date) continue;
const monthKey = article.date.toFormat("yyyy-MM");
counts.set(monthKey, (counts.get(monthKey) || 0) + 1);
}
if (counts.size === 0) {
return null;
}
const sorted = Array.from(counts.entries()).sort((a, b) => {
if (b[1] !== a[1]) return b[1] - a[1];
return a[0] < b[0] ? -1 : 1;
});
const [monthKey, count] = sorted[0];
const label = DateTime.fromISO(`${monthKey}-01`).setLocale("fr").toFormat("LLLL yyyy");
return { value: `${label} (${count})`, month: monthKey, count };
}
async function run({ contentDir }) {
const result = await computeMostProlificMonth(contentDir || "content");
return result || { value: null };
}
module.exports = { run };