forked from admin/zeropost-engine
feat: categories table, API, category field in articles
This commit is contained in:
@@ -31,14 +31,12 @@ function estimateReadingTime(text) {
|
||||
/**
|
||||
* Список опубликованных статей.
|
||||
*/
|
||||
async function listArticles({ limit = 20, offset = 0, tag = null } = {}) {
|
||||
let sql = `SELECT id, slug, title, excerpt, cover_url, tags, author, reading_time, published_at
|
||||
async function listArticles({ limit = 20, offset = 0, tag = null, category = null } = {}) {
|
||||
let sql = `SELECT id, slug, title, excerpt, cover_url, tags, category, author, reading_time, published_at
|
||||
FROM articles WHERE status='published'`;
|
||||
const params = [];
|
||||
if (tag) {
|
||||
sql += ` AND tags ?? $${params.length + 1}`;
|
||||
params.push(tag);
|
||||
}
|
||||
if (tag) { sql += ` AND tags ?? ${params.length + 1}`; params.push(tag); }
|
||||
if (category) { sql += ` AND category=${params.length + 1}`; params.push(category); }
|
||||
sql += ` ORDER BY published_at DESC LIMIT $${params.length + 1} OFFSET $${params.length + 2}`;
|
||||
params.push(limit, offset);
|
||||
const { rows } = await query(sql, params);
|
||||
|
||||
Reference in New Issue
Block a user