From 0f7285b6e4afaf20c4649abef86b730bc28b82a0 Mon Sep 17 00:00:00 2001 From: Stefan Probst Date: Sun, 17 Mar 2024 17:57:35 +0100 Subject: [PATCH] feat: add route handler --- app/rss.xml/route.ts | 7 ++++++ components/app-header.tsx | 13 ++++++++--- lib/{feed.ts => create-feed.ts} | 38 +++++++++++++++++---------------- 3 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 app/rss.xml/route.ts rename lib/{feed.ts => create-feed.ts} (63%) diff --git a/app/rss.xml/route.ts b/app/rss.xml/route.ts new file mode 100644 index 000000000..eea52a16a --- /dev/null +++ b/app/rss.xml/route.ts @@ -0,0 +1,7 @@ +import { createFeed } from "@/lib/create-feed"; + +export async function GET(): Promise { + const feed = await createFeed("en"); + + return new Response(feed, { headers: { "content-type": "application/xml" } }); +} diff --git a/components/app-header.tsx b/components/app-header.tsx index d5d621891..217d2b445 100644 --- a/components/app-header.tsx +++ b/components/app-header.tsx @@ -1,3 +1,4 @@ +import { MenuIcon } from "lucide-react"; import { useTranslations } from "next-intl"; import { AppNavLink } from "@/components/app-nav-link"; @@ -5,6 +6,7 @@ import { ColorSchemeSwitcher } from "@/components/color-scheme-switcher"; import type { LinkProps } from "@/components/link"; import { LocaleSwitcher } from "@/components/locale-switcher"; import { Logo } from "@/components/logo"; +import { IconButton } from "@/components/ui/icon-button"; import { createHref } from "@/lib/create-href"; export function AppHeader() { @@ -18,8 +20,8 @@ export function AppHeader() { return (
-
-
diff --git a/lib/feed.ts b/lib/create-feed.ts similarity index 63% rename from lib/feed.ts rename to lib/create-feed.ts index 2681360c9..c4f7934f6 100644 --- a/lib/feed.ts +++ b/lib/create-feed.ts @@ -1,32 +1,32 @@ import { assert, createUrl, groupByToMap, keyByToMap } from "@acdh-oeaw/lib"; import { getFormatter } from "next-intl/server"; -import { renderToStaticMarkup } from "react-dom/server"; +// import { renderToStaticMarkup } from "react-dom/server"; import { type Entry, rss } from "xast-util-feed"; import { toXml } from "xast-util-to-xml"; import { env } from "@/config/env.config"; -import { locales } from "@/config/i18n.config"; -import { getResourceContent } from "@/lib/content/mdx"; +import type { Locale } from "@/config/i18n.config"; +// import { getResourceContent } from "@/lib/content/mdx"; import { reader } from "@/lib/content/reader"; const baseUrl = env.NEXT_PUBLIC_APP_BASE_URL; -const resources = await reader().collections.resources.all(); -const resourcesByLocale = groupByToMap(resources, (resource) => { - return resource.entry.locale; -}); +export async function createFeed(locale: Locale) { + const allResources = await reader().collections.resources.all(); + const resourcesByLocale = groupByToMap(allResources, (resource) => { + return resource.entry.locale; + }); -const people = await reader().collections.people.all(); -const peopleById = keyByToMap(people, (person) => { - return person.slug; -}); + const allPeople = await reader().collections.people.all(); + const peopleById = keyByToMap(allPeople, (person) => { + return person.slug; + }); -const tags = await reader().collections.tags.all(); -const tagsById = keyByToMap(tags, (tag) => { - return tag.slug; -}); + const allTags = await reader().collections.tags.all(); + const tagsById = keyByToMap(allTags, (tag) => { + return tag.slug; + }); -for (const locale of locales) { const { list } = await getFormatter({ locale }); const channel = { @@ -42,8 +42,8 @@ for (const locale of locales) { const data: Array = []; for (const resource of resources) { - const { Content } = await getResourceContent(resource.slug); - const html = renderToStaticMarkup(Content({})); + // const { Content } = await getResourceContent(resource.slug); + // const html = renderToStaticMarkup(Content({})); data.push({ title: resource.entry.title, @@ -66,4 +66,6 @@ for (const locale of locales) { } const feed = toXml(rss(channel, data)); + + return feed; }