added lang support to all html templates and cleaned up template rendering
This commit is contained in:
parent
5dd3114e2d
commit
d9d0301548
18 changed files with 645 additions and 410 deletions
19
video.go
19
video.go
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
@ -158,17 +157,12 @@ func handleVideoSearch(w http.ResponseWriter, settings UserSettings, query strin
|
|||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
tmpl, err := template.New("videos.html").Funcs(funcs).ParseFiles("templates/videos.html")
|
||||
if err != nil {
|
||||
printErr("Error parsing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.Execute(w, map[string]interface{}{
|
||||
// Prepare the data to pass to the template
|
||||
data := map[string]interface{}{
|
||||
"Results": results,
|
||||
"Query": query,
|
||||
"Fetched": fmt.Sprintf("%.2f seconds", elapsed.Seconds()),
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsed.Seconds(), Translate("seconds")),
|
||||
"Page": page,
|
||||
"HasPrevPage": page > 1,
|
||||
"HasNextPage": len(results) > 0,
|
||||
|
@ -177,11 +171,10 @@ func handleVideoSearch(w http.ResponseWriter, settings UserSettings, query strin
|
|||
"Theme": settings.Theme,
|
||||
"Safe": settings.SafeSearch,
|
||||
"IsThemeDark": settings.IsThemeDark,
|
||||
})
|
||||
if err != nil {
|
||||
printErr("Error executing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// Render the template without measuring time
|
||||
renderTemplate(w, "videos.html", data)
|
||||
}
|
||||
|
||||
func fetchVideoResults(query, safe, lang string, page int) []VideoResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue