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

View file

@ -3,6 +3,8 @@ package config
import (
"fmt"
"os"
"html/template"
"strings"
"gopkg.in/yaml.v3"
)
@ -21,6 +23,9 @@ type Config struct {
Meta struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
Footer string `yaml:"footer,omitempty"`
MaintainerEmail string `yaml:"maintainerEmail,omitempty"`
CompiledFooter template.HTML `yaml:"thisIsNotSupposedToBeHere,omitempty"`
} `yaml:"meta"`
Server struct {
Name string `yaml:"name,omitempty"`
@ -29,7 +34,23 @@ type Config struct {
} `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)
if err != nil {
return nil, fmt.Errorf("reading config: %w", err)
@ -40,5 +61,7 @@ func Read(f string) (*Config, error) {
return nil, fmt.Errorf("parsing config: %w", err)
}
compileFooter(&c, v)
return &c, nil
}

View file

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

View file

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

View file

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

View file

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

View file

@ -3,8 +3,8 @@
{{ template "head" . }}
<title>{{.name }} &mdash; {{ .path }}</title>
{{ template "repoheader" . }}
<body>
{{ template "repoheader" . }}
{{ template "nav" . }}
<main>
<p>{{ .path }} (<a href="{{ .raw }}">raw</a>)</p>
@ -25,6 +25,7 @@
</tbody></tr>
</table>
</main>
{{ template "footer" .meta }}
</body>
</html>
{{ 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 }}
</title>
<body>
<header>
<h1>{{ .meta.Title }}</h1>
<h2>{{ .meta.Description }}</h2>
</header>
<body>
<main>
<div class="index">
{{ range .info }}
@ -20,6 +21,8 @@
{{ end }}
</div>
</main>
{{ template "footer" .meta }}
</body>
</html>
{{ end }}

View file

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

View file

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

View file

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

View file

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