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("/", d.Index, "GET")
mux.HandleFunc("/static/:file", d.ServeStatic, "GET") mux.HandleFunc("/static/:file", d.ServeStatic, "GET")
mux.HandleFunc("/:category/:name", d.Multiplex, "GET", "POST") 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("/:name", d.Multiplex, "GET", "POST")
mux.HandleFunc("/:category/:name/tree/:ref/...", d.RepoTree, "GET")
mux.HandleFunc("/: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("/: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("/: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("/:name/commit/:ref", d.Diff, "GET")
mux.HandleFunc("/:category/:name/refs", d.Refs, "GET")
mux.HandleFunc("/: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") mux.HandleFunc("/:name/...", d.Multiplex, "GET", "POST")
return mux return mux

View File

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

View File

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

View File

@ -2,74 +2,76 @@
<html> <html>
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }} {{ template "repoheader" . }}
<body>
{{ template "nav" . }} <body>
<main> {{ template "nav" . }}
<section class="commit"> <main>
<pre> <section class="commit">
{{- .commit.Message -}} <pre>
</pre> {{- .commit.Message -}}
<div class="commit-info"> </pre>
{{ .commit.Author.Name }} <a href="mailto:{{ .commit.Author.Email }}" class="commit-email">{{ .commit.Author.Email}}</a> <div class="commit-info">
{{ .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>{{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</div> </div>
<div> <div>
<strong>commit</strong> <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 }} {{ .commit.This }}
</a> </a>
</p> </p>
</div> </div>
{{ if .commit.Parent }} {{ if .commit.Parent }}
<div> <div>
<strong>parent</strong> <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 }} {{ .commit.Parent }}
</a></p> </a></p>
</div> </div>
{{ end }} {{ end }}
<div class="diff-stat"> <div class="diff-stat">
<div> <div>
{{ .stat.FilesChanged }} files changed, {{ .stat.FilesChanged }} files changed,
{{ .stat.Insertions }} insertions(+), {{ .stat.Insertions }} insertions(+),
{{ .stat.Deletions }} deletions(-) {{ .stat.Deletions }} deletions(-)
</div>
<div>
<br>
<strong>jump to</strong>
{{ range .diff }}
<ul>
<li><a href="#{{ .Name.New }}">{{ .Name.New }}</a></li>
</ul>
{{ end }}
</div>
</div> </div>
</section> <div>
<section> <br>
{{ $repo := .name }} <strong>jump to</strong>
{{ $this := .commit.This }} {{ range .diff }}
{{ $parent := .commit.Parent }} <ul>
{{ range .diff }} <li><a href="#{{ .Name.New }}">{{ .Name.New }}</a></li>
<div id="{{ .Name.New }}"> </ul>
<div class="diff"> {{ end }}
{{ if .IsNew }} </div>
<span class="diff-type">A</span> </div>
{{ end }} </section>
{{ if .IsDelete }} <section>
<span class="diff-type">D</span> {{ $repo := .repo }}
{{ end }} {{ $this := .commit.This }}
{{ if not (or .IsNew .IsDelete) }} {{ $parent := .commit.Parent }}
<span class="diff-type">M</span> {{ range .diff }}
{{ end }} <div id="{{ .Name.New }}">
<div class="diff">
{{ if .IsNew }}
<span class="diff-type">A</span>
{{ end }}
{{ if .IsDelete }}
<span class="diff-type">D</span>
{{ end }}
{{ if not (or .IsNew .IsDelete) }}
<span class="diff-type">M</span>
{{ end }}
{{ if .Name.Old }} {{ if .Name.Old }}
<a href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}">{{ .Name.Old }}</a> <a href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}">{{ .Name.Old }}</a>
{{ if .Name.New }} {{ if .Name.New }}
&#8594; &#8594;
<a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a>
{{ end }} {{ end }}
{{ else }} {{ else }}
<a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a>
@ -77,28 +79,29 @@
{{ if .IsBinary }} {{ if .IsBinary }}
<p>Not showing binary file.</p> <p>Not showing binary file.</p>
{{ else }} {{ else }}
<pre> <pre>
{{- range .TextFragments -}} {{- range .TextFragments -}}
<p>{{- .Header -}}</p> <p>{{- .Header -}}</p>
{{- range .Lines -}} {{- range .Lines -}}
{{- if eq .Op.String "+" -}} {{- if eq .Op.String "+" -}}
<span class="diff-add">{{ .String }}</span> <span class="diff-add">{{ .String }}</span>
{{- end -}} {{- end -}}
{{- if eq .Op.String "-" -}} {{- if eq .Op.String "-" -}}
<span class="diff-del">{{ .String }}</span> <span class="diff-del">{{ .String }}</span>
{{- end -}} {{- end -}}
{{- if eq .Op.String " " -}} {{- if eq .Op.String " " -}}
<span class="diff-noop">{{ .String }}</span> <span class="diff-noop">{{ .String }}</span>
{{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
</pre> {{- end -}}
</div> </pre>
</div> </div>
{{ end }} </div>
</section> {{ end }}
</main> </section>
</body> </main>
</body>
</html> </html>
{{ end }} {{ end }}

View File

@ -2,24 +2,26 @@
<html> <html>
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }} {{ template "repoheader" . }}
<body>
{{ template "nav" . }} <body>
<main> {{ template "nav" . }}
{{ $repo := .name }} <main>
<div class="log"> {{ $repo := .repo }}
{{ range .commits }} <div class="log">
<div> {{ range .commits }}
<div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div> <div>
<pre>{{ .Message }}</pre> <div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div>
</div> <pre>{{ .Message }}</pre>
<div class="commit-info">
{{ .Author.Name }} <a href="mailto:{{ .Author.Email }}" class="commit-email">{{ .Author.Email }}</a>
<div>{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</div>
{{ end }}
</div> </div>
</main> <div class="commit-info">
</body> {{ .Author.Name }} <a href="mailto:{{ .Author.Email }}" class="commit-email">{{ .Author.Email }}</a>
<div>{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</div>
{{ end }}
</div>
</main>
</body>
</html> </html>
{{ end }} {{ end }}

View File

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

View File

@ -2,37 +2,39 @@
<html> <html>
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }} {{ template "repoheader" . }}
<body>
{{ template "nav" . }} <body>
<main> {{ template "nav" . }}
{{ $name := .name }} <main>
<h3>branches</h3> {{ $name := .repo }}
<div class="refs"> <h3>branches</h3>
<div class="refs">
{{ range .branches }} {{ range .branches }}
<div> <div>
<strong>{{ .Name.Short }}</strong> <strong>{{ .Name.Short }}</strong>
<a href="/{{ $name }}/tree/{{ .Name.Short }}/">browse</a> <a href="/{{ $name }}/tree/{{ .Name.Short }}/">browse</a>
<a href="/{{ $name }}/log/{{ .Name.Short }}">log</a> <a href="/{{ $name }}/log/{{ .Name.Short }}">log</a>
</div>
{{ end }}
</div> </div>
{{ if .tags }} {{ end }}
<h3>tags</h3> </div>
<div class="refs"> {{ if .tags }}
<h3>tags</h3>
<div class="refs">
{{ range .tags }} {{ range .tags }}
<div> <div>
<strong>{{ .Name }}</strong> <strong>{{ .Name }}</strong>
<a href="/{{ $name }}/tree/{{ .Name }}/">browse</a> <a href="/{{ $name }}/tree/{{ .Name }}/">browse</a>
<a href="/{{ $name }}/log/{{ .Name }}">log</a> <a href="/{{ $name }}/log/{{ .Name }}">log</a>
{{ if .Message }} {{ if .Message }}
<pre>{{ .Message }}</pre> <pre>{{ .Message }}</pre>
</div> </div>
{{ end }} {{ end }}
{{ end }} {{ end }}
</div> </div>
{{ end }} {{ end }}
</main> </main>
</body> </body>
</html> </html>
{{ end }} {{ end }}

View File

@ -1,12 +1,12 @@
{{ define "repoheader" }} {{ define "repoheader" }}
<header> <header>
<h2> <h2>
<a href="/">all repos</a> <a href="/">all repos</a>
&mdash; {{ .name }} &mdash; {{ .repo }}
{{ if .ref }} {{ if .ref }}
<span class="ref">@ {{ .ref }}</span> <span class="ref">@ {{ .ref }}</span>
{{ end }} {{ end }}
</h2> </h2>
<h3 class="desc">{{ .desc }}</h3> <h3 class="desc">{{ .desc }}</h3>
</header> </header>
{{ end }} {{ end }}

View File

@ -4,35 +4,36 @@
{{ template "repoheader" . }} {{ template "repoheader" . }}
<body> <body>
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
{{ $repo := .name }} {{ $repo := .repo }}
<div class="log"> <div class="log">
{{ range .commits }} {{ range .commits }}
<div> <div>
<div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div> <div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div>
<pre>{{ .Message }}</pre> <pre>{{ .Message }}</pre>
</div>
<div class="commit-info">
{{ .Author.Name }} <a href="mailto:{{ .Author.Email }}" class="commit-email">{{ .Author.Email }}</a>
<div>{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</div>
{{ end }}
</div> </div>
{{- if .readme }} <div class="commit-info">
<article class="readme"> {{ .Author.Name }} <a href="mailto:{{ .Author.Email }}" class="commit-email">{{ .Author.Email }}</a>
{{- .readme -}} <div>{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div>
</article> </div>
{{- end -}} {{ end }}
</div>
{{- if .readme }}
<article class="readme">
{{- .readme -}}
</article>
{{- end -}}
<div class="clone-url"> <div class="clone-url">
<strong>clone</strong> <strong>clone</strong>
<pre> <pre>
git clone https://{{ .servername }}/{{ .name }} git clone https://{{ .servername }}/{{ .repo }}
</pre> </pre>
</div> </div>
</main> </main>
</body> </body>
</html> </html>
{{ end }} {{ end }}

View File

@ -3,53 +3,55 @@
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }} {{ template "repoheader" . }}
<body>
{{ template "nav" . }}
<main>
{{ $repo := .name }}
{{ $ref := .ref }}
{{ $parent := .parent }}
<div class="tree"> <body>
{{ template "nav" . }}
<main>
{{ $repo := .repo }}
{{ $ref := .ref }}
{{ $parent := .parent }}
<div class="tree">
{{ if $parent }}
<div></div>
<div></div>
<div><a href="/{{ $repo }}/tree/{{ $ref }}/{{ .dotdot }}">..</a></div>
{{ end }}
{{ range .files }}
{{ if not .IsFile }}
<div class="mode">{{ .Mode }}</div>
<div class="size">{{ .Size }}</div>
<div>
{{ if $parent }} {{ if $parent }}
<div></div> <a href="/{{ $repo }}/tree/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}/</a>
<div></div> {{ else }}
<div><a href="/{{ $repo }}/tree/{{ $ref }}/{{ .dotdot }}">..</a></div> <a href="/{{ $repo }}/tree/{{ $ref }}/{{ .Name }}">{{ .Name }}/</a>
{{ end }}
{{ range .files }}
{{ if not .IsFile }}
<div class="mode">{{ .Mode }}</div>
<div class="size">{{ .Size }}</div>
<div>
{{ if $parent }}
<a href="/{{ $repo }}/tree/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}/</a>
{{ else }}
<a href="/{{ $repo }}/tree/{{ $ref }}/{{ .Name }}">{{ .Name }}/</a>
{{ end }}
</div>
{{ end }}
{{ end }}
{{ range .files }}
{{ if .IsFile }}
<div class="mode">{{ .Mode }}</div>
<div class="size">{{ .Size }}</div>
<div>
{{ if $parent }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}</a>
{{ else }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ .Name }}">{{ .Name }}</a>
{{ end }}
</div>
{{ end }}
{{ end }} {{ end }}
</div> </div>
<article> {{ end }}
<pre> {{ end }}
{{- if .readme }}{{ .readme }}{{- end -}} {{ range .files }}
</pre> {{ if .IsFile }}
</article> <div class="mode">{{ .Mode }}</div>
</main> <div class="size">{{ .Size }}</div>
</body> <div>
{{ if $parent }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}</a>
{{ else }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ .Name }}">{{ .Name }}</a>
{{ end }}
</div>
{{ end }}
{{ end }}
</div>
<article>
<pre>
{{- if .readme }}{{ .readme }}{{- end -}}
</pre>
</article>
</main>
</body>
</html> </html>
{{ end }} {{ end }}