package internal import ( "log" "net/http" "slices" "github.com/labstack/echo/v4" ) func (s *Server) handleHome(c echo.Context) error { return s.renderFullPage(c, PageHome, PageSections[PageHome][0]) } func (s *Server) handlePage(c echo.Context) error { page := c.Param("page") if !validPage(page) { return c.String(http.StatusNotFound, "Page not found") } return s.renderFullPage(c, page, PageSections[page][0]) } func (s *Server) handlePageSection(c echo.Context) error { page := c.Param("page") section := c.Param("section") if !validPage(page) { return c.String(http.StatusNotFound, "Page not found") } if !validSection(page, section) { return c.String(http.StatusNotFound, "Section not found") } return s.renderFullPage(c, page, section) } func (s *Server) handleHTMXPage(c echo.Context) error { page := c.Param("page") if !validPage(page) { return c.String(http.StatusNotFound, "Page not found") } content, err := s.tmpl.GetContent(page, PageSections[page][0]) if err != nil { log.Printf("Error rendering content for %s: %v", page, err) return c.String( http.StatusInternalServerError, "Error loading content") } data := PageData { Page: page, Pages: ValidPages, Sections: PageSections[page], Content: content, } return c.Render(http.StatusOK, "page.html", data) } func (s *Server) handleHTMXSection(c echo.Context) error { page := c.Param("page") section := c.Param("section") if !validPage(page) { return c.String(http.StatusNotFound, "Page not found") } if !validSection(page, section) { return c.String(http.StatusNotFound, "Section not found") } return s.renderContent(c, page, section) } func (s *Server) renderFullPage(c echo.Context, page, section string) error { content, err := s.tmpl.GetContent(page, section) if err != nil { log.Printf( "Error rendering content for %s/%s: %v", page, section, err) return c.String( http.StatusInternalServerError, "Error loading content") } data := PageData{ Page: page, Pages: ValidPages, Sections: PageSections[page], Content: content, } return c.Render(http.StatusOK, "layout.html", data) } func (s *Server) renderContent(c echo.Context, page, section string) error { content, err := s.tmpl.GetContent(page, section) if err != nil { log.Printf("Error rendering content for %s/%s: %v", page, section, err) return c.String( http.StatusInternalServerError, "Error loading content") } return c.HTML(http.StatusOK, string(content)) } func validPage(page string) bool { return slices.Contains(ValidPages, page) } func validSection(page, section string) bool { sections, exists := PageSections[page] if !exists { return false } return slices.Contains(sections, section) }