solutions: load a catalog without a disk (LoadFSWith, LoadBigPictureFS); skip *.conflict.md
LoadFSWith reads the Big Picture from its own fs.FS, so a catalog can be embedded -- the web wizard runs the engine in the browser as WebAssembly. The knowledge index leaves out wiki-sync conflict copies (*.conflict.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8a219a84b
commit
c1c0b8a116
4 files changed
+60
-6
No files matched your search
@@ -2,7 +2,9 @@ package catalog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -15,7 +17,8 @@ import (
|
||||
// here they are decoded leniently and only the fields the guide uses are
|
||||
// kept.
|
||||
type BigPicture struct {
|
||||
Dir string `json:"-"`
|
||||
Dir string `json:"-"`
|
||||
fsys fs.FS
|
||||
Title string `json:"title"`
|
||||
WebPath string `json:"webPath"` // "map/"
|
||||
Topics map[string]*BPTopic `json:"topics"`
|
||||
@@ -89,8 +92,14 @@ type BPInterface struct {
|
||||
|
||||
// LoadBigPicture reads dir/manifest.yaml and the files it names.
|
||||
func LoadBigPicture(dir string) (*BigPicture, error) {
|
||||
return LoadBigPictureFS(os.DirFS(dir), dir)
|
||||
}
|
||||
|
||||
// LoadBigPictureFS reads manifest.yaml and the files it names from fsys
|
||||
// (an embedded copy, e.g. in the browser); dir only names it in messages.
|
||||
func LoadBigPictureFS(fsys fs.FS, dir string) (*BigPicture, error) {
|
||||
bp := &BigPicture{
|
||||
Dir: dir, WebPath: "map/",
|
||||
Dir: dir, fsys: fsys, WebPath: "map/",
|
||||
Topics: map[string]*BPTopic{}, Stories: map[string]*BPStory{},
|
||||
Products: map[string]*BPProduct{}, Interfaces: map[string]BPInterface{},
|
||||
}
|
||||
@@ -157,7 +166,7 @@ func (bp *BigPicture) read(name string, v any) error {
|
||||
if name == "" {
|
||||
return fmt.Errorf("big picture: manifest names no file")
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join(bp.Dir, name))
|
||||
b, err := fs.ReadFile(bp.fsys, path.Clean(filepath.ToSlash(name)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("big picture: %w", err)
|
||||
}
|
||||
@@ -172,7 +181,7 @@ func (bp *BigPicture) read(name string, v any) error {
|
||||
}
|
||||
|
||||
func (bp *BigPicture) readDir(sub string, fn func(string) error) error {
|
||||
ents, err := os.ReadDir(filepath.Join(bp.Dir, sub))
|
||||
ents, err := fs.ReadDir(bp.fsys, path.Clean(filepath.ToSlash(sub)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("big picture: %w", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user