mirror of
https://github.com/Kugelschieber/schnittfest.git
synced 2026-01-18 18:30:27 +00:00
Added basic template rendering.
This commit is contained in:
5
pages/footer.go
Normal file
5
pages/footer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package pages
|
||||
|
||||
var footerComponentI18n = map[string]map[string]string{
|
||||
"de": {},
|
||||
}
|
||||
@@ -1 +1,38 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"github.com/Kugelschieber/schnittfest/util"
|
||||
"github.com/emvi/logbuch"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var landingPageI18n = map[string]map[string]string{
|
||||
"de": {
|
||||
"test": "Hello World",
|
||||
},
|
||||
}
|
||||
|
||||
func LandingPageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tpl := tplCache.GetTemplate(landingPageTemplate)
|
||||
|
||||
if tpl == nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
langCode := util.GetLangCode(r)
|
||||
data := struct {
|
||||
Vars map[string]string
|
||||
NavbarVars map[string]string
|
||||
FooterVars map[string]string
|
||||
}{
|
||||
landingPageI18n[langCode],
|
||||
navbarComponentI18n[langCode],
|
||||
footerComponentI18n[langCode],
|
||||
}
|
||||
|
||||
if err := tpl.Execute(w, &data); err != nil {
|
||||
logbuch.Error("Error rendering landing page", logbuch.Fields{"err": err})
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
5
pages/navbar.go
Normal file
5
pages/navbar.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package pages
|
||||
|
||||
var navbarComponentI18n = map[string]map[string]string{
|
||||
"de": {},
|
||||
}
|
||||
43
pages/template.go
Normal file
43
pages/template.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"github.com/Kugelschieber/schnittfest/util"
|
||||
"github.com/emvi/logbuch"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultTemplateBase = "template"
|
||||
landingPageTemplate = "landing_page"
|
||||
notfoundPageTemplate = "notfound_page"
|
||||
)
|
||||
|
||||
var (
|
||||
tplCache *util.TemplateCache
|
||||
)
|
||||
|
||||
func LoadTemplates() {
|
||||
tplCache = util.NewTemplateCache()
|
||||
templateBase := os.Getenv("SCHNITTFEST_TEMPLATE_BASE")
|
||||
|
||||
if templateBase == "" {
|
||||
templateBase = defaultTemplateBase
|
||||
}
|
||||
|
||||
if _, err := tplCache.ParseFiles(landingPageTemplate, filepath.Join(templateBase, "landing_page.html"),
|
||||
filepath.Join(templateBase, "head.html"),
|
||||
filepath.Join(templateBase, "end.html"),
|
||||
filepath.Join(templateBase, "navbar.html"),
|
||||
filepath.Join(templateBase, "footer.html")); err != nil {
|
||||
logbuch.Fatal("Error loading landing page template", logbuch.Fields{"err": err})
|
||||
}
|
||||
|
||||
if _, err := tplCache.ParseFiles(notfoundPageTemplate, filepath.Join(templateBase, "404_page.html"),
|
||||
filepath.Join(templateBase, "head.html"),
|
||||
filepath.Join(templateBase, "end.html"),
|
||||
filepath.Join(templateBase, "navbar.html"),
|
||||
filepath.Join(templateBase, "footer.html")); err != nil {
|
||||
logbuch.Fatal("Error loading 404 page template", logbuch.Fields{"err": err})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user