accept-md-runtime 1.0.2 → 1.0.3
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 +2 -2
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +3 -5
- package/dist/templates.js.map +1 -1
- package/package.json +4 -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';\
|
|
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
|
|
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 = /\\\\btext\\\\/markdown\\\\b/;\nconst EXCLUDED_PREFIXES = ['/api/', '/_next/'];\nconst MARKDOWN_HANDLER_PATH = '/api/accept-md';\n\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 return NextResponse.rewrite(url);\n}\n";
|
|
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();\n\nexport async function GET(request) {\n const path = request.nextUrl.searchParams.get('path') || '/';\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\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 path = req.query.path || '/';\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,kuBAkB/B,CAAC;AAEF,eAAO,MAAM,0BAA0B,u/BA8BtC,CAAC;AAEF,eAAO,MAAM,0BAA0B,smCA+BtC,CAAC"}
|
package/dist/templates.js
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
*/
|
|
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
|
-
import type { NextRequest } from 'next/server';
|
|
7
6
|
|
|
8
7
|
const MARKDOWN_ACCEPT = /\\\\btext\\\\/markdown\\\\b/;
|
|
9
8
|
const EXCLUDED_PREFIXES = ['/api/', '/_next/'];
|
|
10
9
|
const MARKDOWN_HANDLER_PATH = '/api/accept-md';
|
|
11
10
|
|
|
12
|
-
export function middleware(request
|
|
11
|
+
export function middleware(request) {
|
|
13
12
|
const pathname = request.nextUrl.pathname;
|
|
14
13
|
const accept = request.headers.get('accept') || '';
|
|
15
14
|
if (!MARKDOWN_ACCEPT.test(accept)) return NextResponse.next();
|
|
@@ -23,12 +22,11 @@ export function middleware(request: NextRequest) {
|
|
|
23
22
|
`;
|
|
24
23
|
export const APP_ROUTE_HANDLER_TEMPLATE = `// Generated by accept-md. Do not edit the markdown block by hand.
|
|
25
24
|
import { NextResponse } from 'next/server';
|
|
26
|
-
import type { NextRequest } from 'next/server';
|
|
27
25
|
import { getMarkdownForPath, loadConfig } from 'accept-md-runtime';
|
|
28
26
|
|
|
29
|
-
const cache = new Map
|
|
27
|
+
const cache = new Map();
|
|
30
28
|
|
|
31
|
-
export async function GET(request
|
|
29
|
+
export async function GET(request) {
|
|
32
30
|
const path = request.nextUrl.searchParams.get('path') || '/';
|
|
33
31
|
const config = loadConfig(process.cwd());
|
|
34
32
|
const baseUrl = config.baseUrl || request.nextUrl.origin;
|
package/dist/templates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;CAkBlC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BzC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accept-md-runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "HTML→Markdown conversion and route handler for accept-md (Next.js)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
7
10
|
"publishConfig": {
|
|
8
11
|
"access": "public"
|
|
9
12
|
},
|