diff --git a/config/loader.go b/config/loader.go index 4cea695..0e579c5 100644 --- a/config/loader.go +++ b/config/loader.go @@ -13,6 +13,7 @@ type config struct { WatchDelay string `json:"watch_delay"` SyncDir string `json:"sync_dir"` MetaFiles []string `json:"meta_files"` + Exclude []string `json:"exclude"` } var Settings config diff --git a/example/.ssgod.json b/example/.ssgod.json index dbb8eaf..d73b2de 100644 --- a/example/.ssgod.json +++ b/example/.ssgod.json @@ -4,6 +4,7 @@ "target": "public", "watch_delay": "500ms", "sync_dir": "static", + "exclude": [], "meta_files": [ "pages/sitemap.html" ] diff --git a/main.go b/main.go index 542219a..7465e26 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,8 @@ import ( "strings" "text/template" "time" + "regexp" + "slices" "github.com/fsnotify/fsnotify" "github.com/yuin/goldmark" @@ -187,6 +189,17 @@ func SamePath(a string, b string) bool { return filepath.ToSlash(a) == filepath.ToSlash(b) } +func ExcludedPath(fp string) bool { + is_layout := fp == config.Settings.Layout + is_excluded := slices.ContainsFunc(config.Settings.Exclude, func (s string) bool { + matches, err := regexp.MatchString(s, fp) + if err != nil { log.Panic("invalid excludes regex", s, "error: ", err) } + return matches + }) + + return is_layout || is_excluded +} + func ProcessDirEntry(path string, d fs.DirEntry, meta *PageMetaData) error { settings := config.Settings var err error = nil @@ -194,7 +207,7 @@ func ProcessDirEntry(path string, d fs.DirEntry, meta *PageMetaData) error { if !d.IsDir() && !SamePath(path, config.Settings.Layout) { source_name, ext, found := SplitPathExt(path) - if found && path != settings.Layout { + if found && !ExcludedPath(path) { target_path := RePrefixPath(path, settings.Target) err = MkdirPath(target_path)