diff --git a/config.yaml b/config.yaml index 7333e95..23e72ca 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/config/config.go b/config/config.go index 3119352..e3b8146 100644 --- a/config/config.go +++ b/config/config.go @@ -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( + "%s", + 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) @@ -39,6 +60,8 @@ func Read(f string) (*Config, error) { if err := yaml.Unmarshal(b, &c); err != nil { return nil, fmt.Errorf("parsing config: %w", err) } + + compileFooter(&c, v) return &c, nil } diff --git a/main.go b/main.go index 4cc95b1..22404d8 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/routes/routes.go b/routes/routes.go index e1765dc..3c82bdb 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -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) diff --git a/static/style.css b/static/style.css index 2d9994a..fd4756a 100644 --- a/static/style.css +++ b/static/style.css @@ -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; diff --git a/templates/commit.html b/templates/commit.html index 656c097..2c33705 100644 --- a/templates/commit.html +++ b/templates/commit.html @@ -1,9 +1,8 @@ {{ define "commit" }} {{ template "head" . }} - - {{ template "repoheader" . }} + {{ template "repoheader" . }} {{ template "nav" . }}
@@ -104,6 +103,7 @@ {{ end }}
+ {{ template "footer" .meta }} {{ end }} diff --git a/templates/file.html b/templates/file.html index 7de7e6d..208f653 100644 --- a/templates/file.html +++ b/templates/file.html @@ -3,8 +3,8 @@ {{ template "head" . }} {{.name }} — {{ .path }} - {{ template "repoheader" . }} + {{ template "repoheader" . }} {{ template "nav" . }}

{{ .path }} (raw)

@@ -25,6 +25,7 @@
+ {{ template "footer" .meta }} {{ end }} diff --git a/templates/footer.html b/templates/footer.html new file mode 100644 index 0000000..0e2c0ec --- /dev/null +++ b/templates/footer.html @@ -0,0 +1,7 @@ +{{ define "footer" }} +{{ if .CompiledFooter }} + +{{ end }} +{{ end }} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 8bff3d7..ae1109c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,11 +6,12 @@ {{ .meta.Title }} -
-

{{ .meta.Title }}

-

{{ .meta.Description }}

-
+ +
+

{{ .meta.Title }}

+

{{ .meta.Description }}

+
{{ range .info }} @@ -20,6 +21,8 @@ {{ end }}
+ {{ template "footer" .meta }} + {{ end }} diff --git a/templates/log.html b/templates/log.html index 6cb9833..372518a 100644 --- a/templates/log.html +++ b/templates/log.html @@ -6,8 +6,8 @@ {{ .name }} — log - {{ template "repoheader" . }} + {{ template "repoheader" . }} {{ template "nav" . }}
{{ $repo := .name }} @@ -24,6 +24,7 @@ {{ end }}
+ {{ template "footer" .meta }} {{ end }} diff --git a/templates/refs.html b/templates/refs.html index 99e69f5..541ef4c 100644 --- a/templates/refs.html +++ b/templates/refs.html @@ -6,8 +6,8 @@ {{ .name }} — refs - {{ template "repoheader" . }} + {{ template "repoheader" . }} {{ template "nav" . }}
{{ $name := .name }} @@ -47,6 +47,8 @@ {{ end }}
+ {{ template "footer" .meta }} + {{ end }} diff --git a/templates/repo.html b/templates/repo.html index 8c06822..99b718f 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -6,10 +6,8 @@ {{ end }} {{ template "head" . }} - -{{ template "repoheader" . }} - + {{ template "repoheader" . }} {{ template "nav" . }}
{{ $repo := .name }} @@ -38,6 +36,8 @@ git clone https://{{ .servername }}/{{ .name }}
+ {{ template "footer" .meta }} + {{ end }} diff --git a/templates/tree.html b/templates/tree.html index 33a4dd3..be285c0 100644 --- a/templates/tree.html +++ b/templates/tree.html @@ -6,9 +6,8 @@ {{ end }} {{ template "head" . }} - - {{ template "repoheader" . }} + {{ template "repoheader" . }} {{ template "nav" . }}
{{ $repo := .name }} @@ -53,7 +52,7 @@ {{ end }} {{ end }} - +
           {{- if .readme }}{{ .readme }}{{- end -}}
@@ -61,5 +60,6 @@
       
+ {{ template "footer" .meta }} {{ end }}