// GET /cms/posts — public list of PUBLISHED posts, newest first. // Optional ?tag= filters by tag. Since the platform fix (F-015), the docs // filter DSL supports `$contains` (JSONB @>) for array-membership, so the tag // filter now runs IN THE DATABASE with real pagination — no over-fetch/in-script // scan needed. import "util" as util; let posts = docs::collection("posts"); let per = util::to_int_or(vars::get("posts-per-page"), 10); let tag = ctx.request.query["tag"]; let filter = #{ status: "published", "$sort": #{ publish_at: -1 }, "$limit": per }; if tag != () { filter.tags = #{ "$contains": tag }; } let rows = posts.find(filter); let out = []; for r in rows { let p = util::shape_doc(r); p.remove("body_md"); // list view: excerpt only out.push(p); } #{ statusCode: 200, body: #{ posts: out, tag: tag } }