Files
at-container-registry/themes/seamark/embed.go
T

68 lines
1.9 KiB
Go

// Package seamark provides the Seamark visual theme for the ATCR AppView.
// Import with a blank identifier to register: _ "atcr.io/themes/seamark"
// Enable with ATCR_UI_THEME=seamark.
package seamark
import (
"embed"
"io/fs"
"atcr.io/pkg/appview"
)
//go:embed public
var publicFS embed.FS
//go:embed theme.css
var themeCSS string
func init() {
appview.RegisterTheme("seamark", branding)
}
func branding() *appview.BrandingOverrides {
// Strip the leading "public" directory so the overlay FS matches the
// structure expected by resolvePublicFS (which looks under "public/").
pubSub, err := fs.Sub(publicFS, "public")
if err != nil {
panic("seamark: bad embed layout: " + err.Error())
}
return &appview.BrandingOverrides{
PublicFS: prefixFS{sub: pubSub},
ExtraCSS: themeCSS,
}
}
// prefixFS re-adds the "public/" prefix so the overlay FS works with
// atcr.io's resolvePublicFS which opens paths like "public/favicon.svg".
type prefixFS struct{ sub fs.FS }
func (p prefixFS) Open(name string) (fs.File, error) {
const prefix = "public/"
if len(name) > len(prefix) && name[:len(prefix)] == prefix {
return p.sub.Open(name[len(prefix):])
}
// Non-public paths: return not-found so the overlay falls through.
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist}
}
func (p prefixFS) ReadDir(name string) ([]fs.DirEntry, error) {
const prefix = "public/"
if name == "public" {
return fs.ReadDir(p.sub, ".")
}
if len(name) > len(prefix) && name[:len(prefix)] == prefix {
return fs.ReadDir(p.sub, name[len(prefix):])
}
return nil, &fs.PathError{Op: "readdir", Path: name, Err: fs.ErrNotExist}
}
func (p prefixFS) ReadFile(name string) ([]byte, error) {
const prefix = "public/"
if len(name) > len(prefix) && name[:len(prefix)] == prefix {
return fs.ReadFile(p.sub, name[len(prefix):])
}
return nil, &fs.PathError{Op: "readfile", Path: name, Err: fs.ErrNotExist}
}