diff --git a/apps/docs/app/api/guides-md/[...slug]/route.ts b/apps/docs/app/api/guides-md/[...slug]/route.ts index f09a7854f25..b942ff2f73c 100644 --- a/apps/docs/app/api/guides-md/[...slug]/route.ts +++ b/apps/docs/app/api/guides-md/[...slug]/route.ts @@ -14,7 +14,10 @@ export async function GET(_request: Request, { params }: { params: Promise<{ slu try { const content = await fs.readFile(filePath, 'utf-8') return new NextResponse(content, { - headers: { 'Content-Type': 'text/markdown; charset=utf-8' }, + headers: { + 'Content-Type': 'text/markdown; charset=utf-8', + 'Cache-Control': 'public, max-age=86400, stale-while-revalidate=3600', + }, }) } catch { return new NextResponse('Not found', { status: 404 }) diff --git a/apps/docs/components/GuidesSidebar.tsx b/apps/docs/components/GuidesSidebar.tsx index 7945943892a..544efe3fe2f 100644 --- a/apps/docs/components/GuidesSidebar.tsx +++ b/apps/docs/components/GuidesSidebar.tsx @@ -30,7 +30,15 @@ function AiTools({ className }: { className?: string }) { try { const res = await fetch(mdUrl) - const text = await res.text() + let text: string + + if (res.ok) { + text = await res.text() + } else { + // Default to HTML content within the article when no .md file is available. + text = document.getElementById('sb-docs-guide-main-article')?.innerHTML ?? '' + } + await navigator.clipboard.writeText(text) setCopied(true) setTimeout(() => setCopied(false), 2000)