From 90524606043100978a80e1a725e6ec866e778e29 Mon Sep 17 00:00:00 2001 From: Yasutake Yohei Date: Sat, 4 Jul 2026 23:28:35 +0900 Subject: og画像: キャッシュをnode_modules/.og-cacheに移動しビルド間で保持 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/og/[slug].png.ts | 12 ++++++------ 1 file 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 = {}; 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)); -- cgit v1.3.1