diff options
| author | Julian Hurst <julian.hurst92@gmail.com> | 2020-10-16 11:59:13 +0200 |
|---|---|---|
| committer | Julian Hurst <julian.hurst92@gmail.com> | 2020-10-16 11:59:13 +0200 |
| commit | e949e31dcb6959b6352f2f9123b945e7432da7cf (patch) | |
| tree | b140f15475ebb881818c3d7c69bae9eca5e6d324 | |
| parent | 5a1ed892243de630ebb0e145e7989193eab4bdb6 (diff) | |
| download | grimtube-e949e31dcb6959b6352f2f9123b945e7432da7cf.tar.gz | |
Available langs as slice
| -rw-r--r-- | grimtube.go | 13 | ||||
| -rw-r--r-- | templates/index.html | 6 | ||||
| -rw-r--r-- | templates/search.html | 10 |
3 files changed, 22 insertions, 7 deletions
diff --git a/grimtube.go b/grimtube.go index ef51f0c..5df86aa 100644 --- a/grimtube.go +++ b/grimtube.go @@ -13,6 +13,10 @@ import ( "grimtube/ytparser" ) +func getLangs() []string { + return []string{"en", "fr", "de"} +} + func serve(w http.ResponseWriter, templatePath string, data interface{}) { funcMap := template.FuncMap { "inc": func(i int) int { @@ -33,7 +37,12 @@ func serve(w http.ResponseWriter, templatePath string, data interface{}) { } func index(w http.ResponseWriter, r *http.Request) { - serve(w, "templates/index.html", nil) + data := struct { + Langs []string + }{ + getLangs(), + } + serve(w, "templates/index.html", data) } func search(w http.ResponseWriter, r *http.Request) { @@ -70,11 +79,13 @@ func search(w http.ResponseWriter, r *http.Request) { Term string Page int Lang string + Langs []string }{ items, term, page, lang, + getLangs(), } serve(w, "templates/search.html", data) } diff --git a/templates/index.html b/templates/index.html index 4b16728..434a34f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,9 +3,9 @@ <form action="/search" method="get"> <input id="term" name="term" type="text" placeholder="search" required> <select id="lang" name="lang"> - <option>en</option> - <option>fr</option> - <option>de</option> + {{range .Langs}} + <option> {{.}}</option> + {{end}} </select> </form> {{end}} diff --git a/templates/search.html b/templates/search.html index e5a8e34..8a75962 100644 --- a/templates/search.html +++ b/templates/search.html @@ -3,9 +3,13 @@ <form action="/search" method="get"> <input id="term" name="term" type="text" placeholder="search" required> <select id="lang" name="lang"> - <option>en</option> - <option>fr</option> - <option>de</option> + {{range .Langs}} + {{if eq . $.Lang}} + <option selected>{{.}}</option> + {{else}} + <option>{{.}}</option> + {{end}} + {{end}} </select> </form> <table> |
