Leaflet Blog in Deno Fresh
1import { bsky } from "./bsky.ts"; 2import { env } from "./env.ts"; 3 4import { type ComAtprotoRepoListRecords } from "npm:@atcute/client/lexicons"; 5import { type ComWhtwndBlogEntry } from "npm:@atcute/whitewind"; 6 7export async function getPosts() { 8 const posts = await bsky.get("com.atproto.repo.listRecords", { 9 params: { 10 repo: env.NEXT_PUBLIC_BSKY_DID, 11 collection: "com.whtwnd.blog.entry", 12 // todo: pagination 13 }, 14 }); 15 return posts.data.records.filter( 16 drafts, 17 ) as (ComAtprotoRepoListRecords.Record & { 18 value: ComWhtwndBlogEntry.Record; 19 })[]; 20} 21 22function drafts(record: ComAtprotoRepoListRecords.Record) { 23 if (Deno.env.get("NODE_ENV") === "development") return true; 24 const post = record.value as ComWhtwndBlogEntry.Record; 25 return post.visibility === "public"; 26} 27 28export async function getPost(rkey: string) { 29 const post = await bsky.get("com.atproto.repo.getRecord", { 30 params: { 31 repo: env.NEXT_PUBLIC_BSKY_DID, 32 rkey: rkey, 33 collection: "com.whtwnd.blog.entry", 34 }, 35 }); 36 37 return post.data as ComAtprotoRepoListRecords.Record & { 38 value: ComWhtwndBlogEntry.Record; 39 }; 40}