diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-05-02 17:22:14 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-05-02 17:22:14 -0400 |
| commit | 37a96c43f6df141dc745f239891f4163b8870c02 (patch) | |
| tree | 1014bf3ca04b4ad078a7819ac97fb5d6afda921d /pkg/index/filters.go | |
| parent | 966a1162a56652b4d56ffe003af05161841fb192 (diff) | |
Implement YAML header parsing
Parses `title` and `tags` fields using default behavior.
Custom parsing logic is used for `author` (single and multiauthor
support), `date` (parses into `time.Time`), and meta (collects all other
header fields into a YAML string).
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} } |
