46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
"github.com/gorilla/sessions"
|
|
"html/template"
|
|
)
|
|
|
|
func AboutHandler(app *App) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
session := r.Context().Value("session").(*sessions.Session)
|
|
loggedIn := session.Values["user_id"] != nil
|
|
cookie, _ := r.Cookie("threadr_cookie_banner")
|
|
|
|
aboutContent, err := ioutil.ReadFile("config/about.template")
|
|
if err != nil {
|
|
log.Printf("Error reading about.template: %v", err)
|
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
data := struct {
|
|
PageData
|
|
AboutContent template.HTML
|
|
}{
|
|
PageData: PageData{
|
|
Title: "ThreadR - About",
|
|
Navbar: "about",
|
|
LoggedIn: loggedIn,
|
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
|
BasePath: app.Config.ThreadrDir,
|
|
StaticPath: app.Config.ThreadrDir + "/static",
|
|
CurrentURL: r.URL.Path,
|
|
},
|
|
AboutContent: template.HTML(aboutContent),
|
|
}
|
|
|
|
if err := app.Tmpl.ExecuteTemplate(w, "about", data); err != nil {
|
|
log.Printf("Error executing template in AboutHandler: %v", err)
|
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|
|
} |