[OCaml] Mobile-friendly clone of cgit.
Initial commit for ogit.
Changed files
bin/dune
@@ -0,0 +1,6 @@
1
Added:
(executable
2
Added:
(public_name ogit)
3
Added:
(name main)
4
Added:
(libraries
5
Added:
dream
6
Added:
ogit.handlers))
bin/main.ml
@@ -0,0 +1,10 @@
1
Added:
(* ogit: A lightweight, mobile-friendly alternative to cgit *)
2
Added:
3
Added:
let () =
4
Added:
Dream.run
5
Added:
@@ Dream.logger
6
Added:
@@ Dream.router [
7
Added:
Dream.get "/" Handlers.root;
8
Added:
Dream.get "/:repo_name/" Handlers.repo_root;
9
Added:
Dream.get "/:repo_name/tree" Handlers.repo_tree;
10
Added:
]
dune-project
@@ -0,0 +1,30 @@
1
Added:
(lang dune 3.16)
2
Added:
3
Added:
(name ogit)
4
Added:
5
Added:
(generate_opam_files true)
6
Added:
7
Added:
(source
8
Added:
(github username/reponame))
9
Added:
10
Added:
(authors "Marius Peter")
11
Added:
12
Added:
(maintainers "Marius Peter")
13
Added:
14
Added:
(license LICENSE)
15
Added:
16
Added:
(documentation https://url/to/documentation)
17
Added:
18
Added:
(package
19
Added:
(name ogit)
20
Added:
(synopsis "Replacement for cgit")
21
Added:
(description "A longer description")
22
Added:
(depends
23
Added:
ocaml
24
Added:
dune
25
Added:
dream
26
Added:
git)
27
Added:
(tags
28
Added:
(topics "to describe" your project)))
29
Added:
30
Added:
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
lib/handlers/dune
@@ -0,0 +1,8 @@
1
Added:
(library
2
Added:
(name handlers)
3
Added:
(public_name ogit.handlers)
4
Added:
(libraries
5
Added:
dream
6
Added:
ogit.helpers
7
Added:
ogit.layouts)
8
Added:
(modules handlers))
lib/handlers/handlers.ml
@@ -0,0 +1,43 @@
1
Added:
(* Page layout function *)
2
Added:
let page_layout ~content =
3
Added:
"<html><body>"
4
Added:
^ Layouts.Header.header ()
5
Added:
^ Layouts.Topnav.topnav ()
6
Added:
^ "<main>" ^ content ^ "</main>"
7
Added:
^ "</body></html>"
8
Added:
9
Added:
let root _ =
10
Added:
let content =
11
Added:
"<h1>Available Repositories</h1><ul>"
12
Added:
^ Helpers.Html_helpers.generate_repo_links ()
13
Added:
^ "</ul>"
14
Added:
in
15
Added:
Dream.html (page_layout ~content)
16
Added:
17
Added:
let repo_root _ =
18
Added:
(* let repo_name = Dream.param request "repo_name" in *)
19
Added:
let content =
20
Added:
"<div class=\"content\"><table summary=\"repository info\" class=\"list nowrap\"><tbody>\n"
21
Added:
^ "<tr class=\"nohover\"><th class=\"left\">Branch</th><th class=\"left\">Commit message</th><th class=\"left\">Author</th><th class=\"left\" colspan=\"2\">Age</th></tr>\n"
22
Added:
^ "<tr><td><a href=\"/wtt.git/log/\">master</a></td><td><a href=\"/wtt.git/commit/\">Ensure session[:id] before scoring: all tests now pass.</a></td><td>Marius Peter</td><td colspan=\"2\"><span class=\"age-weeks\" title=\"2025-01-02 19:11:34 +0100\">2 weeks</span></td></tr>\n"
23
Added:
^ "<tr class=\"nohover\"><td colspan=\"3\"> </td></tr>\n"
24
Added:
^ "<tr class=\"nohover\"><th class=\"left\">Tag</th><th class=\"left\">Download</th><th class=\"left\">Author</th><th class=\"left\" colspan=\"2\">Age</th></tr>\n"
25
Added:
^ "<tr><td><a href=\"/wtt.git/tag/?h=v1.0\">v1.0</a></td><td><a href=\"/wtt.git/commit/?id=175111f9d84354dce00503525649197e9acb6382\">commit 175111f9d8...</a></td><td>Marius Peter</td><td colspan=\"2\"><span class=\"age-weeks\" title=\"2025-01-02 13:58:46 +0100\">2 weeks</span></td></tr>\n"
26
Added:
^ "<tr class=\"nohover\"><td colspan=\"3\"> </td></tr>\n"
27
Added:
^ "<tr class=\"nohover\"><th class=\"left\">Age</th><th class=\"left\">Commit message</th><th class=\"left\">Author</th></tr>\n"
28
Added:
^ "<tr><td><span title=\"2025-01-02 19:11:34 +0100\">2025-01-02</span></td><td><a href=\"/wtt.git/commit/?id=b34d2b51174b511d59fa324d9f42abc75a1fa09a\">Ensure session[:id] before scoring: all tests now pass.</a><span class=\"decoration\"><a class=\"deco\" href=\"/wtt.git/commit/?id=b34d2b51174b511d59fa324d9f42abc75a1fa09a\">HEAD</a><a class=\"branch-deco\" href=\"/wtt.git/log/\">master</a></span></td><td>Marius Peter</td></tr>\n"
29
Added:
^ "</tbody></table></div>"
30
Added:
in
31
Added:
Dream.html (page_layout ~content)
32
Added:
33
Added:
let repo_tree request =
34
Added:
let repo_name = Dream.param request "repo_name" in
35
Added:
let repo_path = Filename.concat (Unix.getenv "HOME") ("git/" ^ repo_name) in
36
Added:
let content =
37
Added:
if Sys.file_exists repo_path && Sys.is_directory repo_path then
38
Added:
let files = Helpers.File_helpers.list_files repo_path in
39
Added:
"<h1>Browsing repository: " ^ repo_name ^ "</h1><ul>" ^ files ^ "</ul>"
40
Added:
else
41
Added:
"<h1>Repository not found: " ^ repo_name ^ "</h1>"
42
Added:
in
43
Added:
Dream.html (page_layout ~content)
lib/helpers/dune
@@ -0,0 +1,9 @@
1
Added:
(library
2
Added:
(name helpers)
3
Added:
(public_name ogit.helpers)
4
Added:
(libraries
5
Added:
unix
6
Added:
ogit.layouts)
7
Added:
(modules
8
Added:
html_helpers
9
Added:
file_helpers))
lib/helpers/file_helpers.ml
@@ -0,0 +1,7 @@
1
Added:
let list_files dir =
2
Added:
try
3
Added:
Array.to_list (Sys.readdir dir)
4
Added:
|> List.map (fun file -> Printf.sprintf "<li>%s</li>" file)
5
Added:
|> String.concat ""
6
Added:
with _ ->
7
Added:
"<li>Error: Unable to read directory</li>"
lib/helpers/html_helpers.ml
@@ -0,0 +1,18 @@
1
Added:
(* Helper function to generate links for repositories *)
2
Added:
let generate_repo_links () =
3
Added:
let git_dir = Filename.concat (Unix.getenv "HOME") "git" in
4
Added:
if Sys.file_exists git_dir && Sys.is_directory git_dir then
5
Added:
Sys.readdir git_dir
6
Added:
|> Array.to_list
7
Added:
|> List.map (fun repo -> Printf.sprintf "<li><a href='/%s/tree'>%s</a></li>" repo repo)
8
Added:
|> String.concat ""
9
Added:
else
10
Added:
"<li>Error: '~/git' directory not found.</li>"
11
Added:
12
Added:
(* Page layout function *)
13
Added:
let page_layout ~content =
14
Added:
"<html><body>"
15
Added:
^ Layouts.Header.header ()
16
Added:
^ Layouts.Topnav.topnav ()
17
Added:
^ "<main>" ^ content ^ "</main>"
18
Added:
^ "</body></html>"
lib/layouts/dune
@@ -0,0 +1,16 @@
1
Added:
(library
2
Added:
(name layouts)
3
Added:
(public_name ogit.layouts)
4
Added:
(modules header topnav))
5
Added:
6
Added:
; Rule to preprocess header.eml.html
7
Added:
(rule
8
Added:
(targets header.ml)
9
Added:
(deps header.eml.html)
10
Added:
(action (run dream_eml %{deps} --workspace %{workspace_root})))
11
Added:
12
Added:
; Rule to preprocess topnav.eml.html
13
Added:
(rule
14
Added:
(targets topnav.ml)
15
Added:
(deps topnav.eml.html)
16
Added:
(action (run dream_eml %{deps} --workspace %{workspace_root})))
lib/layouts/header.eml.html
@@ -0,0 +1,3 @@
1
Added:
let header _ =
2
Added:
<h1>ogit</h1>
3
Added:
<h2>Your mobile-friendly Git repository viewer.</h2>
lib/layouts/topnav.eml.html
@@ -0,0 +1,11 @@
1
Added:
let topnav _ =
2
Added:
<nav id="top">
3
Added:
<ul>
4
Added:
<li><a href="/">Home</a></li>
5
Added:
<li><a href="/">Refs</a></li>
6
Added:
<li><a href="/">Log</a></li>
7
Added:
<li><a href="/">Tree</a></li>
8
Added:
<li><a href="/">Commit</a></li>
9
Added:
<li><a href="/">Diff</a></li>
10
Added:
</ul>
11
Added:
</nav>
ogit.opam
@@ -0,0 +1,33 @@
1
Added:
# This file is generated by dune, edit dune-project instead
2
Added:
opam-version: "2.0"
3
Added:
synopsis: "Replacement for cgit"
4
Added:
description: "A longer description"
5
Added:
maintainer: ["Marius Peter"]
6
Added:
authors: ["Marius Peter"]
7
Added:
license: "LICENSE"
8
Added:
tags: ["topics" "to describe" "your" "project"]
9
Added:
homepage: "https://github.com/username/reponame"
10
Added:
doc: "https://url/to/documentation"
11
Added:
bug-reports: "https://github.com/username/reponame/issues"
12
Added:
depends: [
13
Added:
"ocaml"
14
Added:
"dune" {>= "3.16"}
15
Added:
"dream"
16
Added:
"git"
17
Added:
"odoc" {with-doc}
18
Added:
]
19
Added:
build: [
20
Added:
["dune" "subst"] {dev}
21
Added:
[
22
Added:
"dune"
23
Added:
"build"
24
Added:
"-p"
25
Added:
name
26
Added:
"-j"
27
Added:
jobs
28
Added:
"@install"
29
Added:
"@runtest" {with-test}
30
Added:
"@doc" {with-doc}
31
Added:
]
32
Added:
]
33
Added:
dev-repo: "git+https://github.com/username/reponame.git"
test/dune
@@ -0,0 +1,2 @@
1
Added:
(test
2
Added:
(name test_ogit))