const { query } = require('../../utils/db') const COLS = 'id, category, title, slug, excerpt, body, image_url, published, author_id, created_at, updated_at, published_at, announced_at, announce_job_id' // Published posts for a category, newest first — public feed. async function listPublished(category) { return query( `SELECT ${COLS} FROM posts WHERE category = ? AND published = 1 ` + 'ORDER BY COALESCE(published_at, created_at) DESC, id DESC', [category], ) } // Every published post, across categories, newest first — the option source // behind `core.announce.post`'s `postId` param (EVENTS.md §F, Phase 10). Its own // query rather than a loop over `listPublished` because an authoring dropdown // wants one bounded, ordered list and needs neither the body nor the excerpt: a // hundred posts' bodies would be a megabyte of HTML sent to draw a `