Skip to content

Commit

Permalink
Sidebar: sort by kind first
Browse files Browse the repository at this point in the history
  • Loading branch information
panglesd committed Dec 5, 2024
1 parent ce570b5 commit d9d70b7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index/skeleton_of.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ module ModuleName = Odoc_model.Names.ModuleName

type t = Entry.t Tree.t

let compare_entry (e1 : Entry.t) (e2 : Entry.t) =
let int_of_kind (kind : Entry.kind) =
match kind with
| Page _ -> -10
| Dir -> 0
| Module _ -> 10
| Impl -> 20
| _ -> 30
in
match Int.compare (int_of_kind e1.kind) (int_of_kind e2.kind) with
| 0 -> Astring.String.compare (Id.name e1.id) (Id.name e2.id)
| i -> i

let rec t_of_in_progress (dir : In_progress.in_progress) : t =
let entry_of_page page =
let kind = Entry.Page page.Lang.Page.frontmatter in
Expand Down Expand Up @@ -145,10 +158,7 @@ let rec t_of_in_progress (dir : In_progress.in_progress) : t =
|> List.map snd
in
let unordered =
List.sort
(fun (x, _) (y, _) ->
String.compare (Paths.Identifier.name x) (Paths.Identifier.name y))
unordered
List.sort (fun (_, x) (_, y) -> compare_entry x.Tree.node y.node) unordered
in
let contents = ordered @ unordered |> List.map snd in
{ Tree.node = index; children = contents }
Expand Down

0 comments on commit d9d70b7

Please sign in to comment.