package fiesta import ( _ "embed" "encoding/json" "maps" "sync" ) // Source says where one example state came from when the examples were // seeded: the kind of thing it was in the gallery it was taken from (a // partial, an idiom, a shell, a format or a screen), that thing's name, // which of its states, the locale it was rendered in, and, for a shell, // which view of it (index or page). A server whose templates render the // same parts can hold its output to the example a Source names. type Source struct { Kind string `json:"kind"` Source string `json:"source"` State int `json:"state"` Locale string `json:"locale"` View string `json:"view,omitempty"` } // sourcesJSON is the seed's record, kept where the seeding wrote it. // //go:embed hack/seed/sources.json var sourcesJSON []byte // sources is sourcesJSON read once. The file is embedded, so a record // that does not read is a broken build rather than a condition to // report: the panic says so. var sources = sync.OnceValue(func() map[string]Source { var out map[string]Source if err := json.Unmarshal(sourcesJSON, &out); err != nil { panic("fiesta: hack/seed/sources.json does not read: " + err.Error()) } return out }) // Sources returns where every seeded example state came from, keyed by // its path under examples/ without the .html: "badge/positive" for // examples/badge/positive.html. The returned map is a copy, so a caller // that edits it cannot change the next caller's. func Sources() map[string]Source { return maps.Clone(sources()) }