From 37a96c43f6df141dc745f239891f4163b8870c02 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Fri, 2 May 2025 17:22:14 -0400 Subject: 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). --- pkg/index/filters.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pkg/index/filters.go') 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} } -- cgit v1.2.3