diff options
Diffstat (limited to 'internal/behavior/store.go')
| -rw-r--r-- | internal/behavior/store.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/behavior/store.go b/internal/behavior/store.go index 4051836..f2e9350 100644 --- a/internal/behavior/store.go +++ b/internal/behavior/store.go @@ -12,12 +12,32 @@ import ( "gopkg.in/yaml.v3" ) +// excludedContentPath reports whether path lies under a directory or file +// whose name starts with "_", relative to root. That is the project's +// convention for work-in-progress content that must not be loaded, validated, +// indexed, or published while a builder is still authoring it. +func excludedContentPath(root, path string) bool { + rel, err := filepath.Rel(root, path) + if err != nil { + return false + } + for _, part := range strings.Split(rel, string(os.PathSeparator)) { + if strings.HasPrefix(part, "_") { + return true + } + } + return false +} + func BuildPathIndex(dir string) map[string]string { index := make(map[string]string) filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") { return nil } + if excludedContentPath(dir, path) { + return nil + } id := strings.TrimSuffix(d.Name(), ".yaml") index[id] = path return nil @@ -31,6 +51,9 @@ func BuildRoomIndex(dir string) map[int]string { if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") { return nil } + if excludedContentPath(dir, path) { + return nil + } id := strings.TrimSuffix(d.Name(), ".yaml") n, convErr := strconv.Atoi(id) if convErr != nil { @@ -39,6 +62,11 @@ func BuildRoomIndex(dir string) map[int]string { // skip it here and let validation flag it. return nil } + // Room IDs are positive; every other code path treats <= 0 as "no + // room". A 0.yaml/-1.yaml must not become a real room. + if n <= 0 { + return nil + } index[n] = path return nil }) @@ -59,6 +87,9 @@ func WalkYAMLDir(dir string, fn func(path, id string, data []byte) error) error if d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") { return nil } + if excludedContentPath(dir, path) { + return nil + } data, readErr := os.ReadFile(path) if readErr != nil { if os.IsNotExist(readErr) { @@ -82,6 +113,9 @@ func CheckDuplicateIDs(dir string) []Duplicate { if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") { return nil } + if excludedContentPath(dir, path) { + return nil + } id := strings.TrimSuffix(d.Name(), ".yaml") seen[id] = append(seen[id], path) return nil |
