1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-16 19:45:33 -04:00

try memoizing front matter parsing

This commit is contained in:
2022-07-18 17:39:55 -04:00
parent a788f673e9
commit a9f3bf2974
5 changed files with 416 additions and 404 deletions

View File

@@ -5,6 +5,7 @@ import matter from "gray-matter";
import { marked } from "marked";
import removeMarkdown from "remove-markdown";
import pMap from "p-map";
import pMemoize from "p-memoize";
import { formatDate } from "./format-date";
import { baseUrl } from "../config";
import { NOTES_DIR } from "../config/constants";
@@ -55,7 +56,7 @@ export const getNoteData = async (
};
// returns the parsed front matter of ALL notes, sorted reverse chronologically
export const getAllNotes = async (): Promise<NoteFrontMatter[]> => {
export const getAllNotes = pMemoize(async (): Promise<NoteFrontMatter[]> => {
const slugs = await getNoteSlugs();
// for each slug, query its front matter
@@ -65,4 +66,4 @@ export const getAllNotes = async (): Promise<NoteFrontMatter[]> => {
data.sort((note1, note2) => (note1.date > note2.date ? -1 : 1));
return data;
};
});