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:
@@ -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[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user