1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-05 20:15:31 -04:00
Files
jarv.is/lib/build-feed.ts
T
jake 5a1636baa3 refactor: migrate from Biome to oxlint/oxfmt, remove contact form
- Replace Biome with oxlint + oxfmt (OXC toolchain) for linting and formatting
- Add .oxlintrc.json and .oxfmtrc.json configuration files
- Update VS Code settings and devcontainer to use oxc-vscode extension
- Remove contact form, Resend email integration, and related server action/schema
- Remove unused UI components (accordion, alert, card, tabs, toggle, etc.)
2026-04-05 19:45:18 -04:00

64 lines
2.0 KiB
TypeScript

import { Feed, type Item as FeedItem } from "feed";
import ogImage from "@/app/opengraph-image.jpg";
import authorConfig from "@/lib/config/author";
import siteConfig from "@/lib/config/site";
import { getContent, getFrontMatter } from "@/lib/posts";
/**
* Returns a `Feed` object, which can then be processed with `feed.rss2()`, `feed.atom1()`, or `feed.json1()`.
* @see https://github.com/jpmonette/feed#example
*/
export const buildFeed = async (): Promise<Feed> => {
const feed = new Feed({
id: `${process.env.NEXT_PUBLIC_BASE_URL}`,
link: `${process.env.NEXT_PUBLIC_BASE_URL}`,
title: siteConfig.name,
description: siteConfig.description,
copyright: `https://spdx.org/licenses/${siteConfig.license}.html`,
updated: new Date(),
image: `${process.env.NEXT_PUBLIC_BASE_URL}${ogImage.src}`,
feedLinks: {
rss: `${process.env.NEXT_PUBLIC_BASE_URL}/feed.xml`,
atom: `${process.env.NEXT_PUBLIC_BASE_URL}/feed.atom`,
},
author: {
name: authorConfig.name,
link: process.env.NEXT_PUBLIC_BASE_URL,
email: authorConfig.email,
},
});
// parse posts into feed items
const frontmatter = await getFrontMatter();
const posts: FeedItem[] = await Promise.all(
frontmatter.map(async (post) => ({
guid: post.permalink,
link: post.permalink,
title: post.title,
description: post.description,
author: [
{
name: authorConfig.name,
link: `${process.env.NEXT_PUBLIC_BASE_URL}`,
},
],
date: new Date(post.date),
content: `
${await getContent(post.slug)}
<p><a href="${post.permalink}"><strong>Continue reading...</strong></a></p>
`.trim(),
})),
);
// sort posts reverse chronologically in case the promises resolved out of order
posts.sort((post1, post2) => new Date(post2.date).getTime() - new Date(post1.date).getTime());
// officially add each post to the feed
posts.forEach((post) => {
feed.addItem(post);
});
return feed;
};