Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
panglesd committed Oct 15, 2024
1 parent e3fe2e8 commit 9ccc10d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
29 changes: 19 additions & 10 deletions src/document/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,30 @@ end = struct
end

type pages = { name : string; pages : Toc.t }
type library = { name : string; units : Toc.t }
type library = { name : string; units : Toc.t list }

type t = { pages : pages list; libraries : library list }

let of_lang (v : Odoc_index.Index.t) =
let { Odoc_index.Index.sidebar = v; index } = v in
let { Odoc_index.Index.pages; libs } = v in
let pages =
let page_hierarchy { Odoc_model.Sidebar.hierarchy_name; pages } =
let hierarchy = Toc.of_lang pages in
Some { name = hierarchy_name; pages = hierarchy }
let page_hierarchy { Odoc_index.Index.p_name; p_hierarchy } =
let hierarchy = Toc.of_lang p_hierarchy in
{ name = p_name; pages = hierarchy }
in
Odoc_utils.List.filter_map page_hierarchy v.pages
Odoc_utils.List.map page_hierarchy pages
in
let units =
List.map (fun sk -> { units = Toc.of_skeleton sk; name = "yo" }) index
let libraries =
let lib_hierarchies { Odoc_index.Index.l_name; l_hierarchies } =
let hierarchies = List.map Toc.of_skeleton l_hierarchies in
{ units = hierarchies; name = l_name }
in
Odoc_utils.List.map lib_hierarchies libs
in
{ pages; libraries = units }
(* let units = *)
(* List.map (fun sk -> { units = Toc.of_skeleton sk; name = "yo" }) libs *)
(* in *)
{ pages; libraries }

let to_block (sidebar : t) path =
let { pages; libraries } = sidebar in
Expand All @@ -165,7 +172,9 @@ let to_block (sidebar : t) path =
let units =
List.map
(fun { units; name } ->
let units = Toc.to_block ~prune:true path units in
let units =
List.concat_map ~f:(Toc.to_block ~prune:true path) units
in
let units = [ block (Block.List (Block.Unordered, [ units ])) ] in
let units = [ title @@ name ^ "'s Units" ] @ units in
units)
Expand Down
8 changes: 4 additions & 4 deletions src/model/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ module PageToc = struct
t_of_in_progress dir |> remove_common_root
end

type toc = PageToc.t
(* type toc = PageToc.t *)

type library = { name : string; units : Paths.Identifier.RootModule.t list }
(* type library = { name : string; units : Paths.Identifier.RootModule.t list } *)

type page_hierarchy = { hierarchy_name : string; pages : toc }
(* type page_hierarchy = { hierarchy_name : string; pages : toc } *)

type t = { pages : page_hierarchy list; libraries : library list }
(* type t = { pages : page_hierarchy list; libraries : library list } *)
6 changes: 3 additions & 3 deletions src/model/sidebar.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module PageToc : sig
container directory to output a payload *)
end

type library = { name : string; units : Id.RootModule.t list }
(* type library = { name : string; units : Id.RootModule.t list } *)

type page_hierarchy = { hierarchy_name : string; pages : PageToc.t }
(* type page_hierarchy = { hierarchy_name : string; pages : PageToc.t } *)

type t = { pages : page_hierarchy list; libraries : library list }
(* type t = { pages : page_hierarchy list; libraries : library list } *)
10 changes: 6 additions & 4 deletions src/odoc/indexing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module H = Odoc_model.Paths.Identifier.Hashtbl.Any
let handle_file file ~unit ~page ~occ =
match Fpath.basename file with
| s when String.is_prefix ~affix:"index-" s ->
Odoc_file.load_index file >>= fun { index; _ } -> Ok (occ index)
Odoc_file.load_index file >>= fun { libs; _ } -> Ok (occ (* index *) libs)
| _ -> (
Odoc_file.load file >>= fun unit' ->
match unit' with
Expand Down Expand Up @@ -151,7 +151,7 @@ let compile out_format ~output ~warnings_options ~occurrences ~lib_roots
List.map
(fun (page_root, _) ->
let pages = Resolver.all_pages ~root:page_root resolver in
let pages =
let p_hierarchy =
let pages =
pages
|> List.filter_map
Expand All @@ -175,13 +175,15 @@ let compile out_format ~output ~warnings_options ~occurrences ~lib_roots
in
PageToc.of_list pages
in
{ hierarchy_name = page_root; pages })
{ Odoc_index.Index.p_name = page_root; p_hierarchy })
page_roots
in
let libraries =
List.map
(fun (library, _) ->
{ name = library; units = Resolver.all_units ~library resolver })
let units = Resolver.all_units ~library resolver in
let node = List.map Odoc_index.Skeleton.from_unit u in
{ Odoc_index.Index.l_name = library; l_hierarchies = _ })
lib_roots
in
let includes_rec =
Expand Down
15 changes: 11 additions & 4 deletions src/search/index.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
type t = {
sidebar : Odoc_model.Sidebar.t;
index : Entry.t Odoc_utils.Tree.t list;
}
open Odoc_model
open Odoc_utils

type title = Comment.link_content
type page_hierarchy = (Paths.Identifier.Page.t * title) option Tree.t
type page = { p_name : string; p_hierarchy : page_hierarchy }

type lib_hierarchies = Entry.t Tree.t list
type lib = { l_name : string; l_hierarchies : lib_hierarchies }

type t = { pages : page list; libs : lib list }

0 comments on commit 9ccc10d

Please sign in to comment.