feat display README from git_project_root on the index page

Commit
c6c56606b5a148c30fa7de66b1232c77213d7141
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
lib/handlers.ml
index 548b2568..a6ae47d4 100644..100644
@@ -44,8 +44,9 @@
44 44 Lwt.return (path, date))
45 45 repo_paths
46 46 in
47 Added: let readme = Resolvers.read_root_readme config in
47 48 Views.root ~user:config.Config.user ~root_title:(root_title config) ~dates
48 Removed: nodes
49 Added: ?readme nodes
49 50 | Error error -> error_response error
50 51
51 52 module Repo = struct
lib/resolvers.ml
index f174988d..c7f4cbd2 100644..100644
@@ -661,3 +661,18 @@
661 661 | _ -> Lwt_result.fail (Internal ("could not read file " ^ readme.name))
662 662 )
663 663 end
664 Added:
665 Added: let read_root_readme config =
666 Added: let readme_candidates =
667 Added: [ "README"; "README.md"; "README.org"; "README.txt" ]
668 Added: in
669 Added: let rec try_candidates = function
670 Added: | [] -> None
671 Added: | name :: rest -> (
672 Added: let path = Filename.concat config.Config.git_project_root name in
673 Added: try
674 Added: let content = In_channel.with_open_text path In_channel.input_all in
675 Added: Some { Blob.content }
676 Added: with Sys_error _ -> try_candidates rest)
677 Added: in
678 Added: try_candidates readme_candidates
lib/resolvers.mli
index 793b811c..05353528 100644..100644
@@ -127,3 +127,7 @@
127 127 module Repo : sig
128 128 val readme : repository -> (Blob.t option, error) Lwt_result.t
129 129 end
130 Added:
131 Added: (** {1 Root helpers} *)
132 Added:
133 Added: val read_root_readme : Config.t -> Blob.t option
lib/views/root.ml
index d92d041b..3558b297 100644..100644
@@ -55,13 +55,40 @@
55 55 ];
56 56 ])
57 57
58 Removed: let render ~user ~root_title ~dates nodes =
58 Added: let render ~user ~root_title ~dates ?readme nodes =
59 59 let tree =
60 60 HTML.(
61 61 div
62 62 [ id "repositories" ]
63 63 [ ul [] (List.map (li_of_fs_node ~prefix:"" ~dates) nodes) ])
64 64 in
65 Added: let readme_section =
66 Added: match readme with
67 Added: | None -> HTML.null []
68 Added: | Some (blob : Resolvers.Blob.t) ->
69 Added: let formatted =
70 Added: String.split_on_char '\n' blob.content
71 Added: |> List.mapi (fun number line ->
72 Added: let line_number = number + 1 in
73 Added: HTML.
74 Added: [
75 Added: a
76 Added: [
77 Added: id "readme-%d" line_number;
78 Added: class_ "line-anchor";
79 Added: href "#readme-%d" line_number;
80 Added: Aria.label "Line %d" line_number;
81 Added: ]
82 Added: [ txt "%d" line_number ];
83 Added: span [ class_ "line" ] [ txt "\t%s\n" line ];
84 Added: ])
85 Added: |> List.concat
86 Added: in
87 Added: HTML.(
88 Added: section
89 Added: [ class_ "readme-inline" ]
90 Added: [ h3 [] [ txt "README" ]; div [ class_ "blob" ] formatted ])
91 Added: in
65 92 respond
66 93 @@ Layout.render ~user ~root_title
67 94 {
@@ -69,5 +96,5 @@
69 96 repo = None;
70 97 subtitle = "";
71 98 active = Summary;
72 Removed: content = [ tree ];
99 Added: content = [ tree; readme_section ];
73 100 }