[OCaml] Mobile-friendly clone of cgit.
revert remove clickable pill commit filter feature
Revert the pill from <a> back to <span>. The nested <a> inside the commit row <a> produced invalid HTML that browsers rendered as a full-width block element. Remove: handle_with_request, type_filter query parameter, filter_bar, commit_type_of, commit-row/commit-link CSS, filter-bar/filter-clear CSS, a.commit-pill styles, and the router filter test. The pill remains as a styled <span> for visual labeling only.
lib/handlers.ml
@@ -44,10 +44,6 @@
44
44
45
45
let handle config handler _request name = with_repository config name handler
46
46
47
Removed:
let handle_with_request config handler request name =
48
Removed:
with_repository config name (fun repository context ->
49
Removed:
handler request repository context)
50
Removed:
51
47
let handle_id config handler _request name id =
52
48
with_repository config name (fun repository context ->
53
49
handler repository context id)
@@ -59,12 +55,11 @@
59
55
in
60
56
Views.Repo.summary context branches commits
61
57
62
Removed:
let commits config request repository context =
58
Added:
let commits config repository context =
63
59
let* commits =
64
60
Resolvers.Commit.recent repository config.Config.commits_max_displayed
65
61
in
66
Removed:
let type_filter = Dream.query request "type" in
67
Removed:
Views.Repo.commits context ?type_filter commits
62
Added:
Views.Repo.commits context commits
68
63
69
64
let commits_branch config repository context branch =
70
65
let* reference = Resolvers.Reference.of_id repository branch in
@@ -120,8 +115,7 @@
120
115
get Routes.root_path (root config);
121
116
get Routes.repo_root_path (Repo.handle config (Repo.summary config));
122
117
get Routes.repo_path (Repo.handle config (Repo.summary config));
123
Removed:
get Routes.commits_path
124
Removed:
(Repo.handle_with_request config (Repo.commits config));
118
Added:
get Routes.commits_path (Repo.handle config (Repo.commits config));
125
119
get Routes.commits_branch_path
126
120
(Repo.handle_id config (Repo.commits_branch config));
127
121
get Routes.commit_path (Repo.handle_id config Repo.commit_id);
lib/static/styles.css
@@ -183,7 +183,7 @@
183
183
border: none;
184
184
}
185
185
186
Removed:
div#main ul li a {
186
Added:
div#main ul li > a {
187
187
display: flex;
188
188
align-items: center;
189
189
justify-content: space-between;
@@ -222,15 +222,13 @@
222
222
223
223
.commit-pill {
224
224
display: inline-block;
225
Removed:
padding: 0.15em 0.5em;
226
Removed:
border-radius: 1em;
227
Removed:
font-size: 0.75em;
225
Added:
padding: 0.15em 0.4em;
226
Added:
border-radius: 0.75em;
227
Added:
font-size: 0.7em;
228
228
font-weight: 600;
229
229
text-transform: uppercase;
230
Removed:
letter-spacing: 0.03em;
231
Removed:
margin-right: 0.5em;
230
Added:
margin-right: 0.4em;
232
231
vertical-align: middle;
233
Removed:
flex-shrink: 0;
234
232
}
235
233
236
234
.commit-pill-feat {
@@ -286,36 +284,6 @@
286
284
.commit-pill-revert {
287
285
background-color: #4d1a3a;
288
286
color: #f9a8d4;
289
Removed:
}
290
Removed:
291
Removed:
.filter-bar {
292
Removed:
display: flex;
293
Removed:
align-items: center;
294
Removed:
gap: 0.5em;
295
Removed:
padding: 0.5em 0.75em;
296
Removed:
margin-bottom: 0.5em;
297
Removed:
background: #222;
298
Removed:
border-radius: 0.25rem;
299
Removed:
border: 1px solid #3a3a3a;
300
Removed:
}
301
Removed:
302
Removed:
.filter-clear {
303
Removed:
color: #999;
304
Removed:
text-decoration: none;
305
Removed:
font-size: 1.2em;
306
Removed:
line-height: 1;
307
Removed:
}
308
Removed:
309
Removed:
.filter-clear:hover {
310
Removed:
color: white;
311
Removed:
}
312
Removed:
313
Removed:
a.commit-pill {
314
Removed:
text-decoration: none;
315
Removed:
}
316
Removed:
317
Removed:
a.commit-pill:hover {
318
Removed:
opacity: 0.8;
319
287
}
320
288
321
289
.commit-title {
lib/views/repo.ml
@@ -119,13 +119,7 @@
119
119
match commit_type with
120
120
| None -> HTML.null []
121
121
| Some ct ->
122
Removed:
HTML.(
123
Removed:
a
124
Removed:
[
125
Removed:
href "/%s/commits/?type=%s" repo ct;
126
Removed:
class_ "commit-pill commit-pill-%s" ct;
127
Removed:
]
128
Removed:
[ txt "%s" ct ])
122
Added:
HTML.(span [ class_ "commit-pill commit-pill-%s" ct ] [ txt "%s" ct ])
129
123
in
130
124
let title_span =
131
125
HTML.(span [ class_ "commit-title" ] [ txt "%s" commit_title ])
@@ -163,39 +157,9 @@
163
157
ul [] (List.map (li_of_commit context.repo) commits);
164
158
]
165
159
166
Removed:
let commit_type_of (commit : Resolvers.Commit.t) =
167
Removed:
let message = parse_commit_message commit.message in
168
Removed:
fst (parse_conventional message.summary)
169
Removed:
170
Removed:
let filter_bar context type_filter =
171
Removed:
HTML.(
172
Removed:
div
173
Removed:
[ class_ "filter-bar" ]
174
Removed:
[
175
Removed:
span
176
Removed:
[ class_ "commit-pill commit-pill-%s" type_filter ]
177
Removed:
[ txt "%s" type_filter ];
178
Removed:
a
179
Removed:
[
180
Removed:
href "/%s/commits/" context.repo;
181
Removed:
class_ "filter-clear";
182
Removed:
Aria.label "Clear filter";
183
Removed:
]
184
Removed:
[ txt "\xc3\x97" ];
185
Removed:
])
186
Removed:
187
Removed:
let commits context ?type_filter all_commits =
188
Removed:
let commits =
189
Removed:
match type_filter with
190
Removed:
| None -> all_commits
191
Removed:
| Some ft ->
192
Removed:
List.filter (fun commit -> commit_type_of commit = Some ft) all_commits
193
Removed:
in
194
Removed:
let header =
195
Removed:
match type_filter with None -> [] | Some ft -> [ filter_bar context ft ]
196
Removed:
in
160
Added:
let commits context commits =
197
161
render_page context ~active:Commits
198
Removed:
(header @ HTML.[ ul [] (List.map (li_of_commit context.repo) commits) ])
162
Added:
HTML.[ ul [] (List.map (li_of_commit context.repo) commits) ]
199
163
200
164
let breadcrumbs repo (trail : (string * string) list) =
201
165
let root_link = HTML.li [] [ Routes.link_to (Files repo) (txt "Home") ] in
test/test_router.ml
@@ -58,33 +58,6 @@
58
58
let status = Dream.request ~target "" |> request |> Dream.status in
59
59
Alcotest.(check int) "404" 404 (Dream.status_to_int status))
60
60
61
Removed:
let test_commits_type_filter () =
62
Removed:
with_temp_directory "ogit-router" (fun root ->
63
Removed:
let name = "project" in
64
Removed:
let path = Filename.concat root name in
65
Removed:
Unix.mkdir path 0o755;
66
Removed:
ignore (git [ "-C"; path; "init"; "-q"; "-b"; "main" ]);
67
Removed:
ignore (git [ "-C"; path; "config"; "user.name"; "Test" ]);
68
Removed:
ignore (git [ "-C"; path; "config"; "user.email"; "t@t.invalid" ]);
69
Removed:
Out_channel.with_open_text (Filename.concat path "f.txt") (fun ch ->
70
Removed:
output_string ch "x\n");
71
Removed:
ignore (git [ "-C"; path; "add"; "." ]);
72
Removed:
ignore (git [ "-C"; path; "commit"; "-q"; "-m"; "feat: initial" ]);
73
Removed:
let config = Ogit.Config.{ default with git_project_root = root } in
74
Removed:
let request = Dream.test (Dream.router (Ogit.Handlers.routes config)) in
75
Removed:
(* Valid filter returns 200 *)
76
Removed:
let status =
77
Removed:
Dream.request ~target:"/project/commits/?type=feat" ""
78
Removed:
|> request |> Dream.status
79
Removed:
in
80
Removed:
Alcotest.(check int) "filter feat 200" 200 (Dream.status_to_int status);
81
Removed:
(* Unknown filter returns 200 with empty list, not an error *)
82
Removed:
let status =
83
Removed:
Dream.request ~target:"/project/commits/?type=xyz" ""
84
Removed:
|> request |> Dream.status
85
Removed:
in
86
Removed:
Alcotest.(check int) "filter unknown 200" 200 (Dream.status_to_int status))
87
Removed:
88
61
let suite =
89
62
( "router",
90
63
[
@@ -92,5 +65,4 @@
92
65
Alcotest.test_case "missing repo" `Slow test_missing_repo;
93
66
Alcotest.test_case "invalid hash" `Slow test_invalid_hash;
94
67
Alcotest.test_case "missing object" `Slow test_missing_object;
95
Removed:
Alcotest.test_case "commits type filter" `Slow test_commits_type_filter;
96
68
] )