accept-md-runtime 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/templates.d.ts +1 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +2 -2
- package/package.json +1 -1
package/dist/templates.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generated middleware and route handler templates.
|
|
3
3
|
*/
|
|
4
|
-
export declare const MIDDLEWARE_TEMPLATE = "// Generated by accept-md. Do not edit the markdown block by hand.\nimport { NextResponse } from 'next/server';\n\nconst MARKDOWN_ACCEPT = new RegExp('\\\\\\\\btext/markdown\\\\\\\\b');\nconst EXCLUDED_PREFIXES = ['/api/', '/_next/'];\nconst MARKDOWN_HANDLER_PATH = '/api/accept-md';\n\n/** @param {import('next/server').NextRequest} request */\nexport function middleware(request) {\n const pathname = request.nextUrl.pathname;\n const accept = request.headers.get('accept') || '';\n if (!MARKDOWN_ACCEPT.test(accept)) return NextResponse.next();\n if (EXCLUDED_PREFIXES.some((p) => pathname.startsWith(p))) return NextResponse.next();\n\n const url = request.nextUrl.clone();\n url.pathname = MARKDOWN_HANDLER_PATH;\n url.searchParams.set('path', pathname);\n const requestHeaders = new Headers(request.headers);\n requestHeaders.set('x-accept-md-path', pathname);\n return NextResponse.rewrite(url, { request: { headers: requestHeaders } });\n}\n";
|
|
4
|
+
export declare const MIDDLEWARE_TEMPLATE = "// Generated by accept-md. Do not edit the markdown block by hand.\nimport { NextResponse } from 'next/server';\n\nconst MARKDOWN_ACCEPT = new RegExp('\\\\\\\\btext/markdown\\\\\\\\b', 'i');\nconst EXCLUDED_PREFIXES = ['/api/', '/_next/'];\nconst MARKDOWN_HANDLER_PATH = '/api/accept-md';\n\n/** @param {import('next/server').NextRequest} request */\nexport function middleware(request) {\n const pathname = request.nextUrl.pathname;\n const accept = (request.headers.get('accept') || '').toLowerCase();\n if (!MARKDOWN_ACCEPT.test(accept)) return NextResponse.next();\n if (EXCLUDED_PREFIXES.some((p) => pathname.startsWith(p))) return NextResponse.next();\n\n const url = request.nextUrl.clone();\n url.pathname = MARKDOWN_HANDLER_PATH;\n url.searchParams.set('path', pathname);\n const requestHeaders = new Headers(request.headers);\n requestHeaders.set('x-accept-md-path', pathname);\n return NextResponse.rewrite(url, { request: { headers: requestHeaders } });\n}\n";
|
|
5
5
|
export declare const APP_ROUTE_HANDLER_TEMPLATE = "// Generated by accept-md. Do not edit the markdown block by hand.\nimport { NextResponse } from 'next/server';\nimport { getMarkdownForPath, loadConfig } from 'accept-md-runtime';\n\nconst cache = new Map();\nconst HANDLER_PATH = '/api/accept-md';\n\n/** @param {import('next/server').NextRequest} request */\nexport async function GET(request) {\n const pathFromHeader = request.headers.get('x-accept-md-path');\n const pathFromQuery = request.nextUrl.searchParams.get('path');\n const pathname = request.nextUrl.pathname;\n const path = pathFromHeader ?? pathFromQuery ?? (pathname !== HANDLER_PATH ? pathname : null) ?? '/';\n const config = loadConfig(process.cwd());\n const baseUrl = config.baseUrl || request.nextUrl.origin;\n try {\n const markdown = await getMarkdownForPath({\n pathname: path,\n baseUrl,\n config,\n cache: config.cache !== false ? cache : undefined,\n });\n return new NextResponse(markdown, {\n headers: {\n 'Content-Type': 'text/markdown; charset=utf-8',\n 'Cache-Control': config.cache ? 'public, s-maxage=60, stale-while-revalidate' : 'no-store',\n },\n });\n } catch (err) {\n return NextResponse.json(\n { error: err instanceof Error ? err.message : 'Markdown generation failed' },\n { status: 500 }\n );\n }\n}\n";
|
|
6
6
|
export declare const PAGES_API_HANDLER_TEMPLATE = "// Generated by accept-md. Do not edit the markdown block by hand.\nimport { getMarkdownForPath, loadConfig } from 'accept-md-runtime';\n\nconst cache = new Map();\n\n/** @param {import('next').NextApiRequest} req @param {import('next').NextApiResponse} res */\nexport default async function handler(req, res) {\n if (req.method !== 'GET') {\n res.setHeader('Allow', 'GET');\n return res.status(405).end();\n }\n const pathFromHeader = req.headers['x-accept-md-path'];\n const pathFromQuery = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;\n const pathRaw = (pathFromHeader || pathFromQuery) || '/';\n const path = typeof pathRaw === 'string' ? pathRaw : (pathRaw[0] || '/');\n const config = loadConfig(process.cwd());\n const baseUrl = config.baseUrl || (req.headers.origin || req.headers.referer || '').replace(/\\\\/?$/, '') || ('http://localhost:' + (process.env.PORT || 3000));\n try {\n const markdown = await getMarkdownForPath({\n pathname: path,\n baseUrl,\n config,\n cache: config.cache !== false ? cache : undefined,\n });\n res.setHeader('Content-Type', 'text/markdown; charset=utf-8');\n if (config.cache) {\n res.setHeader('Cache-Control', 'public, s-maxage=60, stale-while-revalidate');\n }\n res.status(200).send(markdown);\n } catch (err) {\n res.status(500).json({\n error: err instanceof Error ? err.message : 'Markdown generation failed',\n });\n }\n}\n";
|
|
7
7
|
//# sourceMappingURL=templates.d.ts.map
|
package/dist/templates.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,mBAAmB,y9BAqB/B,CAAC;AAEF,eAAO,MAAM,0BAA0B,szCAmCtC,CAAC;AAEF,eAAO,MAAM,0BAA0B,g8CAmCtC,CAAC"}
|
package/dist/templates.js
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
export const MIDDLEWARE_TEMPLATE = `// Generated by accept-md. Do not edit the markdown block by hand.
|
|
5
5
|
import { NextResponse } from 'next/server';
|
|
6
6
|
|
|
7
|
-
const MARKDOWN_ACCEPT = new RegExp('\\\\\\\\btext/markdown\\\\\\\\b');
|
|
7
|
+
const MARKDOWN_ACCEPT = new RegExp('\\\\\\\\btext/markdown\\\\\\\\b', 'i');
|
|
8
8
|
const EXCLUDED_PREFIXES = ['/api/', '/_next/'];
|
|
9
9
|
const MARKDOWN_HANDLER_PATH = '/api/accept-md';
|
|
10
10
|
|
|
11
11
|
/** @param {import('next/server').NextRequest} request */
|
|
12
12
|
export function middleware(request) {
|
|
13
13
|
const pathname = request.nextUrl.pathname;
|
|
14
|
-
const accept = request.headers.get('accept') || '';
|
|
14
|
+
const accept = (request.headers.get('accept') || '').toLowerCase();
|
|
15
15
|
if (!MARKDOWN_ACCEPT.test(accept)) return NextResponse.next();
|
|
16
16
|
if (EXCLUDED_PREFIXES.some((p) => pathname.startsWith(p))) return NextResponse.next();
|
|
17
17
|
|