mirror of
https://github.com/patriceckhart/zot.git
synced 2026-06-26 21:36:31 +02:00
- User themes from $ZOT_HOME/themes/*.json with partial overrides (colors, syntax, spinner) and dark/light fallback. - /settings color-theme picker; selection persisted in config.json. - Theme-only extensions: extension.json plus theme.json (or themes/theme.json) load without spawning a subprocess. - write-zot-themes built-in skill and docs/themes.md. - README, extensions docs, and embedded docs index updated.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package docs
|
|
|
|
import (
|
|
"bytes"
|
|
"embed"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
)
|
|
|
|
// embeddedDocs holds zot's user-facing documentation so installed
|
|
// binaries do not depend on a source checkout existing on disk.
|
|
//
|
|
//go:embed README.md docs/*.md
|
|
var embeddedDocs embed.FS
|
|
|
|
var docFiles = map[string]string{
|
|
"README.md": "README.md",
|
|
"extensions.md": "docs/extensions.md",
|
|
"rpc.md": "docs/rpc.md",
|
|
"skills.md": "docs/skills.md",
|
|
"themes.md": "docs/themes.md",
|
|
}
|
|
|
|
// EnsureInstalled writes the embedded docs into $ZOT_HOME/docs and
|
|
// returns that directory. Existing files are left untouched when their
|
|
// content already matches the embedded copy.
|
|
func EnsureInstalled(zotHome string) (string, error) {
|
|
dir := filepath.Join(zotHome, "docs")
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
return dir, err
|
|
}
|
|
|
|
names := make([]string, 0, len(docFiles))
|
|
for name := range docFiles {
|
|
names = append(names, name)
|
|
}
|
|
sort.Strings(names)
|
|
|
|
for _, name := range names {
|
|
src := docFiles[name]
|
|
data, err := fs.ReadFile(embeddedDocs, src)
|
|
if err != nil {
|
|
return dir, err
|
|
}
|
|
dst := filepath.Join(dir, name)
|
|
if existing, err := os.ReadFile(dst); err == nil && bytes.Equal(existing, data) {
|
|
continue
|
|
}
|
|
if err := os.WriteFile(dst, data, 0o644); err != nil {
|
|
return dir, err
|
|
}
|
|
}
|
|
return dir, nil
|
|
}
|