Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ go run main.go
go run main.go search
go run main.go add "Just a test"
go run main.go archive /path/to/2026/01/11/17.28_wip
go run main.go search -a
```

## Maintenance
Expand Down
18 changes: 13 additions & 5 deletions core/searching.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"fmt"
"io/fs"
"os"
"path/filepath"
"regexp"
Expand All @@ -19,11 +20,17 @@ var isoDateTimeBasicFormat = regexp.MustCompile(`^\d{4}\d{2}\d{2}T\d{2}\d{2}$`)

func Search(baseDirectory, searchTerm string, from time.Time, to time.Time) []LogbookEntry {
var result = make([]LogbookEntry, 0)
err := filepath.Walk(baseDirectory,
func(path string, info os.FileInfo, err error) error {

maxDepth := strings.Count(baseDirectory, string(os.PathSeparator)) + 4

err := filepath.WalkDir(baseDirectory,
func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() && strings.Count(path, string(os.PathSeparator)) > maxDepth {
return fs.SkipDir
}
if !isLogEntryFile(path) {
return nil
}
Expand Down Expand Up @@ -69,11 +76,12 @@ func isInRequestedTimeRange(datetime string, from time.Time, to time.Time) bool
}

func isLogEntryFile(path string) bool {
pathParts := strings.Split(path, string(os.PathSeparator))
lastPathPart := pathParts[len(pathParts)-1]
if !strings.HasSuffix(lastPathPart, ".md") {
if !strings.HasSuffix(path, ".md") {
return false
}

pathParts := strings.Split(path, string(os.PathSeparator))
lastPathPart := pathParts[len(pathParts)-1]
parentDirectory := pathParts[len(pathParts)-2]
if !(regexp.MustCompile(`^\d{2}\.\d{2}_.*`).MatchString(parentDirectory)) {
return false
Expand Down