Rediseno home: hero destacado, chips de genero, masonry + scroll infinito, busqueda publica /buscar, footer comunidad, status/queue protegidos

This commit is contained in:
Renato
2026-08-04 13:21:13 +08:00
parent ff3ec34674
commit 7f939b76a4
10 changed files with 430 additions and 46 deletions
+32
View File
@@ -214,6 +214,38 @@ export function getPostCount(): number {
return row.count
}
// Búsqueda pública por título/título_jpn/artista/tags (LIKE sobre JSON).
export function searchPosts(query: string, publishedOnly = true): Post[] {
const d = getDb()
const q = `%${query}%`
const where = publishedOnly ? "published = 1 AND" : ""
const rows = d
.prepare(
`SELECT * FROM posts WHERE ${where} (
title LIKE @q OR
title_jpn LIKE @q OR
artist LIKE @q OR
parody LIKE @q OR
tags LIKE @q
) ORDER BY published_at DESC LIMIT 100`,
)
.all({ q }) as Record<string, unknown>[]
return rows.map(rowToPost)
}
// Paginación de la home pública.
export function getPostsPage(page: number, perPage: number, publishedOnly = true): { items: Post[]; total: number } {
const d = getDb()
const offset = (page - 1) * perPage
const where = publishedOnly ? "WHERE published = 1" : ""
const order = publishedOnly ? "published_at DESC" : "created_at DESC"
const rows = d
.prepare(`SELECT * FROM posts ${where} ORDER BY ${order} LIMIT @perPage OFFSET @offset`)
.all({ perPage, offset }) as Record<string, unknown>[]
const total = (d.prepare(`SELECT COUNT(*) as count FROM posts ${where}`).get() as { count: number }).count
return { items: rows.map(rowToPost), total }
}
export function getGidsNotInPosts(): string[] {
return []
}