Skip to content
Snippets Groups Projects
Commit a685b19a authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[server] index by categories

parent 0035db92
No related branches found
No related tags found
No related merge requests found
...@@ -120,17 +120,42 @@ let table_of_contents () = ...@@ -120,17 +120,42 @@ let table_of_contents () =
(fun p -> table_of_chapter (`Plugin p)) (fun p -> table_of_chapter (`Plugin p))
(List.sort String.compare !plugins)) (List.sort String.compare !plugins))
module Cmap = Map.Make
(struct
type t = string list
let compare = Pervasives.compare
end)
let index_entry (title,href) =
text @@ Markdown.href ~text:(plain title) href
let index () = let index () =
List.map let category name =
(fun (title,entry) -> Markdown.href ~text:(plain title) entry) match List.rev (String.split_on_char '.' name) with
(List.sort | [] -> []
(fun (e1, _) (e2, _) -> | _::rpath -> List.rev rpath in
let entry e = let cmap =
match List.rev (String.split_on_char '.' e) with List.fold_left
| [] -> [],e (fun cs entry ->
| a::rpath -> List.rev rpath , a let c = category (fst entry) in
in Pervasives.compare (entry e1) (entry e2)) let es = try Cmap.find c cs with Not_found -> [] in
!entries) Cmap.add c (entry :: es) cs)
Cmap.empty !entries in
let by_name (a,_) (b,_) = String.compare a b in
let categories = Cmap.fold
(fun c es ces -> ( c , List.sort by_name es ) :: ces)
cmap [] in
begin
List.fold_left
(fun elements (c,es) ->
let entries = Block (list @@ List.map index_entry es) :: elements in
if c = [] then entries
else
let cname = String.concat "." c in
let title = Printf.sprintf "Index of `%s`" cname in
H3(plain title,None) :: entries
) [] categories
end
let link ~toc ~title ~href : json = let link ~toc ~title ~href : json =
let link = [ "title" , `String title ; "href" , `String href ] in let link = [ "title" , `String title ; "href" , `String href ] in
...@@ -200,8 +225,9 @@ let dump ~root ?(meta=true) () = ...@@ -200,8 +225,9 @@ let dump ~root ?(meta=true) () =
@ @
table_of_contents () table_of_contents ()
@ @
[H2 (plain "Index", None); [H2 (plain "Index", None)]
Block (list (List.map text (index ())))] @
index ()
in in
let title = "Documentation" in let title = "Documentation" in
pp_one_page ~root ~page:"readme.md" ~title body pp_one_page ~root ~page:"readme.md" ~title body
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment