mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-05-15 17:34:28 -04:00
trim some unnecessary dependencies
This commit is contained in:
@@ -3,6 +3,7 @@ import { Feed } from "feed";
|
||||
import { getFrontMatter, getContent } from "./posts";
|
||||
import * as config from "../config";
|
||||
import { BASE_URL } from "../config/constants";
|
||||
import type { Item as FeedItem } from "feed";
|
||||
|
||||
import ogImage from "../../app/opengraph-image.jpg";
|
||||
|
||||
@@ -30,10 +31,10 @@ export const buildFeed = cache(async (): Promise<Feed> => {
|
||||
},
|
||||
});
|
||||
|
||||
// add posts separately using their frontmatter
|
||||
const posts = await getFrontMatter();
|
||||
for (const post of posts) {
|
||||
feed.addItem({
|
||||
// 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,
|
||||
@@ -49,8 +50,16 @@ export const buildFeed = cache(async (): Promise<Feed> => {
|
||||
${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;
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { cache } from "react";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import glob from "fast-glob";
|
||||
import { unified } from "unified";
|
||||
import { read } from "to-vfile";
|
||||
import { remarkHtml, remarkParse, remarkSmartypants, remarkFrontmatter } from "./remark-rehype-plugins";
|
||||
import { decode } from "html-entities";
|
||||
import { BASE_URL, POSTS_DIR } from "../config/constants";
|
||||
@@ -130,7 +130,7 @@ export const getContent = cache(async (slug: string): Promise<string | undefined
|
||||
],
|
||||
},
|
||||
})
|
||||
.process(await read(path.resolve(process.cwd(), `${POSTS_DIR}/${slug}/index.mdx`)));
|
||||
.process(await fs.readFile(path.resolve(process.cwd(), `${POSTS_DIR}/${slug}/index.mdx`)));
|
||||
|
||||
// convert the parsed content to a string with "safe" HTML
|
||||
return content.toString().replaceAll("<p></p>", "").trim();
|
||||
|
||||
Reference in New Issue
Block a user