diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-05-04 18:23:44 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-05-04 18:23:44 -0400 |
| commit | 3e533e65f1baf26355675cfe244fd4da64e8807c (patch) | |
| tree | 3c8a752644ed4da1f0bf64ce3e049cac3775e646 /pkg/index/filters.go | |
| parent | 37a96c43f6df141dc745f239891f4163b8870c02 (diff) | |
Add names to doc fitlers
Diffstat (limited to 'pkg/index/filters.go')
| -rw-r--r-- | pkg/index/filters.go | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/pkg/index/filters.go b/pkg/index/filters.go index 315d125..7766b4c 100644 --- a/pkg/index/filters.go +++ b/pkg/index/filters.go @@ -1,39 +1,70 @@ package index import ( + "fmt" "io" "path/filepath" ) // NOTE: in the future it would be interesting lua filters -// TODO: create excluded path filter factory -type DocFilter func(infoPath, io.ReadSeeker) bool +type DocFilter struct { + Name string + Filter func(infoPath, io.ReadSeeker) bool +} func NewExtensionFilter(ext string) DocFilter { - return func(ip infoPath, _ io.ReadSeeker) bool { - return filepath.Ext(ip.path) == ext + return DocFilter{ + ext + " Filter", + func(ip infoPath, _ io.ReadSeeker) bool { + return filepath.Ext(ip.path) == ext + }, } } func NewMaxFilesizeFilter(size int64) DocFilter { - return func(ip infoPath, _ io.ReadSeeker) bool { - return ip.info.Size() <= size + return DocFilter{ + fmt.Sprintf("Max Size Filter %d", size), + func(ip infoPath, _ io.ReadSeeker) bool { + return ip.info.Size() <= size + }, } } -func NewFilenameFilter(excluded []string) DocFilter { +func NewExcludeFilenameFilter(excluded []string) DocFilter { excludedSet := make(map[string]bool, len(excluded)) for _, filename := range excluded { excludedSet[filename] = true } - return func(ip infoPath, _ io.ReadSeeker) bool { - _, ok := excludedSet[filepath.Base(ip.path)] - return ok + return DocFilter{ + "Excluded Filename filter", + func(ip infoPath, _ io.ReadSeeker) bool { + _, ok := excludedSet[filepath.Base(ip.path)] + return !ok + }, + } +} + +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 + }, + } +} + +var YamlHeaderFilter = DocFilter{ + "YAML Header Filter", + yamlHeaderFilterFunc, } -func YamlHeaderFilter(_ infoPath, r io.ReadSeeker) bool { +func yamlHeaderFilterFunc(_ infoPath, r io.ReadSeeker) bool { const bufSize = 4096 buf := make([]byte, bufSize) |
