diff options
Diffstat (limited to 'pkg/index/filters.go')
| -rw-r--r-- | pkg/index/filters.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/index/filters.go b/pkg/index/filters.go index f59a5d6..315d125 100644 --- a/pkg/index/filters.go +++ b/pkg/index/filters.go @@ -5,6 +5,7 @@ import ( "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 @@ -21,6 +22,17 @@ func NewMaxFilesizeFilter(size int64) DocFilter { } } +func NewFilenameFilter(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 + } +} + func YamlHeaderFilter(_ infoPath, r io.ReadSeeker) bool { const bufSize = 4096 buf := make([]byte, bufSize) @@ -80,5 +92,5 @@ func YamlHeaderFilter(_ infoPath, r io.ReadSeeker) bool { } func DefaultFilters() []DocFilter { - return []DocFilter{NewExtensionFilter(".md"), NewMaxFilesizeFilter(200 * 1024)} + return []DocFilter{NewExtensionFilter(".md"), NewMaxFilesizeFilter(200 * 1024), YamlHeaderFilter} } |
