blob: 797c4053db569cdd78086c6f98843a9f91164326 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
type head_data = { page_title : string }
type body_data = {
title : string Lwt.t;
subtitle : string;
topnav : Dream_html.node;
content : Dream_html.node list;
}
module Layout = struct
open Dream_html
open HTML
let header title subtitle =
null [ h1 [] [ txt "%s" title ]; h2 [] [ txt "%s" subtitle ] ]
let footer =
let today = Unix.localtime (Unix.time ()) in
let year = today.Unix.tm_year + 1900 |> string_of_int in
let space = " " in
let footer_text =
String.concat space [ "Copyright"; year; Config.author ]
in
footer [] [ txt "%s" footer_text ]
let head_data = { page_title = "Ogit" }
let application ?(head_data = head_data) body_data =
html []
[
head []
[
title [] "%s" head_data.page_title;
link [ rel "stylesheet"; href "/static/styles.css" ];
];
body []
[
header "Ogit" body_data.subtitle;
body_data.topnav;
div [ id "main" ] body_data.content;
footer;
];
]
end
module Ogit_root = struct
open Dream_html
open HTML
let repositories_in directory =
let repositories = Sys.readdir directory |> Array.to_list
and li_of_repo repo = li [] [ a [ href "%s" repo ] [ txt "%s" repo ] ] in
div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repositories ]
let body_data =
{
title = Lwt.return "My repositories";
subtitle = "Repositories for " ^ Config.author;
topnav = null [];
content = [ repositories_in Config.git_directory ];
}
let render () = Lwt.return @@ Layout.application body_data
end
module Repo_root = struct
open Dream_html
open HTML
let topnav =
nav
[ id "top" ]
[
ul []
[
li [] [ a [ href "/" ] [ txt "summary" ] ];
li [] [ a [ href "/" ] [ txt "refs" ] ];
li [] [ a [ href "/" ] [ txt "log" ] ];
li [] [ a [ href "/" ] [ txt "tree" ] ];
li [] [ a [ href "/" ] [ txt "commit" ] ];
li [] [ a [ href "/" ] [ txt "diff" ] ];
];
]
let render repo_name =
let title = Git_helpers.get_head_commit_hash repo_name in
let subtitle = "Repository" in
let content = [ null [] ] in
let body_data = { title; subtitle; topnav; content } in
Lwt.return @@ Layout.application body_data
end
module Repo_tree = struct
open Dream_html
open HTML
let render repo_name =
let title = repo_name and content = [ txt "foobar" ] in
let subtitle = "Dinglefops" in
let topnav = null [] in
let body_data = { title; subtitle; topnav; content } in
Lwt.return @@ Layout.application body_data
end
|