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,55 @@
#!/usr/bin/env node
const { loadArticles } = require("../lib/stats/articles");
const { renderWithPython } = require("../lib/stats/python");
function groupBySection(articles) {
const counts = new Map();
for (const article of articles) {
const key = article.section || "root";
counts.set(key, (counts.get(key) || 0) + 1);
}
const entries = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
return entries;
}
async function run({ contentDir, outputPath, publicPath }) {
if (!outputPath) {
throw new Error("outputPath manquant pour articles_per_section");
}
const articles = await loadArticles(contentDir || "content");
const entries = groupBySection(articles);
const maxSlices = 21;
const top = entries.slice(0, maxSlices);
const rest = entries.slice(maxSlices);
if (rest.length > 0) {
const restSum = rest.reduce((sum, [, value]) => sum + value, 0);
top.push(["Others", restSum]);
}
const labels = top.map(([key]) => key);
const values = top.map(([, value]) => value);
await renderWithPython({
type: "articles_per_section",
outputPath,
data: {
labels,
values,
title: "Articles par section",
},
});
return {
image: publicPath,
meta: {
sections: entries.length,
},
};
}
module.exports = { run };