summaryrefslogtreecommitdiffstats
path: root/routes/template.go
diff options
context:
space:
mode:
authorLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-12 20:53:58 +0530
committerLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-12 20:53:58 +0530
commit82b8afe19b77fe02e1a29a5b5e20882d8e5c3fc5 (patch)
tree2173a518664b81e0134853c4c6dee09973377a87 /routes/template.go
parent7d99afc5cd3ddfc7a875754f4593812b8c2664c8 (diff)
downloadlegit-82b8afe19b77fe02e1a29a5b5e20882d8e5c3fc5.tar.gz
legit-82b8afe19b77fe02e1a29a5b5e20882d8e5c3fc5.tar.bz2
legit-82b8afe19b77fe02e1a29a5b5e20882d8e5c3fc5.zip
routes: render readme
Diffstat (limited to '')
-rw-r--r--routes/template.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/routes/template.go b/routes/template.go
index 55a0d17..bc1dd37 100644
--- a/routes/template.go
+++ b/routes/template.go
@@ -6,22 +6,25 @@ import (
"net/http"
"path/filepath"
- "icyphox.sh/legit/config"
"icyphox.sh/legit/git"
)
-func Write404(w http.ResponseWriter, c config.Config) {
+func (d *deps) Write404(w http.ResponseWriter) {
+ tpath := filepath.Join(d.c.Template.Dir, "*")
+ t := template.Must(template.ParseGlob(tpath))
w.WriteHeader(404)
- tpath := filepath.Join(c.Template.Dir, "404.html")
- t := template.Must(template.ParseFiles(tpath))
- t.Execute(w, nil)
+ if err := t.ExecuteTemplate(w, "404", nil); err != nil {
+ log.Printf("404 template: %s", err)
+ }
}
-func Write500(w http.ResponseWriter, c config.Config) {
+func (d *deps) Write500(w http.ResponseWriter) {
+ tpath := filepath.Join(d.c.Template.Dir, "*")
+ t := template.Must(template.ParseGlob(tpath))
w.WriteHeader(500)
- tpath := filepath.Join(c.Template.Dir, "500.html")
- t := template.Must(template.ParseFiles(tpath))
- t.Execute(w, nil)
+ if err := t.ExecuteTemplate(w, "500", nil); err != nil {
+ log.Printf("500 template: %s", err)
+ }
}
func (d *deps) listFiles(files []git.NiceTree, data map[string]any, w http.ResponseWriter) {