39 lines
1.4 KiB
Go
39 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"github.com/gorilla/sessions"
|
|
)
|
|
|
|
func NewsHandler(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")
|
|
newsItems := []string{
|
|
"2020-02-21 Whole Website updated: Homepage, News, Boards, About, Log In, Userhome, Log Out",
|
|
"2020-01-06 First Steps done",
|
|
}
|
|
data := struct {
|
|
PageData
|
|
News []string
|
|
}{
|
|
PageData: PageData{
|
|
Title: "ThreadR - News",
|
|
Navbar: "news",
|
|
LoggedIn: loggedIn,
|
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
|
BasePath: app.Config.ThreadrDir,
|
|
StaticPath: app.Config.ThreadrDir + "/static",
|
|
CurrentURL: r.URL.Path,
|
|
},
|
|
News: newsItems,
|
|
}
|
|
if err := app.Tmpl.ExecuteTemplate(w, "news", data); err != nil {
|
|
log.Printf("Error executing template in NewsHandler: %v", err)
|
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|
|
} |