···991010 val of_page_hierarchy : Odoc_index.Page_hierarchy.t -> t
11111212- val of_skeleton : Odoc_index.Skeleton.t -> t
1313-1412 val to_block : prune:bool -> Url.Path.t -> t -> Block.t
1513end = struct
1614 type t = entry Tree.t
17151818- let of_page_hierarchy (dir : Odoc_index.Page_hierarchy.t) : t =
1919- let f index =
2020- match index with
2121- | Odoc_index.Page_hierarchy.Missing_index None ->
2222- (None, inline @@ Text "Root")
2323- | Odoc_index.Page_hierarchy.Missing_index (Some id) ->
2424- let path = Url.from_identifier ~stop_before:false (id :> Id.t) in
2525- (Some path, inline @@ Text (Id.name id))
2626- | Page (id, title) ->
2727- let path = Url.from_identifier ~stop_before:false (id :> Id.t) in
2828- let content = Comment.link_content title in
2929- let target = Target.Internal (Target.Resolved path) in
3030- let i = inline @@ Inline.Link { target; content; tooltip = None } in
3131- (Some path, i)
3232- in
3333- Tree.map ~f dir
3434-3516 let rec is_prefix (url1 : Url.Path.t) (url2 : Url.Path.t) =
3617 if url1 = url2 then true
3718 else
···41224223 let parent (url : Url.t) =
4324 match url with
4444- | { anchor = ""; page = { parent = Some parent; _ }; _ } -> parent
2525+ | {
2626+ anchor = "";
2727+ page =
2828+ {
2929+ parent = Some { parent = Some parent; _ };
3030+ name = "index";
3131+ kind = `LeafPage;
3232+ };
3333+ _;
3434+ }
3535+ | { anchor = ""; page = { parent = Some parent; _ }; _ } ->
3636+ parent
4537 | { page; _ } -> page
46384739 let to_block ~prune (current_url : Url.Path.t) (tree : t) =
···8274 let block_tree = block_tree_of_t current_url tree in
8375 block_of_block_tree block_tree
84768585- let of_skeleton ({ node = entry; children } : Odoc_index.Entry.t Tree.t) : t =
7777+ let of_page_hierarchy ({ node = entry; children } : Odoc_index.Entry.t Tree.t)
7878+ : t =
8679 let map_entry entry =
8780 let stop_before =
8881 match entry.Odoc_index.Entry.kind with
···9992 in
10093 (Some path, content)
10194 in
102102- let f entry =
103103- match entry.Odoc_index.Entry.kind with
9595+ let f index =
9696+ match index.Odoc_index.Entry.kind with
9797+ | Dir ->
9898+ let path = Url.from_identifier ~stop_before:false index.id in
9999+ Some (Some path, inline @@ Text (Id.name index.id))
100100+ | Page _frontmatter ->
101101+ let path =
102102+ Url.from_identifier ~stop_before:false (index.id :> Id.t)
103103+ in
104104+ let title =
105105+ match Odoc_model.Comment.find_zero_heading index.doc with
106106+ | Some t -> t
107107+ | None ->
108108+ Odoc_model.Location_.[ at (span []) (`Word (Id.name index.id)) ]
109109+ in
110110+ let content = Comment.link_content title in
111111+ let target = Target.Internal (Target.Resolved path) in
112112+ let i = inline @@ Inline.Link { target; content; tooltip = None } in
113113+ Some (Some path, i)
104114 | Module _ | Class_type _ | Class _ | ModuleType _ ->
105105- Some (map_entry entry)
115115+ Some (map_entry index)
106116 | _ -> None
107117 in
108118 let entry = map_entry entry in
109119 let children = Forest.filter_map ~f children in
110120 { Tree.node = entry; children }
121121+ (* Tree.filter_map ~f dir *)
111122end
112123113113-type pages = { name : string; pages : Toc.t }
114114-type library = { name : string; units : Toc.t list }
124124+type t = Toc.t list
115125116116-type t = { pages : pages list; libraries : library list }
117117-118118-let of_lang (v : Odoc_index.t) =
119119- let { Odoc_index.pages; libs; extra = _ } = v in
120120- let pages =
121121- let page_hierarchy { Odoc_index.p_name; p_hierarchy } =
122122- let hierarchy = Toc.of_page_hierarchy p_hierarchy in
123123- { name = p_name; pages = hierarchy }
124124- in
125125- Odoc_utils.List.map page_hierarchy pages
126126- in
127127- let libraries =
128128- let lib_hierarchies { Odoc_index.l_name; l_hierarchies } =
129129- let hierarchies = List.map Toc.of_skeleton l_hierarchies in
130130- { units = hierarchies; name = l_name }
131131- in
132132- Odoc_utils.List.map lib_hierarchies libs
133133- in
134134- { pages; libraries }
126126+let of_lang (v : Odoc_index.t) = List.map Toc.of_page_hierarchy v
135127136128let to_block (sidebar : t) path =
137137- let { pages; libraries } = sidebar in
138138- let title t = block (Inline [ inline (Inline.Styled (`Bold, t)) ]) in
139139- let pages =
140140- let pages =
141141- Odoc_utils.List.concat_map
142142- ~f:(fun (p : pages) ->
143143- let () = ignore p.name in
144144- let pages = Toc.to_block ~prune:false path p.pages in
145145- [
146146- block ~attr:[ "odoc-pages" ]
147147- (Block.List (Block.Unordered, [ pages ]));
148148- ])
149149- pages
150150- in
151151- [ title @@ [ inline (Inline.Text "Documentation") ] ] @ pages
152152- in
153153- let units =
154154- let units =
155155- List.map
156156- (fun { units; name } ->
157157- let units =
158158- List.concat_map ~f:(Toc.to_block ~prune:true path) units
159159- in
160160- let units = [ block (Block.List (Block.Unordered, [ units ])) ] in
161161- [
162162- title
163163- @@ [
164164- inline (Inline.Text "Library ");
165165- inline (Inline.Source [ Elt [ inline @@ Text name ] ]);
166166- ];
167167- ]
168168- @ units)
169169- libraries
170170- in
171171- let units =
172172- block ~attr:[ "odoc-modules" ] (Block.List (Block.Unordered, units))
173173- in
174174- [ units ]
175175- in
176176- units @ pages
129129+ List.map (Toc.to_block ~prune:true path) sidebar
+2-5
src/document/sidebar.mli
···3344type entry = Url.t option * Inline.one
5566-type pages = { name : string; pages : entry Tree.t }
77-type library = { name : string; units : entry Tree.t list }
88-99-type t = { pages : pages list; libraries : library list }
66+type t = entry Tree.t list
107118val of_lang : Odoc_index.t -> t
1291313-val to_block : t -> Url.Path.t -> Types.Block.t
1010+val to_block : t -> Url.Path.t -> Types.Block.t list
1411(** Generates the sidebar document given a global sidebar and the path at which
1512 it will be displayed *)
···7878 in
79798080 let index_of pkg =
8181- let pkg_libs =
8282- List.map (fun l -> l.Packages.lib_name) pkg.Packages.libraries
8383- |> Util.StringSet.of_list
8484- in
8585- let pkg_args = base_args pkg pkg_libs in
8181+ let roots = [ Fpath.( // ) odocl_dir (doc_dir pkg) ] in
8682 let output_file = Fpath.(index_dir / pkg.name / Odoc.index_filename) in
8783 let sidebar =
8884 let output_file = Fpath.(index_dir / pkg.name / Odoc.sidebar_filename) in
8985 { output_file; json = false }
9086 in
9187 {
9292- pkg_args;
8888+ roots;
9389 output_file;
9490 json = false;
9591 search_dir = pkg.pkg_dir;
+6-2
src/driver/run.ml
···6868 Logs.err (fun m -> m "%d - Process exitted %d: stderr=%s" myn n err);
6969 failwith "Error"
7070 | `Signaled n ->
7171- Logs.err (fun m -> m "%d - Signalled %d: stderr=%s" myn n err);
7272- failwith ("Signaled " ^ string_of_int n)
7171+ let err =
7272+ Format.sprintf "Error from %s\n%d - Signalled %d: stderr=%s"
7373+ (String.concat " " cmd) myn n err
7474+ in
7575+ Logs.err (fun m -> m "%s" err);
7676+ failwith err
7377 with Eio.Exn.Io _ as ex ->
7478 let bt = Printexc.get_raw_backtrace () in
7579 Eio.Exn.reraise_with_context ex bt "%d - running command: %a" myn
+2-1
src/html/generator.ml
···543543 | None -> None
544544 | Some sidebar ->
545545 let sidebar = Odoc_document.Sidebar.to_block sidebar url in
546546- (Some (block ~config ~resolve sidebar) :> any Html.elt list option)
546546+ (Some (List.concat_map (block ~config ~resolve) sidebar)
547547+ :> any Html.elt list option)
547548 in
548549 let i = Doctree.Shift.compute ~on_sub i in
549550 let uses_katex = Doctree.Math.has_math_elements p in
···5656 | ModuleType of module_entry
5757 | Constructor of constructor_entry
5858 | Field of field_entry
5959+ | Page of Odoc_model.Frontmatter.t
6060+ | Dir
59616062type t = {
6163 id : Odoc_model.Paths.Identifier.Any.t;
+2
src/index/entry.mli
···5454 | ModuleType of module_entry
5555 | Constructor of constructor_entry
5656 | Field of field_entry
5757+ | Page of Odoc_model.Frontmatter.t
5858+ | Dir
57595860type t = {
5961 id : Odoc_model.Paths.Identifier.Any.t;
+1-12
src/index/odoc_index.ml
···22module Entry = Entry
33module Page_hierarchy = Page_hierarchy
4455-type page = { p_name : string; p_hierarchy : Page_hierarchy.t }
66-77-type lib_hierarchies = Skeleton.t list
88-type lib = { l_name : string; l_hierarchies : lib_hierarchies }
99-1010-type t = {
1111- pages : page list;
1212- libs : lib list;
1313- extra : Skeleton.t list;
1414- (** This extra table is used only for search. It was introduced before
1515- Odoc 3 *)
1616-}
55+type t = Skeleton.t list
+71-30
src/index/page_hierarchy.ml
···7788module CPH = Id.Hashtbl.ContainerPage
99module LPH = Id.Hashtbl.LeafPage
1010+module RMH = Id.Hashtbl.RootModule
10111112type page = Id.Page.t
1212-type leaf_page = Id.LeafPage.t
1313type container_page = Id.ContainerPage.t
14141515open Astring
16161717type title = Comment.link_content
18181919-type payload = {
2020- title : title;
2121- children_order : Frontmatter.children_order option;
1919+type payload = (* { title : title; frontmatter : Frontmatter.t } *) Lang.Page.t
2020+2121+type dir_content = {
2222+ leafs : payload LPH.t;
2323+ dirs : in_progress CPH.t;
2424+ modules : Skeleton.t RMH.t;
2225}
2323-2424-type dir_content = { leafs : payload LPH.t; dirs : in_progress CPH.t }
2526and in_progress = container_page option * dir_content
26272727-let empty_t dir_id = (dir_id, { leafs = LPH.create 10; dirs = CPH.create 10 })
2828+let empty_t dir_id =
2929+ ( dir_id,
3030+ { leafs = LPH.create 10; dirs = CPH.create 10; modules = RMH.create 10 } )
28312932let get_parent id : container_page option =
3033 let id :> page = id in
···38413942let leafs (_, dir_content) =
4043 LPH.fold
4141- (fun id { title = payload; _ } acc ->
4242- if String.equal "index" (Id.name id) then acc else (id, payload) :: acc)
4444+ (fun id page acc ->
4545+ if String.equal "index" (Id.name id) then acc else (id, page) :: acc)
4346 dir_content.leafs []
44474548let dirs (_, dir_content) =
4649 CPH.fold (fun id payload acc -> (id, payload) :: acc) dir_content.dirs []
5050+5151+let modules (_, dir_content) =
5252+ RMH.fold (fun id payload acc -> (id, payload) :: acc) dir_content.modules []
47534854let rec get_or_create (dir : in_progress) (id : container_page) : in_progress =
4955 let _, { dirs = parent_dirs; _ } =
···6167 CPH.add parent_dirs id new_;
6268 new_
63696464-let add (dir : in_progress) ((id : leaf_page), title, children_order) =
7070+let add_page (dir : in_progress) page =
7171+ match page.Lang.Page.name with
7272+ | { iv = #Id.LeafPage.t_pv; _ } as id ->
7373+ let _, dir_content =
7474+ match get_parent id with
7575+ | Some parent -> get_or_create dir parent
7676+ | None -> dir
7777+ in
7878+ LPH.replace dir_content.leafs id page
7979+ | _ -> ()
8080+8181+let add_module (dir : in_progress) m =
6582 let _, dir_content =
6666- match get_parent id with
6767- | Some parent -> get_or_create dir parent
6868- | None -> dir
8383+ match m.Lang.Compilation_unit.id.iv with
8484+ | `Root (Some parent, _) -> get_or_create dir parent
8585+ | `Root (None, _) -> dir
6986 in
7070- LPH.replace dir_content.leafs id { title; children_order }
8787+ let skel = Skeleton.from_unit m in
8888+ RMH.replace dir_content.modules m.id skel
71897290let dir_index ((parent_id, _) as dir) =
7391 let index_id = Id.Mk.leaf_page (parent_id, PageName.make_std "index") in
7492 match find_leaf dir index_id with
7575- | Some payload -> Some (payload, index_id, payload.title)
9393+ | Some payload -> Some (index_id, payload)
7694 | None -> None
77957878-type index =
7979- | Page of Id.Page.t * title
8080- | Missing_index of Id.ContainerPage.t option
8181-8282-type t = index Odoc_utils.Tree.t
9696+type t = Entry.t Tree.t
83978498let rec t_of_in_progress (dir : in_progress) : t =
9999+ let entry_of_page page =
100100+ let kind = Entry.Page page.Lang.Page.frontmatter in
101101+ let doc = page.content in
102102+ let id = page.name in
103103+ Entry.entry ~kind ~doc ~id
104104+ in
85105 let children_order, index =
86106 match dir_index dir with
8787- | Some ({ children_order; _ }, index_id, index_title) ->
8888- (children_order, Page (index_id, index_title))
8989- | None -> (None, Missing_index (fst dir))
107107+ | Some (_, page) ->
108108+ let children_order = page.frontmatter.children_order in
109109+ let entry = entry_of_page page in
110110+ (children_order, entry)
111111+ | None ->
112112+ let entry =
113113+ match fst dir with
114114+ | Some id ->
115115+ let kind = Entry.Dir in
116116+ let doc = [] in
117117+ Entry.entry ~kind ~doc ~id
118118+ | None ->
119119+ let id =
120120+ (* root dir must have an index page *)
121121+ Id.Mk.leaf_page (None, Names.PageName.make_std "index")
122122+ in
123123+ let kind = Entry.Dir in
124124+ let doc = [] in
125125+ Entry.entry ~kind ~doc ~id
126126+ in
127127+ (None, entry)
90128 in
91129 let pp_content fmt (id, _) =
92130 match id.Id.iv with
···102140 let contents =
103141 let leafs =
104142 leafs dir
105105- |> List.map (fun (id, payload) ->
106106- let id :> Id.Page.t = id in
107107- (id, Tree.leaf (Page (id, payload))))
143143+ |> List.map (fun (_, page) ->
144144+ let id :> Id.Page.t = page.Lang.Page.name in
145145+ let entry = entry_of_page page in
146146+ (id, Tree.leaf entry))
108147 in
109148 let dirs =
110149 dirs dir
···178217 String.compare (Paths.Identifier.name x) (Paths.Identifier.name y))
179218 unordered
180219 in
220220+ let modules = modules dir |> List.map snd in
181221 let contents = ordered @ unordered |> List.map snd in
182182- { Tree.node = index; children = contents }
222222+ { Tree.node = index (* , modules *); children = contents @ modules }
183223184224let rec remove_common_root (v : t) =
185225 match v with
186186- | { Tree.children = [ v ]; node = Missing_index _ } -> remove_common_root v
226226+ | { Tree.children = [ v ]; node = { kind = Dir; _ } } -> remove_common_root v
187227 | _ -> v
188228189189-let of_list l =
229229+let of_list ~pages ~modules =
190230 let dir = empty_t None in
191191- List.iter (add dir) l;
231231+ List.iter (add_page dir) pages;
232232+ List.iter (add_module dir) modules;
192233 t_of_in_progress dir |> remove_common_root
+2-7
src/index/page_hierarchy.mli
···11open Odoc_model
22-open Odoc_model.Paths
32open Odoc_utils
4354(** Page hierarchies represent a hierarchy of pages. *)
6576type title = Comment.link_content
8799-type index =
1010- | Page of Paths.Identifier.Page.t * title
1111- | Missing_index of Paths.Identifier.ContainerPage.t option
1212-1313-type t = index Tree.t
88+type t = Entry.t Tree.t
1491510val of_list :
1616- (Identifier.LeafPage.t * title * Frontmatter.children_order option) list -> t
1111+ pages:Lang.Page.t list -> modules:Lang.Compilation_unit.t list -> t
1712(** Uses the convention that the [index] children passes its payload to the
1813 container directory to output a payload *)
···244244 module Any : Hashtbl.S with type key = Any.t
245245 module ContainerPage : Hashtbl.S with type key = ContainerPage.t
246246 module LeafPage : Hashtbl.S with type key = LeafPage.t
247247+ module RootModule : Hashtbl.S with type key = RootModule.t
247248 end
248249249250 module Mk : sig
+11-24
src/odoc/bin/main.ml
···468468 | None, `JSON -> Ok (Fs.File.of_string "index.json")
469469 | None, `Marshall -> Ok (Fs.File.of_string "index.odoc-index")
470470471471- let index dst json warnings_options page_roots lib_roots inputs_in_file inputs
472472- occurrences =
471471+ let index dst json warnings_options roots inputs_in_file inputs occurrences =
473472 let marshall = if json then `JSON else `Marshall in
474473 output_file ~dst marshall >>= fun output ->
475475- Antichain.check (page_roots |> List.map ~f:snd) ~opt:"-P" >>= fun () ->
476476- Antichain.check (lib_roots |> List.map ~f:snd) ~opt:"-L" >>= fun () ->
477477- Indexing.compile marshall ~output ~warnings_options ~occurrences ~lib_roots
478478- ~page_roots ~inputs_in_file ~odocls:inputs
474474+ Antichain.check roots ~opt:"--root" >>= fun () ->
475475+ Indexing.compile marshall ~output ~warnings_options ~roots ~occurrences
476476+ ~inputs_in_file ~odocls:inputs
479477480478 let cmd =
481479 let dst =
···511509 let doc = ".odocl file to index" in
512510 Arg.(value & pos_all convert_fpath [] & info ~doc ~docv:"FILE" [])
513511 in
514514- let page_roots =
512512+ let roots =
515513 let doc =
516516- "Specifies a directory PATH containing pages that should be included \
517517- in the sidebar, under the NAME section."
514514+ "Specifies a directory PATH containing pages or units that should be \
515515+ included in the sidebar."
518516 in
519517 Arg.(
520518 value
521521- & opt_all convert_named_root []
522522- & info ~docs ~docv:"NAME:PATH" ~doc [ "P" ])
523523- in
524524- let lib_roots =
525525- let doc =
526526- "Specifies a directory PATH containing units that should be included \
527527- in the sidebar, as part of the LIBNAME library."
528528- in
529529-530530- Arg.(
531531- value
532532- & opt_all convert_named_root []
533533- & info ~docs ~docv:"LIBNAME:PATH" ~doc [ "L" ])
519519+ & opt_all (convert_directory ()) []
520520+ & info ~docs ~docv:"NAME:PATH" ~doc [ "root" ])
534521 in
535522 Term.(
536523 const handle_error
537537- $ (const index $ dst $ json $ warnings_options $ page_roots $ lib_roots
538538- $ inputs_in_file $ inputs $ occurrences))
524524+ $ (const index $ dst $ json $ warnings_options $ roots $ inputs_in_file
525525+ $ inputs $ occurrences))
539526540527 let info ~docs =
541528 let doc =
+18-87
src/odoc/indexing.ml
···1010let handle_file file ~unit ~page ~occ =
1111 match Fpath.basename file with
1212 | s when String.is_prefix ~affix:"index-" s ->
1313- Odoc_file.load_index file >>= fun { extra (* libs *); _ } ->
1414- Ok (occ extra)
1313+ Odoc_file.load_index file
1414+ >>= fun (* { extra (\* libs *\); _ } *) sidebar -> Ok (occ sidebar)
1515 | _ -> (
1616 Odoc_file.load file >>= fun unit' ->
1717 match unit' with
···7575 Format.fprintf output "]";
7676 Ok ()
77777878-let compile_to_marshall ~output (pages, libs) files =
7979- let unit u = [ Odoc_index.Skeleton.from_unit u ] in
8080- let page p = [ Odoc_index.Skeleton.from_page p ] in
8181- let index i = i in
8282- let extra =
8383- List.concat_map
8484- ~f:(fun file ->
8585- match handle_file ~unit ~page ~occ:index file with
8686- | Ok l -> l
8787- | Error (`Msg m) ->
8888- Error.raise_warning ~non_fatal:true
8989- (Error.filename_only "%s" m (Fs.File.to_string file));
9090- [])
9191- files
9292- in
9393- let content = { Odoc_index.pages; libs; extra } in
9494- Ok (Odoc_file.save_index output content)
7878+let compile_to_marshall ~output hierarchy =
7979+ Ok (Odoc_file.save_index output hierarchy)
95809681let read_occurrences file =
9782 let ic = open_in_bin file in
9883 let htbl : Odoc_occurrences.Table.t = Marshal.from_channel ic in
9984 htbl
10085101101-let pages resolver page_roots =
102102- List.map
103103- (fun (page_root, _) ->
104104- let pages = Resolver.all_pages ~root:page_root resolver in
105105- let p_hierarchy =
106106- let page_toc_input =
107107- (* To create a page toc, we need a list with id, title and children
108108- order. We generate this list from *)
109109- let prepare_input (id, title, frontmatter) =
110110- (* We filter non-leaf pages *)
111111- match id with
112112- | { Id.iv = #Id.LeafPage.t_pv; _ } as id ->
113113- (* We generate a title if needed *)
114114- let title =
115115- match title with
116116- | None -> Location_.[ at (span []) (`Word (Id.name id)) ]
117117- | Some x -> x
118118- in
119119- let children_order = frontmatter.Frontmatter.children_order in
120120- Some (id, title, children_order)
121121- | _ -> None
122122- in
123123- List.filter_map prepare_input pages
124124- in
125125- Odoc_index.Page_hierarchy.of_list page_toc_input
126126- in
127127- { Odoc_index.p_name = page_root; p_hierarchy })
128128- page_roots
129129-130130-let libs resolver lib_roots =
131131- List.map
132132- (fun (library, _) ->
133133- let units = Resolver.all_units ~library resolver in
134134- let l_hierarchies =
135135- List.filter_map
136136- (fun (file, _id) ->
137137- match file () with
138138- | Some unit -> Some (Odoc_index.Skeleton.from_unit unit)
139139- | None -> None)
140140- units
141141- in
142142- { Odoc_index.l_name = library; l_hierarchies })
143143- lib_roots
144144-145145-let compile out_format ~output ~warnings_options ~occurrences ~lib_roots
146146- ~page_roots ~inputs_in_file ~odocls =
8686+let compile out_format ~output ~warnings_options ~occurrences ~roots
8787+ ~inputs_in_file ~odocls =
14788 let handle_warnings f =
14889 let res = Error.catch_warnings f in
14990 Error.handle_warnings ~warnings_options res |> Result.join
15091 in
15192 handle_warnings @@ fun () ->
152152- let current_dir = Fs.File.dirname output in
15393 parse_input_files inputs_in_file >>= fun files ->
15494 let files = List.rev_append odocls files in
15595 let occurrences =
···15797 | None -> None
15898 | Some occurrences -> Some (read_occurrences (Fpath.to_string occurrences))
15999 in
160160- let includes_rec =
161161- List.rev_append (List.map snd page_roots) (List.map snd lib_roots)
162162- in
163100 let files =
164101 List.rev_append files
165165- (includes_rec
102102+ (roots
166103 |> List.map (fun include_rec ->
167104 Fs.Directory.fold_files_rec ~ext:"odocl"
168105 (fun files file -> file :: files)
169106 [] include_rec)
170107 |> List.concat)
171108 in
109109+ let pages, modules =
110110+ let read (pages, modules) f =
111111+ match Odoc_file.load f with
112112+ | Ok { content = Page_content p; _ } -> (p :: pages, modules)
113113+ | Ok { content = Unit_content m; _ } -> (pages, m :: modules)
114114+ | _ -> (pages, modules)
115115+ in
116116+ List.fold_left read ([], []) files
117117+ in
118118+ let hierarchy = Odoc_index.Page_hierarchy.of_list ~pages ~modules in
172119 match out_format with
173120 | `JSON -> compile_to_json ~output ~occurrences files
174174- | `Marshall ->
175175- let resolver =
176176- Resolver.create ~important_digests:false ~directories:[]
177177- ~roots:
178178- (Some
179179- {
180180- page_roots;
181181- lib_roots;
182182- current_lib = None;
183183- current_package = None;
184184- current_dir;
185185- })
186186- ~open_modules:[]
187187- in
188188- let pages = pages resolver page_roots in
189189- let libs = libs resolver lib_roots in
190190- compile_to_marshall ~output (pages, libs) files
121121+ | `Marshall -> compile_to_marshall ~output [ hierarchy ]
+1-2
src/odoc/indexing.mli
···1414 output:Fs.file ->
1515 warnings_options:Odoc_model.Error.warnings_options ->
1616 occurrences:Fs.file option ->
1717- lib_roots:(string * Fs.directory) list ->
1818- page_roots:(string * Fs.directory) list ->
1717+ roots:Fs.Directory.t list ->
1918 inputs_in_file:Fs.file list ->
2019 odocls:Fs.file list ->
2120 (unit, [> msg ]) result
+4-5
src/odoc/odoc_file.mli
···1919open Odoc_model
2020open Or_error
21212222-type unit_content = Lang.Compilation_unit.t
2323-2424-(** Either a page or a module. *)
2222+(** Either a page or a module or something else. *)
2523type content =
2624 | Page_content of Lang.Page.t
2725 | Impl_content of Lang.Implementation.t
2828- | Unit_content of unit_content
2626+ | Unit_content of Lang.Compilation_unit.t
2927 | Asset_content of Lang.Asset.t
30283129type t = { content : content; warnings : Error.t list }
···3533val save_page : Fs.File.t -> warnings:Error.t list -> Lang.Page.t -> unit
3634(** Save a page. The [page-] prefix is added to the file name if missing. *)
37353838-val save_unit : Fs.File.t -> warnings:Error.t list -> unit_content -> unit
3636+val save_unit :
3737+ Fs.File.t -> warnings:Error.t list -> Lang.Compilation_unit.t -> unit
3938(** Save a module. *)
40394140val save_impl :
···11+open Compatcmdliner
22+33+let run inp =
44+ let inp = Fpath.v inp in
55+ let index = Odoc_odoc.Odoc_file.load_index inp |> Result.get_ok in
66+ let rec tree_to_yojson
77+ ({ node; children } : Odoc_index.Entry.t Odoc_utils.Tree.t) :
88+ Yojson.Safe.t =
99+ let entry =
1010+ Odoc_json_index.Json_display.of_entry node [] |> Odoc_html.Json.to_string
1111+ in
1212+ `Assoc
1313+ [
1414+ ("node", `String entry);
1515+ ("children", `List (List.map tree_to_yojson children));
1616+ ]
1717+ in
1818+ List.iter
1919+ (fun s -> s |> tree_to_yojson |> Format.printf "%a" Yojson.Safe.pp)
2020+ index
2121+2222+let a_inp =
2323+ let doc = "Input file." in
2424+ Arg.(required & pos 0 (some file) None & info ~doc ~docv:"PATH" [])
2525+2626+let term =
2727+ let doc =
2828+ "Print the content of occurrences files into a text format. For tests"
2929+ in
3030+ Term.(const run $ a_inp, info "occurrences_print" ~doc)
3131+3232+let () =
3333+ match Term.eval term with
3434+ | `Ok () -> ()
3535+ | (`Version | `Help | `Error _) as x -> Term.exit x
+23-12
test/parent_id/missing_indexes.t/run.t
···77 $ odoc link _odoc/page-foo.odoc
88 $ odoc link _odoc/page-bar.odoc
99 $ odoc link _odoc/baz/page-bli.odoc
1010- $ odoc compile-index -P _:_odoc
1010+ $ odoc compile-index --root _odoc
1111 $ odoc sidebar-generate index.odoc-index
12121313 $ odoc html-generate --sidebar sidebar.odoc-sidebar --indent --output-dir _html _odoc/page-foo.odocl
14141515Missing index for Baz makes it unclickable but use the ID for the name.
1616-Root is used for the missing index in the unnamed root directory.
1717- $ cat _html/foo.html | grep Documentation -A 8
1818- <b>Documentation</b>
1919- <ul class="odoc-pages">
2020- <li>Root
2121- <ul><li><a href="bar.html">Bar</a></li>
2222- <li>baz<ul><li><a href="baz/bli.html">Bli</a></li></ul></li>
2323- <li><a href="#" class="current_unit">Foo</a></li>
2424- </ul>
2525- </li>
2626- </ul>
1616+Root is used for the missing index in the unnamed root directory. TODO
1717+ $ cat _html/foo.html
1818+ <!DOCTYPE html>
1919+ <html xmlns="http://www.w3.org/1999/xhtml">
2020+ <head><title>foo (foo)</title><meta charset="utf-8"/>
2121+ <link rel="stylesheet" href="odoc.css"/>
2222+ <meta name="generator" content="odoc %%VERSION%%"/>
2323+ <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
2424+ <script src="highlight.pack.js"></script>
2525+ <script>hljs.initHighlightingOnLoad();</script>
2626+ </head>
2727+ <body class="odoc">
2828+ <header class="odoc-preamble">
2929+ <h1 id="foo"><a href="#foo" class="anchor"></a>Foo</h1>
3030+ </header>
3131+ <div class="odoc-tocs">
3232+ <nav class="odoc-toc odoc-global-toc"><a href="index.html">index</a>
3333+ <ul><li><a href="#" class="current_unit">Foo</a></li></ul>
3434+ </nav>
3535+ </div><div class="odoc-content"></div>
3636+ </body>
3737+ </html>
···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
20202121- $ odoc compile-index -P pkg:_odoc/pkg/ -L libname:_odoc/pkg/libname
2121+ $ odoc compile-index --root _odoc/pkg/
2222 $ odoc sidebar-generate index.odoc-index
23232424 $ odoc html-generate --indent --sidebar sidebar.odoc-sidebar -o html _odoc/pkg/page-file.odocl
···30303131 $ cat html/pkg/index.html | grep odoc-global-toc -A 15
3232 <nav class="odoc-toc odoc-global-toc">
3333- <ul class="odoc-modules">
3434- <li><b>Library <code>libname</code></b>
3535- <ul><li><a href="libname/Unit/index.html">Unit</a></li></ul>
3636- </li>
3737- </ul><b>Documentation</b>
3838- <ul class="odoc-pages">
3939- <li><a href="#" class="current_unit">Package <code>pkg</code></a>
4040- <ul>
4141- <li><a href="dir1/index.html">A directory</a>
4242- <ul><li><a href="dir1/my_page.html">My page</a></li></ul>
4343- </li><li><a href="file.html">File</a></li>
4444- </ul>
4545- </li>
3333+ <a href="#" class="current_unit">index</a>
3434+ <ul><li><a href="dir1/index.html">A directory</a></li>
3535+ <li><a href="file.html">File</a></li>
3636+ <li><a href="libname/index.html">Library landing page</a></li>
4637 </ul>
4738 </nav>
3939+ </div><div class="odoc-content"></div>
4040+ </body>
4141+ </html>
48424943As we can see, "Library landing page" has NOT been added to the sidebar, in the "documentation" side.
+5-8
test/search/html_search.t/run.t
···6565passing directly the name of the files.
66666767 $ printf "main.odocl\npage-page.odocl\nj.odocl\n" > index_map
6868- $ odoc compile-index --json -o index.json -P pkgname:.
6868+ $ odoc compile-index --json -o index.json --root .
69697070- $ odoc compile-index -o index-main.odoc-index -P pkgname:.
7070+ $ odoc compile-index -o index-main.odoc-index --root .
71717272The json index file contains a json array, each element of the array corresponding to
7373a search entry.
···214214215215Passing an inexistent file:
216216217217- $ odoc compile-index -P pkgname:babar
217217+ $ odoc compile-index --root babar
218218 $ odoc compile-index --file-list babar
219219 odoc: option '--file-list': no 'babar' file or directory
220220 Usage: odoc compile-index [--file-list=FILE] [--json] [OPTION]… [FILE]…
···224224Passing an empty folder is allowed:
225225226226 $ mkdir foo
227227- $ odoc compile-index -P pkgname:foo
227227+ $ odoc compile-index --root foo
228228229229Wrong file extensions:
230230···241241Passing a file which is not a correctly marshalled one:
242242243243 $ echo hello > my_file.odocl
244244- $ odoc compile-index -P pkgname:.
245245- File "./my_file.odocl":
246246- Warning: Error while unmarshalling "./my_file.odocl": End_of_file
247247-244244+ $ odoc compile-index --root .
248245249246250247Passing no file is allowed, generating an empty index:
+1-1
test/search/id_standalone_comments.t/run.t
···77 $ odoc compile -I . main.cmt
88 $ odoc link -I . main.odoc
991010- $ odoc compile-index --json -P pkgname:./
1010+ $ odoc compile-index --json --root ./
1111We test that you can also pass a .odocl file directly.
1212 $ odoc compile-index --json main.odocl -o index2.json
1313Indexes should be the same no matter how the inputs were passed.
+1-1
test/search/module_aliases.t/run.t
···6677 $ odoc compile main.cmt
88 $ odoc link main.odoc
99- $ odoc compile-index --json -P pkgname:.
99+ $ odoc compile-index --json --root .
10101111Search results only redirect to their definition point (not the
1212expansions). Comments link to the expansion they are in.