Skip to content

Commit e4b03f3

Browse files
committed
Sidebar-generate: take sidebar as input in html-generate
And not the index file, to avoid doing multiple times the same thing
1 parent 60da2d7 commit e4b03f3

File tree

8 files changed

+47
-37
lines changed

8 files changed

+47
-37
lines changed

src/odoc/bin/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ end = struct
863863
Arg.(
864864
value
865865
& opt (some convert_fpath) None
866-
& info [ "index" ] ~doc ~docv:"FILE.odoc-index")
866+
& info [ "sidebar" ] ~doc ~docv:"FILE.odoc-index")
867867

868868
let cmd =
869869
let syntax =

src/odoc/rendering.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ let generate_odoc ~syntax ~warnings_options:_ ~renderer ~output ~extra_suffix
6868
~sidebar extra file =
6969
(match sidebar with
7070
| None -> Ok None
71-
| Some x ->
72-
Odoc_file.load_index x >>= fun index ->
73-
Ok (Some (Odoc_document.Sidebar.of_lang index)))
71+
| Some x -> Odoc_file.load_sidebar x >>= fun sidebar -> Ok (Some sidebar))
7472
>>= fun sidebar ->
7573
document_of_odocl ~syntax file >>= fun doc ->
7674
render_document renderer ~output ~sidebar ~extra_suffix ~extra doc;

test/frontmatter/toc_order.t/run.t

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
File "index.mld", line 1, characters 0-40:
2121
Warning: (children) doesn't include 'omitted'.
2222

23-
$ odoc html-generate --indent --index index.odoc-index -o _html _odoc/pkg/page-index.odocl
24-
$ odoc html-generate --index index.odoc-index -o _html _odoc/pkg/page-content.odocl
25-
$ odoc html-generate --index index.odoc-index -o _html _odoc/pkg/page-omitted.odocl
26-
$ odoc html-generate --index index.odoc-index -o _html _odoc/pkg/dir1/page-index.odocl
27-
$ odoc html-generate --index index.odoc-index -o _html _odoc/pkg/dir1/page-content_in_dir.odocl
28-
$ odoc html-generate --index index.odoc-index -o _html _odoc/pkg/dir1/page-dontent.odocl
23+
Turn the index into a sidebar (removes all unnecessary entries)
24+
$ odoc sidebar-generate index.odoc-index
25+
26+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o _html _odoc/pkg/page-index.odocl
27+
$ odoc html-generate --sidebar sidebar.odoc-sidebar -o _html _odoc/pkg/page-content.odocl
28+
$ odoc html-generate --sidebar sidebar.odoc-sidebar -o _html _odoc/pkg/page-omitted.odocl
29+
$ odoc html-generate --sidebar sidebar.odoc-sidebar -o _html _odoc/pkg/dir1/page-index.odocl
30+
$ odoc html-generate --sidebar sidebar.odoc-sidebar -o _html _odoc/pkg/dir1/page-content_in_dir.odocl
31+
$ odoc html-generate --sidebar sidebar.odoc-sidebar -o _html _odoc/pkg/dir1/page-dontent.odocl
2932
$ odoc support-files -o _html
3033

3134
$ odoc_print _odoc/pkg/page-index.odocl | jq .frontmatter

test/parent_id/missing_indexes.t/run.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
$ odoc link _odoc/page-bar.odoc
99
$ odoc link _odoc/baz/page-bli.odoc
1010
$ odoc compile-index -P _:_odoc
11+
$ odoc sidebar-generate index.odoc-index
1112

12-
$ odoc html-generate --index index.odoc-index --indent --output-dir _html _odoc/page-foo.odocl
13+
$ odoc html-generate --sidebar sidebar.odoc-sidebar --indent --output-dir _html _odoc/page-foo.odocl
1314

1415
Missing index for Baz makes it unclickable but use the ID for the name.
1516
Root is used for the missing index in the unnamed root directory.

test/roots_and_hierarchy/canonical_hierarchy.t/run.t

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ Let's link it:
2323

2424
Let's html-generate it (with a sidebar):
2525

26-
$ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname -o sidebar.odoc-index
27-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/page-file.odocl
28-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/dir1/page-my_page.odocl
29-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/dir1/page-index.odocl
30-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/page-index.odocl
31-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/libname/unit.odocl
26+
$ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname
27+
$ odoc sidebar-generate index.odoc-index
28+
29+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-file.odocl
30+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/dir1/page-my_page.odocl
31+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/dir1/page-index.odocl
32+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-index.odocl
33+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/libname/unit.odocl
3234

3335
Now, let's see the result
3436

test/roots_and_hierarchy/separate_doc_lib_folders.t/run.t

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ Let's link it:
2323

2424
Let's html-generate it (with a sidebar):
2525

26-
$ odoc compile-index -P pkg:_odoc/pkg/doc/ -L libname:_odoc/pkg/lib/libname -o sidebar.odoc-index
27-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/doc/page-file.odocl
28-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/doc/dir1/page-my_page.odocl
29-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/doc/dir1/page-index.odocl
30-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/doc/page-index.odocl
31-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/lib/libname/unit.odocl
26+
$ odoc compile-index -P pkg:_odoc/pkg/doc/ -L libname:_odoc/pkg/lib/libname
27+
$ odoc sidebar-generate index.odoc-index
28+
29+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/doc/page-file.odocl
30+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/doc/dir1/page-my_page.odocl
31+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/doc/dir1/page-index.odocl
32+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/doc/page-index.odocl
33+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/lib/libname/unit.odocl
3234

3335
Now, let's see the result
3436

test/roots_and_hierarchy/sidebar.t/run.t

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
$ odoc link -P pkg:_odoc/pkg/ _odoc/pkg/page-index.odoc
1313
$ odoc link -P pkg:_odoc/pkg/ _odoc/pkg/libname/unit.odoc
1414

15-
$ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname -o sidebar.odoc-index
16-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/page-file.odocl
17-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/dir1/page-my_page.odocl
18-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/dir1/page-index.odocl
19-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/page-index.odocl
20-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/libname/unit.odocl
15+
$ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname
16+
$ odoc sidebar-generate index.odoc-index
17+
18+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-file.odocl
19+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/dir1/page-my_page.odocl
20+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/dir1/page-index.odocl
21+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-index.odocl
22+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/libname/unit.odocl
2123

2224
A json version of a sidebar can be obtained using the sidebar-generate command:
2325

24-
$ odoc sidebar-generate --json sidebar.odoc-index
26+
$ odoc sidebar-generate --json index.odoc-index
2527
$ cat sidebar.json | jq
2628
{
2729
"pages": [

test/roots_and_hierarchy/sidebar_with_indexes.t/run.t

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ Since -L subfolders are omitted from -P roots, the index page should not be adde
1818
$ odoc link -P pkg:_odoc/pkg/ _odoc/pkg/libname/unit.odoc
1919
$ odoc link -P pkg:_odoc/pkg/ _odoc/pkg/libname/page-index.odoc
2020

21-
$ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname -o sidebar.odoc-index
22-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/page-file.odocl
23-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/dir1/page-my_page.odocl
24-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/dir1/page-index.odocl
25-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/page-index.odocl
26-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/libname/unit.odocl
27-
$ odoc html-generate --indent --index sidebar.odoc-index -o html _odoc/pkg/libname/page-index.odocl
21+
$ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname
22+
$ odoc sidebar-generate index.odoc-index
23+
24+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-file.odocl
25+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/dir1/page-my_page.odocl
26+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/dir1/page-index.odocl
27+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-index.odocl
28+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/libname/unit.odocl
29+
$ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/libname/page-index.odocl
2830

2931
$ cat html/pkg/index.html | grep odoc-global-toc -A 15
3032
<nav class="odoc-toc odoc-global-toc">

0 commit comments

Comments
 (0)