feat(site): add markdown content negotiation via Netlify edge function (#573)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Darius Cepulis
2026-02-19 08:39:56 -06:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 38b3a8f55c
commit 52d20bfca8
3 changed files with 34 additions and 1 deletions
+4 -1
View File
@@ -529,6 +529,9 @@ importers:
'@astrojs/check':
specifier: ^0.9.6
version: 0.9.6(prettier@3.8.1)(typescript@5.9.3)
'@netlify/edge-functions':
specifier: ^3.0.3
version: 3.0.3
'@testing-library/jest-dom':
specifier: ^6.9.1
version: 6.9.1
@@ -6323,7 +6326,7 @@ packages:
tar@7.5.2:
resolution: {integrity: sha512-7NyxrTE4Anh8km8iEy7o0QYPs+0JKBTj5ZaqHg6B39erLg0qYXN3BijtShwbsNSvQ+LN75+KV+C4QR/f6Gwnpg==}
engines: {node: '>=18'}
deprecated: Old versions of tar are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me
deprecated: Old versions of tar are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exhorbitant rates) by contacting i@izs.me
tar@7.5.7:
resolution: {integrity: sha512-fov56fJiRuThVFXD6o6/Q354S7pnWMJIVlDBYijsTNx6jKSE4pvrDTs6lUnmGvNyfJwFQQwWy3owKz1ucIhveQ==}
@@ -0,0 +1,29 @@
import type { Config, Context } from '@netlify/edge-functions';
export default async (request: Request, context: Context) => {
const url = new URL(request.url);
const path = url.pathname.replace(/\/$/, '');
// Fetch the pre-built .md file from static assets
const mdResponse = await fetch(new URL(`${path}.md`, request.url));
if (!mdResponse.ok) return;
const body = await mdResponse.text();
const headers = new Headers();
headers.set('content-type', 'text/markdown; charset=utf-8');
headers.set('cache-control', 'public, s-maxage=31536000');
headers.set('vary', 'Accept');
headers.set('x-markdown-tokens', String(Math.ceil(body.length / 4)));
return new Response(body, { status: 200, headers });
};
export const config: Config = {
// https://docs.netlify.com/build/edge-functions/optional-configuration/#caching
cache: 'manual',
path: ['/blog/*', '/docs/*'],
header: {
accept: 'text/markdown',
},
};
+1
View File
@@ -56,6 +56,7 @@
},
"devDependencies": {
"@astrojs/check": "^0.9.6",
"@netlify/edge-functions": "^3.0.3",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",