Files
LuPhoto/internal/site/site.go
T
lucioandClaude Opus 5.5 18a397653a M1: processor CLI
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 04:07:45 -08:00

117 lines
3.0 KiB
Go

package site
import (
"embed"
"html/template"
"io"
"github.com/luciochen233/luphoto/internal/process"
)
//go:embed templates/*.html
var templateFiles embed.FS
var templates = template.Must(template.ParseFS(templateFiles, "templates/*.html"))
type Tiles struct {
Format string `json:"format"`
TileSize int `json:"tile_size"`
Overlap int `json:"overlap"`
Path string `json:"path"`
}
type Photo struct {
process.Pyramid
Title string `json:"title,omitempty"`
Caption string `json:"caption,omitempty"`
Alt string `json:"alt,omitempty"`
Slides int `json:"slides"`
EXIF *process.EXIF `json:"exif,omitempty"`
}
type Manifest struct {
Build string `json:"build"`
Slug string `json:"slug"`
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"`
Date string `json:"date,omitempty"`
Order *int `json:"order,omitempty"`
Hidden bool `json:"hidden,omitempty"`
CollapsedFocusY float64 `json:"collapsed_focus_y"`
ShowEXIF bool `json:"show_exif"`
Tiles Tiles `json:"tiles"`
Cover *process.Pyramid `json:"cover"`
Photos []Photo `json:"photos"`
}
type IndexAlbum struct {
Slug string `json:"slug"`
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"`
Date string `json:"date,omitempty"`
CollapsedFocusY float64 `json:"collapsed_focus_y"`
Photos int `json:"photos"`
Manifest string `json:"manifest"`
Cover *process.Pyramid `json:"cover"`
}
type Index struct {
Build string `json:"build"`
Tiles Tiles `json:"tiles"`
Albums []IndexAlbum `json:"albums"`
}
func IndexURL(build string) string {
return "/index." + build + ".json"
}
func ManifestURL(build, slug string) string {
return "/a/" + slug + "/manifest." + build + ".json"
}
func ManifestName(build string) string {
return "manifest." + build + ".json"
}
func IndexName(build string) string {
return "index." + build + ".json"
}
type indexPage struct {
Build string
IndexURL string
Albums []IndexAlbum
}
type albumPage struct {
Build string
Slug string
Title string
Subtitle string
Date string
Photos int
ManifestURL string
IndexURL string
}
func RenderIndex(w io.Writer, index *Index) error {
return templates.ExecuteTemplate(w, "index.html", indexPage{
Build: index.Build,
IndexURL: IndexURL(index.Build),
Albums: index.Albums,
})
}
func RenderAlbum(w io.Writer, m *Manifest) error {
return templates.ExecuteTemplate(w, "album.html", albumPage{
Build: m.Build,
Slug: m.Slug,
Title: m.Title,
Subtitle: m.Subtitle,
Date: m.Date,
Photos: len(m.Photos),
ManifestURL: ManifestURL(m.Build, m.Slug),
IndexURL: IndexURL(m.Build),
})
}