fix routes

This commit is contained in:
cel 🌸 2024-02-20 00:24:38 +00:00
parent ac0983a896
commit f4ff8fe6eb
10 changed files with 256 additions and 215 deletions

View File

@ -40,18 +40,18 @@ func Handlers(c *config.Config) *flow.Mux {
mux.HandleFunc("/", d.Index, "GET")
mux.HandleFunc("/static/:file", d.ServeStatic, "GET")
mux.HandleFunc("/:category/:name", d.Multiplex, "GET", "POST")
mux.HandleFunc("/:category/:name/tree/:ref/...", d.RepoTree, "GET")
mux.HandleFunc("/:category/:name/blob/:ref/...", d.FileContent, "GET")
mux.HandleFunc("/:category/:name/log/:ref", d.Log, "GET")
mux.HandleFunc("/:category/:name/commit/:ref", d.Diff, "GET")
mux.HandleFunc("/:category/:name/refs", d.Refs, "GET")
mux.HandleFunc("/:category/:name/...", d.Multiplex, "GET", "POST")
mux.HandleFunc("/:name", d.Multiplex, "GET", "POST")
mux.HandleFunc("/:category/:name/tree/:ref/...", d.RepoTree, "GET")
mux.HandleFunc("/:name/tree/:ref/...", d.RepoTree, "GET")
mux.HandleFunc("/:category/:name/blob/:ref/...", d.FileContent, "GET")
mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET")
mux.HandleFunc("/:category/:name/log/:ref", d.Log, "GET")
mux.HandleFunc("/:name/log/:ref", d.Log, "GET")
mux.HandleFunc("/:category/:name/commit/:ref", d.Diff, "GET")
mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET")
mux.HandleFunc("/:category/:name/refs", d.Refs, "GET")
mux.HandleFunc("/:name/refs", d.Refs, "GET")
mux.HandleFunc("/:category/:name/...", d.Multiplex, "GET", "POST")
mux.HandleFunc("/:name/...", d.Multiplex, "GET", "POST")
return mux

View File

@ -226,6 +226,11 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
data := make(map[string]any)
data["name"] = name
if category != "" {
data["repo"] = filepath.Join(category, name)
} else {
data["repo"] = name
}
data["ref"] = mainBranch
data["readme"] = readmeContent
data["commits"] = commits
@ -276,6 +281,11 @@ func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
data := make(map[string]any)
data["name"] = name
if category != "" {
data["repo"] = filepath.Join(category, name)
} else {
data["repo"] = name
}
data["ref"] = ref
data["parent"] = treePath
data["desc"] = getDescription(path)
@ -313,6 +323,11 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
contents, err := gr.FileContent(treePath)
data := make(map[string]any)
data["name"] = name
if category != "" {
data["repo"] = filepath.Join(category, name)
} else {
data["repo"] = name
}
data["ref"] = ref
data["desc"] = getDescription(path)
data["path"] = treePath
@ -358,6 +373,11 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
data["commits"] = commits
data["meta"] = d.c.Meta
data["name"] = name
if category != "" {
data["repo"] = filepath.Join(category, name)
} else {
data["repo"] = name
}
data["ref"] = ref
data["desc"] = getDescription(path)
data["log"] = true
@ -408,6 +428,11 @@ func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
data["diff"] = diff.Diff
data["meta"] = d.c.Meta
data["name"] = name
if category != "" {
data["repo"] = filepath.Join(category, name)
} else {
data["repo"] = name
}
data["ref"] = ref
data["desc"] = getDescription(path)
@ -459,6 +484,11 @@ func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {
data["meta"] = d.c.Meta
data["name"] = name
if category != "" {
data["repo"] = filepath.Join(category, name)
} else {
data["repo"] = name
}
data["branches"] = branches
data["tags"] = tags
data["desc"] = getDescription(path)

View File

@ -1,11 +1,11 @@
:root {
--light: #f4f4f4;
--cyan: #509c93;
--light-gray: #eee;
--medium-gray: #ddd;
--gray: #6a6a6a;
--dark: #444;
--darker: #222;
--light: #224520;
--cyan: #285125;
--light-gray: #336830;
--medium-gray: #dbd7d4;
--gray: #dbd7d4;
--dark: #f3d0aa;
--darker: #f3d0aa;
--sans-font: "InterVar", -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif;
--display-font: "InterDisplay", -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif;
@ -13,6 +13,7 @@
}
html {
color: var(--dark);
background: var(--light);
-webkit-text-size-adjust: none;
font-family: var(--sans-font);

View File

@ -3,6 +3,7 @@
{{ template "head" . }}
{{ template "repoheader" . }}
<body>
{{ template "nav" . }}
<main>
@ -11,13 +12,14 @@
{{- .commit.Message -}}
</pre>
<div class="commit-info">
{{ .commit.Author.Name }} <a href="mailto:{{ .commit.Author.Email }}" class="commit-email">{{ .commit.Author.Email}}</a>
{{ .commit.Author.Name }} <a href="mailto:{{ .commit.Author.Email }}" class="commit-email">{{
.commit.Author.Email}}</a>
<div>{{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</div>
<div>
<strong>commit</strong>
<p><a href="/{{ .name }}/commit/{{ .commit.This }}" class="commit-hash">
<p><a href="/{{ .repo }}/commit/{{ .commit.This }}" class="commit-hash">
{{ .commit.This }}
</a>
</p>
@ -26,7 +28,7 @@
{{ if .commit.Parent }}
<div>
<strong>parent</strong>
<p><a href="/{{ .name }}/commit/{{ .commit.Parent }}" class="commit-hash">
<p><a href="/{{ .repo }}/commit/{{ .commit.Parent }}" class="commit-hash">
{{ .commit.Parent }}
</a></p>
</div>
@ -50,7 +52,7 @@
</div>
</section>
<section>
{{ $repo := .name }}
{{ $repo := .repo }}
{{ $this := .commit.This }}
{{ $parent := .commit.Parent }}
{{ range .diff }}
@ -100,5 +102,6 @@
</section>
</main>
</body>
</html>
{{ end }}

View File

@ -3,10 +3,11 @@
{{ template "head" . }}
{{ template "repoheader" . }}
<body>
{{ template "nav" . }}
<main>
{{ $repo := .name }}
{{ $repo := .repo }}
<div class="log">
{{ range .commits }}
<div>
@ -21,5 +22,6 @@
</div>
</main>
</body>
</html>
{{ end }}

View File

@ -1,12 +1,12 @@
{{ define "nav" }}
<nav>
<ul>
{{ if .name }}
<li><a href="/{{ .name }}">summary</a>
<li><a href="/{{ .name }}/refs">refs</a>
{{ if .repo }}
<li><a href="/{{ .repo }}">summary</a>
<li><a href="/{{ .repo }}/refs">refs</a>
{{ if .ref }}
<li><a href="/{{ .name }}/tree/{{ .ref }}/">tree</a>
<li><a href="/{{ .name }}/log/{{ .ref }}">log</a>
<li><a href="/{{ .repo }}/tree/{{ .ref }}/">tree</a>
<li><a href="/{{ .repo }}/log/{{ .ref }}">log</a>
{{ end }}
{{ end }}
</ul>

View File

@ -3,10 +3,11 @@
{{ template "head" . }}
{{ template "repoheader" . }}
<body>
{{ template "nav" . }}
<main>
{{ $name := .name }}
{{ $name := .repo }}
<h3>branches</h3>
<div class="refs">
{{ range .branches }}
@ -34,5 +35,6 @@
{{ end }}
</main>
</body>
</html>
{{ end }}

View File

@ -2,7 +2,7 @@
<header>
<h2>
<a href="/">all repos</a>
&mdash; {{ .name }}
&mdash; {{ .repo }}
{{ if .ref }}
<span class="ref">@ {{ .ref }}</span>
{{ end }}

View File

@ -7,7 +7,7 @@
<body>
{{ template "nav" . }}
<main>
{{ $repo := .name }}
{{ $repo := .repo }}
<div class="log">
{{ range .commits }}
<div>
@ -29,10 +29,11 @@
<div class="clone-url">
<strong>clone</strong>
<pre>
git clone https://{{ .servername }}/{{ .name }}
git clone https://{{ .servername }}/{{ .repo }}
</pre>
</div>
</main>
</body>
</html>
{{ end }}

View File

@ -4,10 +4,11 @@
{{ template "head" . }}
{{ template "repoheader" . }}
<body>
{{ template "nav" . }}
<main>
{{ $repo := .name }}
{{ $repo := .repo }}
{{ $ref := .ref }}
{{ $parent := .parent }}
@ -51,5 +52,6 @@
</article>
</main>
</body>
</html>
{{ end }}