Skip to content

Commit 73680b1

Browse files
committed
some more stuff
1 parent 8f1b039 commit 73680b1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/mdx.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {cache} from 'react';
21
import matter from 'gray-matter';
32
import {s} from 'hastscript';
43
import yaml from 'js-yaml';
@@ -666,6 +665,7 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
666665

667666
await cp(assetsCacheDir, outdir, {
668667
recursive: true,
668+
errorOnExist: false,
669669
force: true,
670670
});
671671
writeCacheFile(cacheFile, JSON.stringify(resultObj)).catch(e => {
@@ -676,9 +676,19 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
676676
return resultObj;
677677
}
678678

679+
const fileBySlugCache = new Map<string, Promise<SlugFile>>();
680+
679681
/**
680682
* Cache the result of {@link getFileBySlug}.
681683
*
682684
* This is useful for performance when rendering the same file multiple times.
683685
*/
684-
export const getFileBySlugWithCache = cache(getFileBySlug);
686+
export function getFileBySlugWithCache(slug: string): Promise<SlugFile> {
687+
let cached = fileBySlugCache.get(slug);
688+
if (!cached) {
689+
cached = getFileBySlug(slug);
690+
fileBySlugCache.set(slug, cached);
691+
}
692+
693+
return cached;
694+
}

0 commit comments

Comments
 (0)