summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-07-06 16:50:47 -0300
committerJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-07-06 16:50:47 -0300
commit4ae2b810b68538ba4c287b0c80d6c2e002fe9ddd (patch)
tree3231edc93eabd59aee99e0f109a7c4932de5b46f /src/pages
parent75704b00718f6fe675975c90b27ee767fe5a71cb (diff)
fix: all items correctly
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/outbox.json.ts98
1 files changed, 77 insertions, 21 deletions
diff --git a/src/pages/outbox.json.ts b/src/pages/outbox.json.ts
index 9e2505f..64b0b18 100644
--- a/src/pages/outbox.json.ts
+++ b/src/pages/outbox.json.ts
@@ -1,37 +1,93 @@
import type { APIRoute } from "astro";
import { env } from "../lib/environment.ts";
-import { fromPosts, isOriginal } from "../lib/collection/helpers.ts";
+import {
+ fromPosts,
+ isOriginal,
+ isTranslation,
+ sortFirstCreated,
+} from "../lib/collection/helpers.ts";
+import { getCollection } from "astro:content";
+import { Original, Translation } from "../lib/collection/schemas.ts";
+import { defined } from "../utils/anonymous.ts";
const { PUBLIC_SITE_URL } = env;
const site = new URL(PUBLIC_SITE_URL);
export const GET: APIRoute = async (): Promise<Response> => {
- const orderedItems = await fromPosts(
- isOriginal,
- (x) =>
- x.map(({ id, data, rendered }) => {
- const { dateCreated, title } = data;
- return {
+ const collection = await getCollection("blog");
+ const orderedItems = collection.map(({ id, data, rendered }) => {
+ const original = Original.safeParse(data);
+ if (original.success) {
+ const { dateCreated, title } = original.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: "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 ?? "",
- },
- };
- }),
+ type: "Article",
+ name: title,
+ url: new URL(`blog/read/${id}`, site).href,
+ content: rendered?.html ?? "",
+ alternate: collection.filter(isTranslation).map(({ id, data }) => {
+ const { lang } = data;
+ return {
+ "type": "Link",
+ href: new URL(`blog/read/${id}`, site).href,
+ "hreflang": lang,
+ };
+ }),
+ },
+ };
+ }
+ const translation = Translation.safeParse(data);
+ if (translation.success) {
+ const { dateCreated, title, translationOf } = translation.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 ?? "",
+ inReplyTo: new URL(`blog/read/${translationOf.id}`, site).href,
+ },
+ };
+ }
+ const micro = Translation.safeParse(data);
+ if (micro.success) {
+ const { dateCreated, title } = micro.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: "Note",
+ name: title,
+ url: new URL(`blog/read/${id}`, site).href,
+ content: rendered?.html ?? "",
+ },
+ };
+ }
+ return undefined;
+ }).filter(defined).sort((a, b) =>
+ new Date(a.published).getTime() - new Date(b.published).getTime()
);
const outbox = {
"@context": "https://www.w3.org/ns/activitystreams",
id: new URL("outbox.json", site).href,
type: "OrderedCollection",
- totalItems: 1,
+ totalItems: orderedItems.length,
orderedItems,
};
return new Response(JSON.stringify(outbox), {