1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-05-15 19:54:27 -04:00

refactor note processing functions

This commit is contained in:
2025-03-28 09:22:04 -04:00
parent 2d42a7447e
commit 264fd92379
7 changed files with 96 additions and 69 deletions
+11 -5
View File
@@ -1,13 +1,16 @@
import { cache } from "react";
import { Feed } from "feed";
import { getAllPosts, getPostContent } from "./posts";
import { getFrontMatter, getContent } from "./posts";
import * as config from "../config";
import { BASE_URL } from "../config/constants";
import ogImage from "../../app/opengraph-image.jpg";
/**
* 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 = cache(async (): Promise<Feed> => {
// https://github.com/jpmonette/feed#example
const feed = new Feed({
id: BASE_URL,
link: BASE_URL,
@@ -28,8 +31,8 @@ export const buildFeed = cache(async (): Promise<Feed> => {
});
// add posts separately using their frontmatter
const posts = await getAllPosts();
for (const post of posts.reverse()) {
const posts = await getFrontMatter();
for (const post of posts) {
feed.addItem({
guid: post.permalink,
link: post.permalink,
@@ -42,7 +45,10 @@ export const buildFeed = cache(async (): Promise<Feed> => {
},
],
date: new Date(post.date),
content: `${await getPostContent(post.slug)}\n\n<p><a href="${post.permalink}"><strong>Continue reading...</strong></a></p>`,
content: `
${await getContent(post.slug)}
<p><a href="${post.permalink}"><strong>Continue reading...</strong></a></p>
`.trim(),
});
}