feat: range over files for paths
All checks were successful
/ deploy (push) Successful in 46s

This commit is contained in:
ange 2024-12-14 09:19:13 +00:00
parent e9fc659a5a
commit 186491250e
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
3 changed files with 13 additions and 15 deletions

View File

@ -9,21 +9,23 @@ import (
var TMPL map[string][]byte
// TODO not use a global
// TODO use range instead of if else in header.html
func generateTmpl() {
files, _ := filepath.Glob("html/*.html")
re := regexp.MustCompile("html(/.+).html")
re := regexp.MustCompile("html/(.+).html")
names := make([]string, len(files))
for i, f := range files {
names[i] = re.FindStringSubmatch(f)[1]
}
TMPL = make(map[string][]byte, len(files))
for _, f := range files {
for i, f := range files {
b := new(bytes.Buffer)
name := re.FindStringSubmatch(f)[1]
t, _ := template.ParseFiles(f)
t.ParseGlob("tmpl/*.tmpl")
t.Execute(b, map[string]any{
"name": name,
"name": names[i],
"names": names,
})
TMPL[name] = b.Bytes()
TMPL["/" + names[i]] = b.Bytes()
}
}

View File

@ -5,8 +5,7 @@ import (
)
func index(w http.ResponseWriter, r *http.Request) {
r.URL.Path = "/contact"
html(w, r)
http.Redirect(w, r, "/contact", http.StatusMovedPermanently)
}
func style(w http.ResponseWriter, r *http.Request) {

View File

@ -4,12 +4,9 @@
<span class="right" style="font-size: .4em;">Website heavily inspired from <a href="//suckless.org/" target="_blank" rel="noreferrer noopener">suckless.org</a></span>
</div>
<div id="menu">
{{if eq .name "/contact"}}
<a href="/"><b>contact</b></a>
<a href="/resume">resume</a>
{{else if eq .name "/resume"}}
<a href="/">contact</a>
<a href="/resume"><b>resume</b></a>
{{$name := .name}}
{{range .names}}
<a href="/{{.}}">{{if eq $name .}}<b>{{.}}</b>{{else}}{{.}}{{end}}</a>
{{end}}
<span class="right">
<a href="//git.gmoker.com/yw5n" target="_blank" rel="noreferrer noopener">source</a>