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

@@ -1,7 +1,7 @@
#!/usr/bin/env node
const fs = require("fs/promises");
const path = require("path");
const { resolveMarkdownTargets } = require("./lib/content");
const { extractRawDate, readFrontmatter, writeFrontmatter } = require("./lib/weather/frontmatter");
const { resolveArticleDate } = require("./lib/weather/time");
const { fetchWeather, hasConfiguredProvider, mergeWeather } = require("./lib/weather/providers");
@@ -9,62 +9,6 @@ const { loadWeatherConfig } = require("./lib/weather/config");
const CONTENT_ROOT = path.resolve("content");
async function collectMarkdownFiles(rootDir) {
const entries = await fs.readdir(rootDir, { withFileTypes: true });
const files = [];
for (const entry of entries) {
const fullPath = path.join(rootDir, entry.name);
if (entry.isDirectory()) {
const nested = await collectMarkdownFiles(fullPath);
files.push(...nested);
continue;
}
if (!entry.isFile()) continue;
if (!entry.name.endsWith(".md")) continue;
if (entry.name === "_index.md") continue;
files.push(fullPath);
}
return files;
}
async function resolveTargets(args) {
if (args.length === 0) {
return collectMarkdownFiles(CONTENT_ROOT);
}
const targets = new Set();
for (const input of args) {
const resolved = path.resolve(input);
try {
const stat = await fs.stat(resolved);
if (stat.isDirectory()) {
const nested = await collectMarkdownFiles(resolved);
nested.forEach((file) => targets.add(file));
continue;
}
if (stat.isFile()) {
if (!resolved.endsWith(".md")) continue;
if (path.basename(resolved) === "_index.md") continue;
targets.add(resolved);
}
} catch (error) {
console.error(`Skipping ${input}: ${error.message}`);
}
}
return Array.from(targets);
}
async function processFile(filePath, config, { force = false } = {}) {
const frontmatter = await readFrontmatter(filePath);
@@ -128,7 +72,7 @@ async function main() {
console.error("No weather provider configured. Update tools/config.json (weather.providers) before running this script.");
process.exit(1);
}
const files = await resolveTargets(pathArgs);
const files = await resolveMarkdownTargets(pathArgs, { rootDir: CONTENT_ROOT });
if (files.length === 0) {
console.log("No matching markdown files found.");