Skip to content

Commit 909e582

Browse files
committed
Website: update skeleton
- no more html generated from odoc as it's not very nice with zero cost bindings as most code gets removed - sidebar show implemented & unimplemented bindings - undocumented modules get a generated page with the code of the binding as a fallback with a notice about that & a link to edit the file
1 parent 415f6ad commit 909e582

16 files changed

Lines changed: 561 additions & 411 deletions

‎website/docs/example.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
id: example
3+
title: Example
4+
---
5+
6+
@todo

‎website/docs/install.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
id: install
3+
title: Installation
4+
---
5+
6+
@todo

‎website/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"re:clean": "bsb -clean-world",
1111
"re:start": "bsb -make-world -w",
1212
"re:build": "bsb -make-world",
13-
"build:prepare:odoc": "trash build/odoc-html && ./scripts/odoc-to-html.sh && trash build/odoc && node scripts/PrepareOdocHtmlToJson.bs.js",
1413
"build:prepare:md": "trash build/md && node scripts/PrepareMdToJson.bs.js",
15-
"build:prepare": "yarn build:prepare:odoc && yarn build:prepare:md",
14+
"build:prepare": "yarn build:prepare:md",
1615
"build:prerender-legacy": "./scripts/legacy-doc.sh",
1716
"build:prerender": "node scripts/BuildWebsite.entry.js",
1817
"build:copy-static": "cpy \"public/**/*\" dist/bs-react-native",

‎website/scripts/BuildWebsite.re‎

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,66 @@ open Belt;
44
let root = Process.cwd();
55
let outputPath = Path.join([|root, "dist", Consts.baseUrl|]);
66

7-
let buildOdoc = () => {
8-
let sourcePath = Path.join([|root, "build", "odoc"|]);
9-
Path.join([|sourcePath, "**/*.json"|])
10-
->FsUtils.transform(files =>
11-
files->Array.map(file => {
12-
let name =
13-
file.name
14-
|> Js.String.replace(sourcePath, "en/docs")
15-
|> Js.String.replace("/index.json", "/index.html")
16-
|> Js.String.replace(".json", "/index.html");
17-
let content = Prerender.file({name, content: file.content});
18-
let f: FsUtils.t = {name: Path.join([|outputPath, name|]), content};
19-
f;
20-
})
21-
);
22-
};
7+
let indexJsonString =
8+
Fs.readFileAsUtf8Sync(
9+
Path.join([|root, "build", "docs-src", "__index__.json"|]),
10+
);
11+
let indexJson =
12+
try (indexJsonString->Js.Json.parseExn) {
13+
| _ => failwith("Error parsing JSON modules index")
14+
};
15+
let index =
16+
indexJson
17+
->Js.Json.decodeArray
18+
->Option.map(a =>
19+
a->Array.reduce([||], (acc, s) =>
20+
s
21+
->Js.Json.decodeString
22+
->Option.map(s => acc->Array.concat([|s|]))
23+
->Option.getWithDefault(acc)
24+
)
25+
)
26+
->Option.getWithDefault([||]);
2327

24-
let buildMd = () => {
25-
let sourcePath = Path.join([|root, "build", "md"|]);
26-
Path.join([|sourcePath, "**/*.json"|])
27-
->FsUtils.transform(files =>
28-
files->Array.map(file => {
29-
let name =
30-
file.name
31-
|> Js.String.replace(sourcePath, "en/docs")
32-
|> Js.String.replace("/index.json", "/index.html")
33-
|> Js.String.replace(".json", "/index.html");
34-
let content = Prerender.file({name, content: file.content});
35-
let f: FsUtils.t = {name: Path.join([|outputPath, name|]), content};
36-
f;
37-
})
38-
);
39-
};
28+
// build docs pages
29+
let sourcePath = Path.join([|root, "build", "docs-pages"|]);
30+
Path.join([|sourcePath, "**/!(__index__).json"|])
31+
->FsUtils.transform(files =>
32+
files->Array.map(file => {
33+
let name =
34+
file.name
35+
|> Js.String.replace(sourcePath, "en/docs")
36+
|> Js.String.replace("/index.json", "/index.html")
37+
|> Js.String.replace(".json", "/index.html");
38+
let content = Prerender.file({name, content: file.content}, index);
39+
let f: FsUtils.t = {name: Path.join([|outputPath, name|]), content};
40+
f;
41+
})
42+
);
4043

41-
let buildUrl = urls => {
42-
urls
43-
->Array.map(url => {
44-
let f: FsUtils.t = {
45-
name: Path.join([|outputPath, url ++ "/index.html"|]),
46-
content: Prerender.make(~url, ~pageData=None),
47-
};
44+
// build docs src
45+
let sourcePath = Path.join([|root, "build", "docs-src"|]);
46+
Path.join([|sourcePath, "**/!(__index__).json"|])
47+
->FsUtils.transform(files =>
48+
files->Array.map(file => {
49+
let name =
50+
file.name
51+
|> Js.String.replace(sourcePath, "en/docs")
52+
|> Js.String.replace("/index.json", "/index.html")
53+
|> Js.String.replace(".json", "/index.html");
54+
let content = Prerender.file({name, content: file.content}, index);
55+
let f: FsUtils.t = {name: Path.join([|outputPath, name|]), content};
4856
f;
4957
})
50-
->FsUtils.write;
51-
};
58+
);
5259

53-
buildOdoc();
54-
buildMd();
55-
buildUrl([|""|]);
60+
// build urls
61+
[|""|]
62+
->Array.map(url => {
63+
let f: FsUtils.t = {
64+
name: Path.join([|outputPath, url ++ "/index.html"|]),
65+
content: Prerender.make(~url, ~pageData=None),
66+
};
67+
f;
68+
})
69+
->FsUtils.write;

‎website/scripts/PrepareMdToJson.re‎

Lines changed: 149 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ open Node;
22
open Belt;
33

44
let root = Process.cwd();
5-
let sourcePath = Path.join([|root, "docs"|]);
6-
let outputPath = Path.join([|root, "build/md"|]);
75

86
{
97
HighlightJs.(hjs->registerLanguage("reason", reason));
@@ -16,6 +14,7 @@ let remarkable =
1614
"html": true,
1715
"linkify": true,
1816
"xhtmlOut": true,
17+
"langPrefix": "hljs language-",
1918
"highlight":
2019
Some(
2120
(code, lang) =>
@@ -30,48 +29,156 @@ let remarkable =
3029
},
3130
);
3231

32+
Js.log("Pages...");
33+
let sourcePath = Path.join([|root, "docs"|]);
34+
let outputPath = Path.join([|root, "build", "docs-pages"|]);
3335
Path.join([|sourcePath, "**/*.md"|])
3436
->FsUtils.transform(files => {
3537
let newFiles: array(FsUtils.t) = [||];
36-
files->Array.reduce(
37-
newFiles,
38-
(files, file) => {
39-
let shortName =
40-
file.name
41-
|> Js.String.replace(sourcePath, "")
42-
|> Js.String.replace(".md", "");
43-
let front = FrontMatter.parse(file.content);
44-
let content =
45-
{
46-
"id": front##attributes##id,
47-
"title": front##attributes##title,
48-
"body": Remarkable.render(remarkable, front##body),
49-
}
50-
->Js.Json.stringifyAny;
51-
if (content->Option.isNone) {
52-
Js.log2(file.name, "can't be transformed");
53-
};
54-
content
55-
->Option.map(content =>
56-
files->Array.concat([|
57-
{
58-
name: Path.join([|outputPath, shortName ++ ".json"|]),
59-
content,
60-
},
61-
|])
38+
let finalFiles =
39+
files->Array.reduce(
40+
newFiles,
41+
(files, file) => {
42+
let shortName =
43+
file.name
44+
|> Js.String.replace(sourcePath, "")
45+
|> Js.String.replace(".md", "");
46+
let front = FrontMatter.parse(file.content);
47+
let content =
48+
{
49+
"id": front##attributes##id,
50+
"title": front##attributes##title,
51+
"body": Remarkable.render(remarkable, front##body),
52+
}
53+
->Js.Json.stringifyAny;
54+
if (content->Option.isNone) {
55+
Js.log2(file.name, "can't be transformed");
56+
};
57+
content
58+
->Option.map(content =>
59+
files->Array.concat([|
60+
{
61+
name: Path.join([|outputPath, shortName ++ ".json"|]),
62+
content,
63+
},
64+
|])
65+
)
66+
->Option.getWithDefault(files);
67+
},
68+
);
69+
finalFiles->Array.concat([|
70+
{
71+
name: Path.join([|outputPath, "__index__.json"|]),
72+
content:
73+
(
74+
finalFiles->Array.map(file =>
75+
file.name
76+
|> Js.String.replace(outputPath ++ "/", "")
77+
|> Js.String.replace(".json", "")
78+
)
79+
|> Js.Json.stringifyAny
80+
)
81+
->Option.getWithDefault("[]"),
82+
},
83+
|]);
84+
});
85+
86+
Js.log("Create missing markdown files (wip)...");
87+
// create missing md for modules
88+
[@bs.module "fs"] external existsSync: string => bool = "existsSync";
89+
let createMissingMd = (sourcePath, outputPath, files) => {
90+
let newFiles: array(FsUtils.t) = [||];
91+
files->Array.reduce(
92+
newFiles,
93+
(files, file: FsUtils.t) => {
94+
let shortName =
95+
file.name
96+
|> Js.String.replace(sourcePath ++ "/", "")
97+
|> Js.String.replace(".rei", "")
98+
|> Js.String.replace(".re", "");
99+
let finalfilename = Path.join([|outputPath, shortName ++ ".md"|]);
100+
if (try (!existsSync(finalfilename)) {
101+
| _ => true
102+
}) {
103+
let name = shortName->Path.basename;
104+
let code = file.content;
105+
let content = {j|---
106+
id: $shortName
107+
title: $name
108+
wip: true
109+
---
110+
111+
```reason
112+
$code
113+
```
114+
|j};
115+
files->Array.concat([|{name: finalfilename, content}|]);
116+
} else {
117+
files;
118+
};
119+
},
120+
);
121+
};
122+
let sourcePath = Path.join([|root, "..", "bs-react-native-next", "src"|]);
123+
let outputPath = Path.join([|root, "..", "bs-react-native-next", "src"|]);
124+
// create from rei first
125+
Path.join([|sourcePath, "**/*.rei"|])
126+
->FsUtils.transform(createMissingMd(sourcePath, outputPath));
127+
// fallback to re
128+
Path.join([|sourcePath, "**/*.re"|])
129+
->FsUtils.transform(createMissingMd(sourcePath, outputPath));
130+
131+
Js.log("Modules...");
132+
let sourcePath = Path.join([|root, "..", "bs-react-native-next", "src"|]);
133+
let outputPath = Path.join([|root, "build", "docs-src"|]);
134+
Path.join([|sourcePath, "**/*.md"|])
135+
->FsUtils.transform(files => {
136+
let newFiles: array(FsUtils.t) = [||];
137+
let finalFiles =
138+
files->Array.reduce(
139+
newFiles,
140+
(files, file) => {
141+
let shortName =
142+
file.name
143+
|> Js.String.replace(sourcePath, "")
144+
|> Js.String.replace(".md", "");
145+
let front = FrontMatter.parse(file.content);
146+
let content =
147+
{
148+
"id": front##attributes##id,
149+
"title": front##attributes##title,
150+
"wip": front##attributes##wip,
151+
"body": Remarkable.render(remarkable, front##body),
152+
}
153+
->Js.Json.stringifyAny;
154+
if (content->Option.isNone) {
155+
Js.log2(file.name, "can't be transformed");
156+
};
157+
content
158+
->Option.map(content =>
159+
files->Array.concat([|
160+
{
161+
name: Path.join([|outputPath, shortName ++ ".json"|]),
162+
content,
163+
},
164+
|])
165+
)
166+
->Option.getWithDefault(files);
167+
},
168+
);
169+
finalFiles->Array.concat([|
170+
{
171+
name: Path.join([|outputPath, "__index__.json"|]),
172+
content:
173+
(
174+
finalFiles->Array.map(file =>
175+
file.name
176+
|> Js.String.replace(outputPath ++ "/", "")
177+
|> Js.String.replace(".json", "")
178+
)
179+
|> Js.Json.stringifyAny
62180
)
63-
->Option.getWithDefault(files);
181+
->Option.getWithDefault("[]"),
64182
},
65-
);
66-
}) /*->Future.map(files => {
67-
let names = files->Array.map(file => file.name);
68-
{"files": names}
69-
->Js.Json.stringifyAny
70-
->Option.map(jsonNames =>
71-
Fs.writeFileAsUtf8Sync(
72-
Path.join([|outputPath, "__index__" ++ ".json"|]),
73-
jsonNames,
74-
)
75-
)
76-
->ignore;
77-
})*/;
183+
|]);
184+
});

0 commit comments

Comments
 (0)