diff options
| -rw-r--r-- | src/pages/og/[slug].png.ts | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/pages/og/[slug].png.ts b/src/pages/og/[slug].png.ts index 1047647..a743efe 100644 --- a/src/pages/og/[slug].png.ts +++ b/src/pages/og/[slug].png.ts @@ -142,10 +142,10 @@ export async function GET({ params }: { params: { slug: string } }) { title = `${reiwa}${month}定例会`; } - // Check cache: if title hash matches, return cached PNG - const distDir = path.join(process.cwd(), "dist", "og"); - const cacheFile = path.join(distDir, `${slug}.png`); - const cacheJsonPath = path.join(distDir, ".og-cache.json"); + // Check cache: if title hash matches, return cached PNG from node_modules/.og-cache + const cacheDir = path.join(process.cwd(), "node_modules", ".og-cache"); + const cacheFile = path.join(cacheDir, `${slug}.png`); + const cacheJsonPath = path.join(cacheDir, ".og-cache.json"); let cache: Record<string, string> = {}; if (existsSync(cacheJsonPath)) { @@ -293,8 +293,8 @@ export async function GET({ params }: { params: { slug: string } }) { const resvg = new Resvg(svg, { fitTo: { mode: "width", value: 1200 } }); const pngBuffer = resvg.render().asPng(); - // Save to cache - if (!existsSync(distDir)) mkdirSync(distDir, { recursive: true }); + // Save to cache in node_modules/.og-cache (persists across builds) + if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true }); writeFileSync(cacheFile, pngBuffer); cache[slug] = titleHash; writeFileSync(cacheJsonPath, JSON.stringify(cache, null, 2)); |
