diff options
author | cel 🌸 <cel@blos.sm> | 2024-02-20 00:24:38 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2024-02-20 00:24:38 +0000 |
commit | f4ff8fe6eb20ab5b557d7beac095959890e126e8 (patch) | |
tree | 41e3c708a0c5c3cb4a318ebcd7739e3f2dc74552 | |
parent | ac0983a89692534daa3d36dba528461b5bb32dbc (diff) | |
download | legit-f4ff8fe6eb20ab5b557d7beac095959890e126e8.tar.gz legit-f4ff8fe6eb20ab5b557d7beac095959890e126e8.tar.bz2 legit-f4ff8fe6eb20ab5b557d7beac095959890e126e8.zip |
fix routes
-rw-r--r-- | routes/handler.go | 12 | ||||
-rw-r--r-- | routes/routes.go | 30 | ||||
-rw-r--r-- | static/style.css | 15 | ||||
-rw-r--r-- | templates/commit.html | 147 | ||||
-rw-r--r-- | templates/log.html | 40 | ||||
-rw-r--r-- | templates/nav.html | 22 | ||||
-rw-r--r-- | templates/refs.html | 48 | ||||
-rw-r--r-- | templates/repo-header.html | 6 | ||||
-rw-r--r-- | templates/repo.html | 57 | ||||
-rw-r--r-- | templates/tree.html | 90 |
10 files changed, 254 insertions, 213 deletions
diff --git a/routes/handler.go b/routes/handler.go index f133e80..1a9bfbd 100644 --- a/routes/handler.go +++ b/routes/handler.go @@ -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 diff --git a/routes/routes.go b/routes/routes.go index 6c6df6c..f27a554 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -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) diff --git a/static/style.css b/static/style.css index 5f7087b..ce66ba6 100644 --- a/static/style.css +++ b/static/style.css @@ -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); diff --git a/templates/commit.html b/templates/commit.html index c1def17..3e6ec5e 100644 --- a/templates/commit.html +++ b/templates/commit.html @@ -2,74 +2,76 @@ <html> {{ template "head" . }} - {{ template "repoheader" . }} - <body> - {{ template "nav" . }} - <main> - <section class="commit"> - <pre> - {{- .commit.Message -}} - </pre> - <div class="commit-info"> - {{ .commit.Author.Name }} <a href="mailto:{{ .commit.Author.Email }}" class="commit-email">{{ .commit.Author.Email}}</a> +{{ template "repoheader" . }} + +<body> + {{ template "nav" . }} + <main> + <section class="commit"> + <pre> + {{- .commit.Message -}} + </pre> + <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> + </div> - <div> + <div> <strong>commit</strong> - <p><a href="/{{ .name }}/commit/{{ .commit.This }}" class="commit-hash"> - {{ .commit.This }} - </a> + <p><a href="/{{ .repo }}/commit/{{ .commit.This }}" class="commit-hash"> + {{ .commit.This }} + </a> </p> - </div> + </div> - {{ if .commit.Parent }} - <div> + {{ if .commit.Parent }} + <div> <strong>parent</strong> - <p><a href="/{{ .name }}/commit/{{ .commit.Parent }}" class="commit-hash"> - {{ .commit.Parent }} - </a></p> - </div> + <p><a href="/{{ .repo }}/commit/{{ .commit.Parent }}" class="commit-hash"> + {{ .commit.Parent }} + </a></p> + </div> - {{ end }} - <div class="diff-stat"> - <div> + {{ end }} + <div class="diff-stat"> + <div> {{ .stat.FilesChanged }} files changed, {{ .stat.Insertions }} insertions(+), {{ .stat.Deletions }} deletions(-) - </div> - <div> - <br> - <strong>jump to</strong> - {{ range .diff }} - <ul> + </div> + <div> + <br> + <strong>jump to</strong> + {{ range .diff }} + <ul> <li><a href="#{{ .Name.New }}">{{ .Name.New }}</a></li> - </ul> - {{ end }} - </div> + </ul> + {{ end }} </div> - </section> - <section> - {{ $repo := .name }} - {{ $this := .commit.This }} - {{ $parent := .commit.Parent }} - {{ range .diff }} - <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 }} + </div> + </section> + <section> + {{ $repo := .repo }} + {{ $this := .commit.This }} + {{ $parent := .commit.Parent }} + {{ range .diff }} + <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 }} <a href="/{{ $repo }}/blob/{{ $parent }}/{{ .Name.Old }}">{{ .Name.Old }}</a> {{ if .Name.New }} - → - <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> + → + <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> {{ end }} {{ else }} <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> @@ -77,28 +79,29 @@ {{ if .IsBinary }} <p>Not showing binary file.</p> {{ else }} - <pre> + <pre> {{- range .TextFragments -}} <p>{{- .Header -}}</p> {{- range .Lines -}} - {{- if eq .Op.String "+" -}} - <span class="diff-add">{{ .String }}</span> - {{- end -}} - {{- if eq .Op.String "-" -}} - <span class="diff-del">{{ .String }}</span> - {{- end -}} - {{- if eq .Op.String " " -}} - <span class="diff-noop">{{ .String }}</span> - {{- end -}} + {{- if eq .Op.String "+" -}} + <span class="diff-add">{{ .String }}</span> {{- end -}} + {{- if eq .Op.String "-" -}} + <span class="diff-del">{{ .String }}</span> {{- end -}} - {{- end -}} - </pre> - </div> - </div> - {{ end }} - </section> - </main> - </body> + {{- if eq .Op.String " " -}} + <span class="diff-noop">{{ .String }}</span> + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + </pre> + </div> + </div> + {{ end }} + </section> + </main> +</body> + </html> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/templates/log.html b/templates/log.html index 7d74cb3..e596149 100644 --- a/templates/log.html +++ b/templates/log.html @@ -2,24 +2,26 @@ <html> {{ template "head" . }} - {{ template "repoheader" . }} - <body> - {{ template "nav" . }} - <main> - {{ $repo := .name }} - <div class="log"> - {{ range .commits }} - <div> - <div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div> - <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 }} +{{ template "repoheader" . }} + +<body> + {{ template "nav" . }} + <main> + {{ $repo := .repo }} + <div class="log"> + {{ range .commits }} + <div> + <div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div> + <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> - </main> - </body> + {{ end }} + </div> + </main> +</body> + </html> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html index 51c9a34..6f6b4dd 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -1,14 +1,14 @@ {{ define "nav" }} - <nav> - <ul> - {{ if .name }} - <li><a href="/{{ .name }}">summary</a> - <li><a href="/{{ .name }}/refs">refs</a> +<nav> + <ul> + {{ 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> - </nav> -{{ end }} + {{ end }} + </ul> +</nav> +{{ end }}
\ No newline at end of file diff --git a/templates/refs.html b/templates/refs.html index 76add7d..347ff3b 100644 --- a/templates/refs.html +++ b/templates/refs.html @@ -2,37 +2,39 @@ <html> {{ template "head" . }} - {{ template "repoheader" . }} - <body> - {{ template "nav" . }} - <main> - {{ $name := .name }} - <h3>branches</h3> - <div class="refs"> +{{ template "repoheader" . }} + +<body> + {{ template "nav" . }} + <main> + {{ $name := .repo }} + <h3>branches</h3> + <div class="refs"> {{ range .branches }} - <div> + <div> <strong>{{ .Name.Short }}</strong> <a href="/{{ $name }}/tree/{{ .Name.Short }}/">browse</a> <a href="/{{ $name }}/log/{{ .Name.Short }}">log</a> - </div> - {{ end }} </div> - {{ if .tags }} - <h3>tags</h3> - <div class="refs"> + {{ end }} + </div> + {{ if .tags }} + <h3>tags</h3> + <div class="refs"> {{ range .tags }} <div> - <strong>{{ .Name }}</strong> - <a href="/{{ $name }}/tree/{{ .Name }}/">browse</a> - <a href="/{{ $name }}/log/{{ .Name }}">log</a> - {{ if .Message }} - <pre>{{ .Message }}</pre> + <strong>{{ .Name }}</strong> + <a href="/{{ $name }}/tree/{{ .Name }}/">browse</a> + <a href="/{{ $name }}/log/{{ .Name }}">log</a> + {{ if .Message }} + <pre>{{ .Message }}</pre> </div> {{ end }} {{ end }} - </div> - {{ end }} - </main> - </body> + </div> + {{ end }} + </main> +</body> + </html> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/templates/repo-header.html b/templates/repo-header.html index f358278..fae5525 100644 --- a/templates/repo-header.html +++ b/templates/repo-header.html @@ -1,12 +1,12 @@ {{ define "repoheader" }} <header> <h2> - <a href="/">all repos</a> - — {{ .name }} + <a href="/">all repos</a> + — {{ .repo }} {{ if .ref }} <span class="ref">@ {{ .ref }}</span> {{ end }} </h2> <h3 class="desc">{{ .desc }}</h3> </header> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/templates/repo.html b/templates/repo.html index 1cd9b5c..957faba 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -4,35 +4,36 @@ {{ template "repoheader" . }} - <body> - {{ template "nav" . }} - <main> - {{ $repo := .name }} - <div class="log"> - {{ range .commits }} - <div> - <div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div> - <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 }} +<body> + {{ template "nav" . }} + <main> + {{ $repo := .repo }} + <div class="log"> + {{ range .commits }} + <div> + <div><a href="/{{ $repo }}/commit/{{ .Hash.String }}" class="commit-hash">{{ slice .Hash.String 0 8 }}</a></div> + <pre>{{ .Message }}</pre> </div> -{{- if .readme }} - <article class="readme"> - {{- .readme -}} - </article> -{{- end -}} + <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> + {{- if .readme }} + <article class="readme"> + {{- .readme -}} + </article> + {{- end -}} - <div class="clone-url"> + <div class="clone-url"> <strong>clone</strong> - <pre> -git clone https://{{ .servername }}/{{ .name }} - </pre> - </div> - </main> - </body> + <pre> + git clone https://{{ .servername }}/{{ .repo }} + </pre> + </div> + </main> +</body> + </html> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/templates/tree.html b/templates/tree.html index c4b7e4f..a4f0d1b 100644 --- a/templates/tree.html +++ b/templates/tree.html @@ -3,53 +3,55 @@ {{ template "head" . }} - {{ template "repoheader" . }} - <body> - {{ template "nav" . }} - <main> - {{ $repo := .name }} - {{ $ref := .ref }} - {{ $parent := .parent }} +{{ template "repoheader" . }} - <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 }} - <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 }} - <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> + <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> - <article> - <pre> - {{- if .readme }}{{ .readme }}{{- end -}} - </pre> - </article> - </main> - </body> + {{ end }} + {{ end }} + </div> + <article> + <pre> + {{- if .readme }}{{ .readme }}{{- end -}} + </pre> + </article> + </main> +</body> + </html> -{{ end }} +{{ end }}
\ No newline at end of file |