summaryrefslogtreecommitdiff
path: root/lib/routes.ml
blob: f615168351599f3467bc6b3eb89c9347c9e48ee6 (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
(* -*- mode: tuareg; -*- *)

type t =
  | Root
  | Repo of string
  | Log of string
  | Files of string
  | Refs of string
  | Commit of string * string
  | File of string * string

let%path root_path = "/"
let%path repo_path = "/%s/summary/"
let%path log_path = "/%s/log/"
let%path files_path = "/%s/files/"
let%path refs_path = "/%s/refs/"
let%path commit_path = "/%s/commit/%s"
let%path file_path = "/%s/file/%s"

let link_to route ?(other_attrs = []) contents =
  let open Dream_html in
  let open HTML in
  let path = function
    | Root -> path_attr href root_path
    | Repo repo -> path_attr href repo_path repo
    | Log repo -> path_attr href log_path repo
    | Files repo -> path_attr href files_path repo
    | Refs repo -> path_attr href refs_path repo
    | Commit (repo, commit) -> path_attr href commit_path repo commit
    | File (repo, hash) -> path_attr href file_path repo hash
  in
  a (path route :: other_attrs) [ contents ]
Copyright 2019--2025 Marius PETER