Skip to content

Commit

Permalink
feat: add route handler
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst committed Mar 17, 2024
1 parent 3d4bbfe commit 0f7285b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
7 changes: 7 additions & 0 deletions app/rss.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createFeed } from "@/lib/create-feed";

export async function GET(): Promise<Response> {
const feed = await createFeed("en");

return new Response(feed, { headers: { "content-type": "application/xml" } });
}
13 changes: 10 additions & 3 deletions components/app-header.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { MenuIcon } from "lucide-react";
import { useTranslations } from "next-intl";

import { AppNavLink } from "@/components/app-nav-link";
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() {
Expand All @@ -18,8 +20,8 @@ export function AppHeader() {

return (
<header className="border-b">
<div className="container flex max-w-screen-md items-center justify-between gap-x-4 border-x bg-neutral-0 py-6 dark:bg-neutral-900">
<nav aria-label={t("navigation-primary")}>
<div className="container flex max-w-screen-md items-center justify-between gap-x-4 border-x bg-neutral-0 py-3 xs:py-6 dark:bg-neutral-900">
<nav aria-label={t("navigation-primary")} className="hidden xs:block">
<ul className="-ml-3 flex items-center gap-x-2 text-sm font-medium" role="list">
{Object.entries(links).map(([id, link]) => {
if (id === "home") {
Expand All @@ -42,9 +44,14 @@ export function AppHeader() {
</ul>
</nav>

<div className="-mr-1 flex items-center gap-x-2">
<div className="-mr-1 ml-auto flex items-center gap-x-2">
<ColorSchemeSwitcher />
<LocaleSwitcher />
<nav aria-label={t("navigation-primary")} className="block xs:hidden">
<IconButton variant="plain">
<MenuIcon className="size-5 shrink-0" />
</IconButton>
</nav>
</div>
</div>
</header>
Expand Down
38 changes: 20 additions & 18 deletions lib/feed.ts → lib/create-feed.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -42,8 +42,8 @@ for (const locale of locales) {
const data: Array<Entry> = [];

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,
Expand All @@ -66,4 +66,6 @@ for (const locale of locales) {
}

const feed = toXml(rss(channel, data));

return feed;
}

0 comments on commit 0f7285b

Please sign in to comment.