accept-md-runtime 1.0.3 → 1.0.5
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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/templates.d.ts +1 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +4 -1
- package/dist/templates.js.map +1 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 accept-md contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Fetches the given path as HTML from your app, converts it to markdown, and retur
|
|
|
27
27
|
```ts
|
|
28
28
|
import { getMarkdownForPath } from 'accept-md-runtime';
|
|
29
29
|
|
|
30
|
-
// App Router: app/api/accept-md/route.ts
|
|
30
|
+
// App Router: app/api/accept-md/route.js (or route.ts)
|
|
31
31
|
export async function GET(req: Request) {
|
|
32
32
|
const path = new URL(req.url).searchParams.get('path') ?? '/';
|
|
33
33
|
const markdown = await getMarkdownForPath(req, path);
|
package/dist/templates.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Generated middleware and route handler templates.
|
|
3
3
|
*/
|
|
4
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
|
|
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\nexport async function GET(request) {\n const pathFromQuery = request.nextUrl.searchParams.get('path');\n const pathname = request.nextUrl.pathname;\n const path = 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\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,kuBAkB/B,CAAC;AAEF,eAAO,MAAM,0BAA0B,
|
|
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,sqCAiCtC,CAAC;AAEF,eAAO,MAAM,0BAA0B,smCA+BtC,CAAC"}
|
package/dist/templates.js
CHANGED
|
@@ -25,9 +25,12 @@ import { NextResponse } from 'next/server';
|
|
|
25
25
|
import { getMarkdownForPath, loadConfig } from 'accept-md-runtime';
|
|
26
26
|
|
|
27
27
|
const cache = new Map();
|
|
28
|
+
const HANDLER_PATH = '/api/accept-md';
|
|
28
29
|
|
|
29
30
|
export async function GET(request) {
|
|
30
|
-
const
|
|
31
|
+
const pathFromQuery = request.nextUrl.searchParams.get('path');
|
|
32
|
+
const pathname = request.nextUrl.pathname;
|
|
33
|
+
const path = pathFromQuery ?? (pathname !== HANDLER_PATH ? pathname : null) ?? '/';
|
|
31
34
|
const config = loadConfig(process.cwd());
|
|
32
35
|
const baseUrl = config.baseUrl || request.nextUrl.origin;
|
|
33
36
|
try {
|
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;;;;;;;;;;;;;;;;;;CAkBlC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCzC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BzC,CAAC"}
|