Files
cdnutterandClaude Opus 5.5 ddf2157e63 Add list styles: Podium, Spotlight, Grid, List
- Each list picks a style in List settings (new lists default to Podium);
  existing lists keep Grid or List
- Podium: top 3 on medal-colored steps (#1 center and raised), the rest
  behind a native <details> "Show N more"; stacks #1 over #2/#3 on phones
- Spotlight: #1 as a feature card (art, why-note or description, play
  button), the rest as a numbered list
- Visitors can switch styles on a list page (?style=), preserved across
  pages; later pages fall back to a plain list since they don't start at #1
- Entries' detail data now lives on a wrapper per list, so featured and
  collapsed entries all open the detail view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 11:18:44 -07:00

86 lines
2.0 KiB
Go

package server
import (
"encoding/json"
"html/template"
"net/http"
"github.com/cdnutter/canon/internal/store"
)
// adminPage carries a JSON blob the page script boots from.
type adminPage struct {
Boot template.JS
List *store.List
}
func bootJSON(v any) template.JS {
b, _ := json.Marshal(v)
return template.JS(b)
}
type sizeLimits struct {
Max int `json:"max"`
Recommended int `json:"recommended"`
Warn int `json:"warn"`
}
var limits = sizeLimits{store.MaxListSize, store.RecommendedListSize, store.SoftListSizeWarning}
func (s *Server) handleAdminLists(w http.ResponseWriter, r *http.Request) {
lists, err := s.store.Lists(r.Context(), true)
if err != nil {
s.serverError(w, r, err)
return
}
if lists == nil {
lists = []store.List{}
}
covers, err := s.store.ListCovers(r.Context(), 3)
if err != nil {
s.serverError(w, r, err)
return
}
s.render(w, r, http.StatusOK, "admin_lists", "Your lists", adminPage{Boot: bootJSON(map[string]any{
"lists": lists,
"covers": covers,
"styles": store.ListStyles,
"categories": store.Categories,
"limits": limits,
})})
}
func (s *Server) handleAdminList(w http.ResponseWriter, r *http.Request) {
id, err := pathID(r)
if err != nil {
s.notFound(w, r)
return
}
l, err := s.store.ListByID(r.Context(), id)
if err != nil {
s.notFound(w, r)
return
}
cat := listCategory(l)
provider := ""
if p, err := s.providers.For(r.Context(), l.Category); err == nil {
provider = p.Label()
}
s.render(w, r, http.StatusOK, "admin_list", l.Title, adminPage{List: &l, Boot: bootJSON(map[string]any{
"list": l,
"category": cat,
"categories": store.Categories,
"limits": limits,
"provider": provider,
"productions": store.TheaterProductions,
"styles": store.ListStyles,
"pageSize": listPageSize,
})})
}
func (s *Server) handleAdminSettings(w http.ResponseWriter, r *http.Request) {
s.render(w, r, http.StatusOK, "admin_settings", "Settings", adminPage{Boot: bootJSON(map[string]any{
"categories": store.Categories,
})})
}