@mintlify/previewing 4.0.1504 → 4.0.1506
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/__tests__/export-assets.test.d.ts +1 -0
- package/dist/__tests__/export-assets.test.js +144 -0
- package/dist/__tests__/export-fetch.test.d.ts +1 -0
- package/dist/__tests__/export-fetch.test.js +81 -0
- package/dist/__tests__/export.test.js +19 -1
- package/dist/local-preview/export-assets.d.ts +8 -0
- package/dist/local-preview/export-assets.js +135 -0
- package/dist/local-preview/export-fetch.d.ts +12 -0
- package/dist/local-preview/export-fetch.js +55 -0
- package/dist/local-preview/export-llms.d.ts +1 -0
- package/dist/local-preview/export-llms.js +39 -0
- package/dist/local-preview/export.d.ts +1 -0
- package/dist/local-preview/export.js +39 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/export-scripts/README.md +15 -0
- package/export-scripts/serve.js +21 -2
- package/package.json +6 -6
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Exported documentation
|
|
2
|
+
|
|
3
|
+
## View locally
|
|
4
|
+
|
|
5
|
+
Run `node serve.js` (or double-click `Start Docs.command` on macOS, `Start Docs.bat` on Windows) and open `http://localhost:3000`. Requires Node.js.
|
|
6
|
+
|
|
7
|
+
## Host on your own server
|
|
8
|
+
|
|
9
|
+
Serve this folder as static files with these rules:
|
|
10
|
+
|
|
11
|
+
1. **Pages:** a request for `/<path>` serves `<path>/index.html`.
|
|
12
|
+
2. **Client-side navigation:** a request with an `RSC: 1` header or an `_rsc` query parameter serves `<path>/index.txt` with `Content-Type: text/x-component` and `Vary: RSC`. Without this rule, every link click is a full page load and link prefetches download whole HTML pages.
|
|
13
|
+
3. **Caching:** serve `_next/static/*` and `_mintlify/export-assets/*` with `Cache-Control: public, max-age=31536000, immutable`, and pages and `index.txt` files with `Cache-Control: no-cache`.
|
|
14
|
+
|
|
15
|
+
`serve.js` implements all three rules and can be used as a reference.
|
package/export-scripts/serve.js
CHANGED
|
@@ -8,6 +8,8 @@ const { execFile } = require('child_process');
|
|
|
8
8
|
const PORT = process.env.PORT || 3000;
|
|
9
9
|
const DIR = __dirname;
|
|
10
10
|
|
|
11
|
+
const IMMUTABLE_PATH = /^\/(?:_next\/static|_mintlify\/assets|_mintlify\/export-assets)\//;
|
|
12
|
+
|
|
11
13
|
const MIME_TYPES = {
|
|
12
14
|
'.html': 'text/html',
|
|
13
15
|
'.css': 'text/css',
|
|
@@ -45,6 +47,16 @@ function openInBrowser(url) {
|
|
|
45
47
|
execFile(command, [url], () => undefined);
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
function resolveRscPayload(urlPath) {
|
|
51
|
+
const filePath = path.resolve(DIR, urlPath.replace(/^\/+/, ''), 'index.txt');
|
|
52
|
+
if (!filePath.startsWith(DIR + path.sep)) return undefined;
|
|
53
|
+
return fs.existsSync(filePath) && fs.statSync(filePath).isFile() ? filePath : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isRscRequest(req) {
|
|
57
|
+
return req.headers.rsc === '1' || /[?&]_rsc=/.test(req.url || '');
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
function resolveFile(urlPath) {
|
|
49
61
|
const filePath = path.resolve(DIR, urlPath.replace(/^\/+/, ''));
|
|
50
62
|
if (!filePath.startsWith(DIR + path.sep) && filePath !== DIR) return undefined;
|
|
@@ -64,11 +76,18 @@ http
|
|
|
64
76
|
return;
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
const
|
|
79
|
+
const rsc = isRscRequest(req);
|
|
80
|
+
const file = rsc ? resolveRscPayload(urlPath) : resolveFile(urlPath);
|
|
68
81
|
|
|
69
82
|
if (file) {
|
|
70
83
|
const ext = path.extname(file).toLowerCase();
|
|
71
|
-
res.writeHead(200, {
|
|
84
|
+
res.writeHead(200, {
|
|
85
|
+
'Content-Type': rsc ? 'text/x-component' : MIME_TYPES[ext] || 'application/octet-stream',
|
|
86
|
+
Vary: 'RSC',
|
|
87
|
+
'Cache-Control': IMMUTABLE_PATH.test(urlPath)
|
|
88
|
+
? 'public, max-age=31536000, immutable'
|
|
89
|
+
: 'no-cache',
|
|
90
|
+
});
|
|
72
91
|
fs.createReadStream(file).pipe(res);
|
|
73
92
|
} else {
|
|
74
93
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/previewing",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1506",
|
|
4
4
|
"description": "Preview Mintlify docs locally",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"type": "tsgo --noEmit"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@mintlify/common": "1.0.
|
|
48
|
-
"@mintlify/prebuild": "1.0.
|
|
49
|
-
"@mintlify/validation": "0.1.
|
|
47
|
+
"@mintlify/common": "1.0.1265",
|
|
48
|
+
"@mintlify/prebuild": "1.0.1430",
|
|
49
|
+
"@mintlify/validation": "0.1.925",
|
|
50
50
|
"adm-zip": "0.6.0",
|
|
51
51
|
"better-opn": "3.0.2",
|
|
52
52
|
"chalk": "5.2.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"yargs": "17.7.1"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@mintlify/package-builder": "0.0.
|
|
67
|
+
"@mintlify/package-builder": "0.0.53"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@mintlify/models": "0.0.375",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"vitest": "2.1.9",
|
|
87
87
|
"vitest-mock-process": "1.0.4"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "afa4e5cf775b14bcf04e830cdde309bfc728f439"
|
|
90
90
|
}
|