diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-05-28 23:02:14 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-05-28 23:02:14 +0200 |
commit | ffae61af1a13862ffc2bf9415313f5da3d90d38e (patch) | |
tree | d1849eaf647e498e68cc0c9511d6b1d7f786dc62 /lib/routes.ml | |
parent | 378d9f24bd19855b7aa59936d7104ab1203c42f3 (diff) |
Add link_to route generator.
Diffstat (limited to 'lib/routes.ml')
-rw-r--r-- | lib/routes.ml | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/routes.ml b/lib/routes.ml new file mode 100644 index 0000000..0778c18 --- /dev/null +++ b/lib/routes.ml @@ -0,0 +1,30 @@ +(* -*- mode: tuareg; -*- *) + +open Dream_html +open HTML + +type t = + | Root + | Repo of string + | Tag of string * string + | Commit of string * string + | Tree of string * string * string + | Blob of string * string * string + +let%path root_path = "/" +let%path repo_path = "/%s" +let%path tag_path = "/%s/refs/%s" +let%path commit_path = "/%s/commit/%s" +let%path tree_path = "/%s/tree/%s/%s" +let%path blob_path = "/%s/blob/%s/%s" + +let path_attr = function + | Root -> path_attr href root_path + | Repo repo -> path_attr href repo_path repo + | Tag (repo, branch) -> path_attr href tag_path repo branch + | Commit (repo, commit) -> path_attr href commit_path repo commit + | Tree (repo, commit, path) -> path_attr href tree_path repo commit path + | Blob (repo, commit, path) -> path_attr href blob_path repo commit path + +let link_to label route = a [ path_attr route ] [ txt "%s" label ] +let li_of_repo repo = li [] [ link_to repo (Repo repo) ] |