diff options
| author | Julian Hurst <julian.hurst92@gmail.com> | 2021-01-12 00:51:42 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst92@gmail.com> | 2021-01-12 00:51:42 +0100 |
| commit | 0947552992261ae28a5efaf18d4021994c7f38f9 (patch) | |
| tree | ae99510b986b5f10b071e5505657b4ec28c55a2d | |
| parent | 3e0d197bfbea2b093b9d120dcd6c5071bf34cf4e (diff) | |
| download | grimtube-0947552992261ae28a5efaf18d4021994c7f38f9.tar.gz | |
Add custom docPath flag
| -rw-r--r-- | grimtube.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/grimtube.go b/grimtube.go index 86c102a..e768c12 100644 --- a/grimtube.go +++ b/grimtube.go @@ -8,11 +8,13 @@ import ( //"io" "log" "strconv" - //"path" + "path" "git.sr.ht/~ark/ytparser" ) +var docPath string + func getLangs() []string { return []string{"en", "fr", "de", "ja", "ru"} } @@ -22,6 +24,8 @@ func getOrders() []string { } func serve(w http.ResponseWriter, templatePath string, data interface{}) { + tmplPath := path.Join(docPath, templatePath) + basePath := path.Join(docPath, "templates/base.html") funcMap := template.FuncMap { "inc": func(i int) int { return i + 1 @@ -30,7 +34,7 @@ func serve(w http.ResponseWriter, templatePath string, data interface{}) { return i - 1 }, } - t, err := template.New("base.html").Funcs(funcMap).ParseFiles("templates/base.html", templatePath) + t, err := template.New("base.html").Funcs(funcMap).ParseFiles(basePath, tmplPath) if err != nil { panic(err) } else { @@ -145,9 +149,11 @@ func favicon(w http.ResponseWriter, r *http.Request) { func main() { port := flag.Int("p", 8080, "The port to bind to.") + dir := flag.String("d", "", "Location of the templates and static resources.") flag.Parse() + docPath = *dir fs := http.FileServer(http.Dir("static")) - http.Handle("/static/", http.StripPrefix("/static/", fs)) + http.Handle("/static/", http.StripPrefix(path.Join(docPath, "/static/"), fs)) http.HandleFunc("/favicon.ico", favicon) http.HandleFunc("/", index) http.HandleFunc("/search", search) |
