Blog: numero di articoli accanto a ogni tematica

I filtri non dicevano dove ci fosse materiale: si sceglieva una categoria
per scoprirla vuota. Ora ognuna porta il proprio conteggio, cestino e
bozze esclusi, e il numero si aggiorna insieme ai filtri quando si cambia
tematica senza ricaricare.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-31 17:16:39 +02:00
parent b7f4a7948c
commit d8862ba8ec
3 changed files with 29 additions and 3 deletions
+8
View File
@@ -69,6 +69,14 @@ export function listPublished(
return { items, total };
}
/** Quanti articoli pubblicati ha ogni categoria, cestino escluso. */
export function countPublishedByCategory(db: Database.Database): Record<string, number> {
const righe = db.prepare(
'SELECT category, COUNT(*) AS n FROM posts WHERE draft = 0 AND deleted_at IS NULL GROUP BY category'
).all() as { category: string; n: number }[];
return Object.fromEntries(righe.map((r) => [r.category, r.n]));
}
export function listAllPosts(db: Database.Database): Post[] {
return db.prepare('SELECT * FROM posts WHERE deleted_at IS NULL ORDER BY updated_at DESC').all() as Post[];
}