diff options
| -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) |
