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,32 @@
#!/usr/bin/env node
const { loadArticles } = require("../lib/stats/articles");
function computeAveragePerMonth(articles) {
let first = null;
let last = null;
for (const article of articles) {
if (!article.date) continue;
if (!first || article.date < first) first = article.date;
if (!last || article.date > last) last = article.date;
}
if (!first || !last) {
return { average: 0, months: 0 };
}
const monthSpan = Math.max(1, Math.round(last.diff(first.startOf("month"), "months").months) + 1);
const total = articles.filter((a) => a.date).length;
const average = total / monthSpan;
return { average, months: monthSpan };
}
async function run({ contentDir }) {
const articles = await loadArticles(contentDir || "content");
const { average, months } = computeAveragePerMonth(articles);
return { value: average.toFixed(2), meta: { months } };
}
module.exports = { run };