diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-06-12 03:17:08 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-06-12 03:17:08 -0400 |
| commit | fbf242cee18655daa13a85d57cf4465736380f35 (patch) | |
| tree | 434c4459423e0ccd083c74aba95f6b43cd8bb556 /pkg/index/filters.go | |
| parent | 61d89ee58e6a4d990e6e81c951731c80c2cd1ece (diff) | |
Add index filter for parent directories
Diffstat (limited to 'pkg/index/filters.go')
| -rw-r--r-- | pkg/index/filters.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/pkg/index/filters.go b/pkg/index/filters.go index a439185..3a22910 100644 --- a/pkg/index/filters.go +++ b/pkg/index/filters.go @@ -3,7 +3,10 @@ package index import ( "fmt" "io" + "os" "path/filepath" + "slices" + "strings" ) // NOTE: in the future it would be interesting lua filters @@ -32,29 +35,32 @@ func NewMaxFilesizeFilter(size int64) DocFilter { } func NewExcludeFilenameFilter(excluded []string) DocFilter { - excludedSet := make(map[string]bool, len(excluded)) - for _, filename := range excluded { - excludedSet[filename] = true - } return DocFilter{ "Excluded Filename filter", func(ip infoPath, _ io.ReadSeeker) bool { - _, ok := excludedSet[filepath.Base(ip.path)] - return !ok + filename := filepath.Base(ip.path) + return !slices.Contains(excluded, filename) }, } } func NewIncludeFilenameFilter(included []string) DocFilter { - includedSet := make(map[string]bool, len(included)) - for _, filename := range included { - includedSet[filename] = true - } return DocFilter{ "Included Filename filter", func(ip infoPath, _ io.ReadSeeker) bool { - _, ok := includedSet[filepath.Base(ip.path)] - return ok + filename := filepath.Base(ip.path) + return slices.Contains(included, filename) + }, + } +} + +// exclude files if it has a parent directory badParent +func NewExcludeParentFilter(badParent string) DocFilter { + return DocFilter{ + "Excluded Parent Directory filter", + func(ip infoPath, _ io.ReadSeeker) bool { + + return !slices.Contains(strings.Split(ip.path, string(os.PathSeparator)), badParent) }, } } @@ -135,5 +141,5 @@ func yamlHeaderPos(r io.ReadSeeker) int64 { } func DefaultFilters() []DocFilter { - return []DocFilter{NewExtensionFilter(".md"), NewMaxFilesizeFilter(200 * 1024), YamlHeaderFilter} + return []DocFilter{NewExtensionFilter(".md"), NewMaxFilesizeFilter(200 * 1024), NewExcludeParentFilter("templates"), YamlHeaderFilter} } |
