add footer, fix HTML hierarchy

This commit is contained in:
Iris Lightshard 2023-02-04 09:34:21 -07:00
parent b0c2a8ee38
commit 30683a7cec
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
13 changed files with 65 additions and 18 deletions

View file

@ -1,5 +1,5 @@
repo: repo:
scanPath: /var/www/git scanPath: /var/www/git/
readme: readme:
- readme - readme
- README - README
@ -14,6 +14,8 @@ dirs:
meta: meta:
title: git good title: git good
description: i think it's a skill issue description: i think it's a skill issue
footer: served with legit vVERSION; email patches to MAINTAINER
maintainerEmail: x@icyphox.sh
server: server:
name: git.icyphox.sh name: git.icyphox.sh
host: 127.0.0.1 host: 127.0.0.1

View file

@ -3,6 +3,8 @@ package config
import ( import (
"fmt" "fmt"
"os" "os"
"html/template"
"strings"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@ -21,6 +23,9 @@ type Config struct {
Meta struct { Meta struct {
Title string `yaml:"title"` Title string `yaml:"title"`
Description string `yaml:"description"` Description string `yaml:"description"`
Footer string `yaml:"footer,omitempty"`
MaintainerEmail string `yaml:"maintainerEmail,omitempty"`
CompiledFooter template.HTML `yaml:"thisIsNotSupposedToBeHere,omitempty"`
} `yaml:"meta"` } `yaml:"meta"`
Server struct { Server struct {
Name string `yaml:"name,omitempty"` Name string `yaml:"name,omitempty"`
@ -29,7 +34,23 @@ type Config struct {
} `yaml:"server"` } `yaml:"server"`
} }
func Read(f string) (*Config, error) { func compileFooter(c *Config, version string) {
if c.Meta.Footer != "" {
c.Meta.CompiledFooter = template.HTML(
strings.ReplaceAll(
strings.ReplaceAll(
c.Meta.Footer,
"VERSION",
version),
"MAINTAINER",
fmt.Sprintf(
"<a href='mailto:%s'>%s</a>",
c.Meta.MaintainerEmail,
c.Meta.MaintainerEmail)))
}
}
func Read(f, v string) (*Config, error) {
b, err := os.ReadFile(f) b, err := os.ReadFile(f)
if err != nil { if err != nil {
return nil, fmt.Errorf("reading config: %w", err) return nil, fmt.Errorf("reading config: %w", err)
@ -39,6 +60,8 @@ func Read(f string) (*Config, error) {
if err := yaml.Unmarshal(b, &c); err != nil { if err := yaml.Unmarshal(b, &c); err != nil {
return nil, fmt.Errorf("parsing config: %w", err) return nil, fmt.Errorf("parsing config: %w", err)
} }
compileFooter(&c, v)
return &c, nil return &c, nil
} }

View file

@ -13,11 +13,12 @@ import (
) )
func main() { func main() {
const version string = "0.2.x"
var cfg string var cfg string
flag.StringVar(&cfg, "config", "./config.yaml", "path to config file") flag.StringVar(&cfg, "config", "./config.yaml", "path to config file")
flag.Parse() flag.Parse()
c, err := config.Read(cfg) c, err := config.Read(cfg, version)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -148,6 +148,7 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
data["desc"] = getDescription(path) data["desc"] = getDescription(path)
data["servername"] = d.c.Server.Name data["servername"] = d.c.Server.Name
data["gomod"] = isGoModule(gr) data["gomod"] = isGoModule(gr)
data["meta"] = d.c.Meta
if err := d.t.ExecuteTemplate(w, "repo", data); err != nil { if err := d.t.ExecuteTemplate(w, "repo", data); err != nil {
log.Println(err) log.Println(err)

View file

@ -45,6 +45,12 @@ main, footer {
line-height: 160%; line-height: 160%;
} }
footer {
font-size: 85%;
padding: 1em;
text-align: center;
}
main h1, h2, h3, strong { main h1, h2, h3, strong {
font-family: var(--display-font); font-family: var(--display-font);
font-weight: 500; font-weight: 500;

View file

@ -1,9 +1,8 @@
{{ define "commit" }} {{ define "commit" }}
<html> <html>
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }}
<body> <body>
{{ template "repoheader" . }}
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
<section class="commit"> <section class="commit">
@ -104,6 +103,7 @@
{{ end }} {{ end }}
</section> </section>
</main> </main>
{{ template "footer" .meta }}
</body> </body>
</html> </html>
{{ end }} {{ end }}

View file

@ -3,8 +3,8 @@
{{ template "head" . }} {{ template "head" . }}
<title>{{.name }} &mdash; {{ .path }}</title> <title>{{.name }} &mdash; {{ .path }}</title>
{{ template "repoheader" . }}
<body> <body>
{{ template "repoheader" . }}
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
<p>{{ .path }} (<a href="{{ .raw }}">raw</a>)</p> <p>{{ .path }} (<a href="{{ .raw }}">raw</a>)</p>
@ -25,6 +25,7 @@
</tbody></tr> </tbody></tr>
</table> </table>
</main> </main>
{{ template "footer" .meta }}
</body> </body>
</html> </html>
{{ end }} {{ end }}

7
templates/footer.html Normal file
View file

@ -0,0 +1,7 @@
{{ define "footer" }}
{{ if .CompiledFooter }}
<footer>
<span>{{ .CompiledFooter }}</span>
</footer>
{{ end }}
{{ end }}

View file

@ -6,11 +6,12 @@
{{ .meta.Title }} {{ .meta.Title }}
</title> </title>
<header>
<h1>{{ .meta.Title }}</h1>
<h2>{{ .meta.Description }}</h2>
</header>
<body> <body>
<header>
<h1>{{ .meta.Title }}</h1>
<h2>{{ .meta.Description }}</h2>
</header>
<main> <main>
<div class="index"> <div class="index">
{{ range .info }} {{ range .info }}
@ -20,6 +21,8 @@
{{ end }} {{ end }}
</div> </div>
</main> </main>
{{ template "footer" .meta }}
</body> </body>
</html> </html>
{{ end }} {{ end }}

View file

@ -6,8 +6,8 @@
{{ .name }} &mdash; log {{ .name }} &mdash; log
</title> </title>
{{ template "repoheader" . }}
<body> <body>
{{ template "repoheader" . }}
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
{{ $repo := .name }} {{ $repo := .name }}
@ -24,6 +24,7 @@
{{ end }} {{ end }}
</div> </div>
</main> </main>
{{ template "footer" .meta }}
</body> </body>
</html> </html>
{{ end }} {{ end }}

View file

@ -6,8 +6,8 @@
{{ .name }} &mdash; refs {{ .name }} &mdash; refs
</title> </title>
{{ template "repoheader" . }}
<body> <body>
{{ template "repoheader" . }}
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
{{ $name := .name }} {{ $name := .name }}
@ -47,6 +47,8 @@
</div> </div>
{{ end }} {{ end }}
</main> </main>
{{ template "footer" .meta }}
</body> </body>
</html> </html>
{{ end }} {{ end }}

View file

@ -6,10 +6,8 @@
{{ end }} {{ end }}
</title> </title>
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }}
<body> <body>
{{ template "repoheader" . }}
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
{{ $repo := .name }} {{ $repo := .name }}
@ -38,6 +36,8 @@ git clone https://{{ .servername }}/{{ .name }}
</pre> </pre>
</div> </div>
</main> </main>
{{ template "footer" .meta }}
</body> </body>
</html> </html>
{{ end }} {{ end }}

View file

@ -6,9 +6,8 @@
{{ end }} {{ end }}
</title> </title>
{{ template "head" . }} {{ template "head" . }}
{{ template "repoheader" . }}
<body> <body>
{{ template "repoheader" . }}
{{ template "nav" . }} {{ template "nav" . }}
<main> <main>
{{ $repo := .name }} {{ $repo := .name }}
@ -53,7 +52,7 @@
</tr> </tr>
{{ end }} {{ end }}
{{ end }} {{ end }}
</div> </table>
<article> <article>
<pre> <pre>
{{- if .readme }}{{ .readme }}{{- end -}} {{- if .readme }}{{ .readme }}{{- end -}}
@ -61,5 +60,6 @@
</article> </article>
</main> </main>
</body> </body>
{{ template "footer" .meta }}
</html> </html>
{{ end }} {{ end }}