This commit is contained in:
parent
e9fc659a5a
commit
186491250e
16
src/tmpl.go
16
src/tmpl.go
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user