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