// GET /cms/posts/:slug — public single published post (by slug). // Resolves slug -> id via the kv slug index, increments a CAS view counter. import "util" as util; let slug = ctx.request.params.slug; if slug == () { return #{ statusCode: 400, body: #{ error: "missing slug" } }; } let idx = kv::collection("slugs"); let id = idx.get("post:" + slug); if id == () { return #{ statusCode: 404, body: #{ error: "not found" } }; } let posts = docs::collection("posts"); let doc = posts.get(id); if doc == () { return #{ statusCode: 404, body: #{ error: "not found" } }; } let p = util::shape_doc(doc); // A public reader may only see PUBLISHED posts — never a draft/scheduled one, // even if they guess the slug. (No platform per-row authz; enforced here.) if p.status != "published" { return #{ statusCode: 404, body: #{ error: "not found" } }; } let views = util::incr("views", "post:" + id); p.views = views; #{ statusCode: 200, body: p }