Skip to content

Commit f4b2eb5

Browse files
authored
Add Python documentation (#123)
1 parent f99324c commit f4b2eb5

19 files changed

Lines changed: 434 additions & 135 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ You need Node.js to build the documentation.
1111

1212
On macOS, you can install rustup and the Node.js runtime via Homebrew.
1313

14+
<!-- TODO: make it clear that the following is an alternative way to install rustup -->
15+
1416
```bash
1517
brew install rustup
1618
brew install node
@@ -33,6 +35,8 @@ You also need the following tools when working on the project.
3335

3436
On macOS, you can install these tools via Homebrew.
3537

38+
<!-- TODO: investigate if we can install Maturin locally -->
39+
3640
```bash
3741
brew install protobuf hatch maturin zig pnpm
3842
```

docs/.vitepress/config.mts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function analyticsHead(): HeadConfig[] {
3636
export default async () => {
3737
return defineConfig({
3838
base: siteBase(),
39-
lastUpdated: true,
4039
lang: "en-US",
4140
title: headTitle,
4241
description: headDescription,
@@ -52,7 +51,10 @@ export default async () => {
5251
["meta", { property: "og:image", content: headImage }],
5352
["meta", { property: "og:type", content: "website" }],
5453
["meta", { property: "og:site_name", content: "Sail documentation" }],
55-
['link', { rel: 'icon', type: 'image/png', href: `${siteBase()}favicon.png` }],
54+
[
55+
"link",
56+
{ rel: "icon", type: "image/png", href: `${siteBase()}favicon.png` },
57+
],
5658
...analyticsHead(),
5759
],
5860
transformPageData(pageData) {
@@ -69,20 +71,34 @@ export default async () => {
6971
"meta",
7072
{ property: "og:url", content: canonicalUrl },
7173
]);
74+
75+
if (pageData.params?.sphinx) {
76+
pageData.frontmatter.prev = pageData.params.prev || {
77+
link: "/reference/",
78+
text: "Reference",
79+
};
80+
pageData.frontmatter.next = pageData.params.next ?? false;
81+
}
7282
},
7383
// Exclude directories starting with an underscore. Such directories are
7484
// internal (e.g. containing pages to be included in other pages).
7585
srcExclude: ["**/_*/**/*.md"],
7686
ignoreDeadLinks: [/^https?:\/\/localhost(:\d+)?(\/.*)?$/],
7787
themeConfig: {
78-
nav: [{ text: "Home", link: "/" }],
88+
logo: "/favicon.png",
89+
nav: [
90+
{ text: "User Guide", link: "/guide/" },
91+
{ text: "Development", link: "/development/" },
92+
{ text: "Reference", link: "/reference/" },
93+
],
7994
notFound: {
8095
quote: "The page does not exist.",
8196
},
8297
sidebar: {
8398
"/": [
8499
{
85100
text: "User Guide",
101+
link: "/guide/",
86102
items: [
87103
{
88104
text: "Installation",
@@ -93,6 +109,17 @@ export default async () => {
93109
{
94110
text: "Development",
95111
link: "/development/",
112+
items: [],
113+
},
114+
{
115+
text: "Reference",
116+
link: "/reference/",
117+
items: [
118+
{
119+
text: "Python API Reference",
120+
link: "/reference/python/",
121+
},
122+
],
96123
},
97124
],
98125
},

docs/development/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Development

docs/guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# User Guide

docs/guide/installation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Installation

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Welcome to the Sail documentation!
88

99
- [User Guide](/guide/)
1010
- [Development](/development/)
11+
- [Reference](/reference/)

docs/reference/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Reference
2+
3+
- [Python API Reference](/reference/python/)

docs/reference/python/[page].md

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

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "module",
33
"private": true,
44
"scripts": {
5-
"lint": "eslint docs",
5+
"lint": "vue-tsc --noEmit && eslint docs",
66
"format": "prettier --write \"*.{js,json,md}\" \".github/**/*.{yml,yaml}\" \"docs/**/*.{ts,mts,vue,css,md}\"",
77
"docs:dev": "vitepress dev docs",
88
"docs:build": "vitepress build docs",
@@ -13,8 +13,8 @@
1313
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
1414
"@types/eslint__js": "^8.42.3",
1515
"@types/node": "^20.14.14",
16-
"@typescript-eslint/eslint-plugin": "^8.0.0",
17-
"@typescript-eslint/parser": "^8.0.0",
16+
"@typescript-eslint/eslint-plugin": "^8.0.1",
17+
"@typescript-eslint/parser": "^8.0.1",
1818
"autoprefixer": "^10.4.20",
1919
"eslint": "^9.8.0",
2020
"eslint-config-prettier": "^9.1.0",
@@ -25,9 +25,11 @@
2525
"prettier": "^3.3.3",
2626
"prettier-plugin-tailwindcss": "^0.5.14",
2727
"tailwindcss": "^3.4.7",
28-
"typescript": "^4.9.5",
29-
"typescript-eslint": "^8.0.0",
30-
"vitepress": "^1.3.1"
28+
"typescript": "^5.5.4",
29+
"typescript-eslint": "^8.0.1",
30+
"vitepress": "^1.3.2",
31+
"vue": "^3.4.35",
32+
"vue-tsc": "^2.0.29"
3133
},
3234
"postcss": {
3335
"plugins": {

0 commit comments

Comments
 (0)