-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy path[page].paths.ts
More file actions
51 lines (48 loc) · 1.61 KB
/
Copy path[page].paths.ts
File metadata and controls
51 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as fs from "node:fs";
import * as path from "node:path";
const SPHINX_BUILD_OUTPUT = path.join(
__dirname,
"../../../python/pysail/docs/_build",
);
export default {
async paths() {
const entries = await fs.promises.readdir(SPHINX_BUILD_OUTPUT, {
withFileTypes: true,
recursive: true,
});
const files = entries.filter(
(entry) => entry.isFile() && entry.name.endsWith(".fjson"),
);
const paths = await Promise.all(
files.map(async (entry) => {
if (entry.name === "search.fjson" || entry.name === "genindex.fjson") {
return null;
}
const file = path.join(entry.parentPath, entry.name);
const content = await fs.promises.readFile(file, "utf-8");
const data = JSON.parse(content);
const page = path
.relative(SPHINX_BUILD_OUTPUT, file)
.replace(/^index\.fjson$/, "/index")
.replace(/[/\\]index\.fjson$/, "/index")
// We must turn non-index pages into directories, since Sphinx handles URL in this way
// in `JSONHTMLBuilder`, which may generate relative URLs containing `../` may appear in the HTML.
.replace(/\.fjson$/, "/index");
return {
params: {
sphinx: true,
page,
prev: data.prev
? { link: data.prev.link, text: data.prev.title }
: false,
next: data.next
? { link: data.next.link, text: data.next.title }
: false,
},
content: data.body,
};
}),
);
return paths.filter((path) => path !== null);
},
};