Skip to content

Commit

Permalink
Children order: Remove common root using ID not URL segments
Browse files Browse the repository at this point in the history
  • Loading branch information
panglesd authored and jonludlam committed Oct 4, 2024
1 parent bc08c07 commit d8980ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/document/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module Toc : sig

val of_lang : Odoc_model.Sidebar.PageToc.t -> t

val remove_common_root : t -> t
(** Returns the deepest subdir containing all files. *)

val to_sidebar :
?fallback:string -> (Url.Path.t * Inline.one -> Block.one) -> t -> Block.t
end = struct
Expand Down Expand Up @@ -56,10 +53,6 @@ end = struct
in
of_lang ~parent_id:None dir

let rec remove_common_root = function
| Item (_, [ d ]) -> remove_common_root d
| x -> x

let rec to_sidebar ?(fallback = "root") convert (Item (name, content)) =
let name =
match name with
Expand All @@ -83,7 +76,7 @@ type t = { pages : pages list; libraries : library list }
let of_lang (v : Odoc_model.Sidebar.t) =
let pages =
let page_hierarchy { Odoc_model.Sidebar.hierarchy_name; pages } =
let hierarchy = Toc.of_lang pages |> Toc.remove_common_root in
let hierarchy = Toc.of_lang pages in
Some { name = hierarchy_name; pages = hierarchy }
in
Odoc_utils.List.filter_map page_hierarchy v.pages
Expand Down
5 changes: 4 additions & 1 deletion src/model/sidebar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ module PageToc = struct
let contents = ordered @ unordered in
(contents, index)

let rec remove_common_root (v : t) =
match v with [ (_, Dir v) ], None -> remove_common_root v | _ -> v

let of_list l =
let dir = empty_t None in
List.iter (add dir) l;
t_of_in_progress dir
t_of_in_progress dir |> remove_common_root
end

type toc = PageToc.t
Expand Down

0 comments on commit d8980ff

Please sign in to comment.