diff options
author | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-07-06 15:45:22 -0300 |
---|---|---|
committer | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-07-06 15:45:22 -0300 |
commit | a8c6eb9542e4baba3ce05da454fc52548214ba06 (patch) | |
tree | 4a2bac5ad88bc56fb24eab4ad398094341fc3810 /src/pages/outbox.json.ts | |
parent | 87df5a27cb34ada02f54dacf4299574f04038612 (diff) |
feat: kind of integrate activity pub
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'src/pages/outbox.json.ts')
-rw-r--r-- | src/pages/outbox.json.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/pages/outbox.json.ts b/src/pages/outbox.json.ts new file mode 100644 index 0000000..cec761e --- /dev/null +++ b/src/pages/outbox.json.ts @@ -0,0 +1,41 @@ +import type { APIRoute } from "astro"; +import { env } from "../lib/environment.ts"; +import { fromPosts, isOriginal } from "../lib/collection/helpers.ts"; + +const { PUBLIC_SITE_URL } = env; +const site = new URL(PUBLIC_SITE_URL); + +const orderedItems = fromPosts( + isOriginal, + (x) => + x.map(({ id, data, rendered }) => { + const { dateCreated, title } = data; + return { + id: new URL(`blog/read/${id}`, site).href, + type: "Create", + actor: new URL("actor.json", site).href, + published: dateCreated.toISOString(), + to: ["https://www.w3.org/ns/activitystreams#Public"], + object: { + id: new URL(`blog/read/${id}`, site).href, + type: "Article", + name: title, + url: new URL(`blog/read/${id}`, site).href, + content: rendered?.html ?? "", + }, + }; + }), +); +const outbox = { + "@context": "https://www.w3.org/ns/activitystreams", + id: new URL("outbox.json", site).href, + type: "OrderedCollection", + totalItems: 1, + orderedItems, +}; + +export const GET: APIRoute = (): Response => { + return new Response(JSON.stringify(outbox), { + headers: { "Content-Type": "application/activity+json" }, + }); +}; |