Skip to content

Commit 35ca240

Browse files
committed
feat: ignore .git and logseq root folders
1 parent 47acecf commit 35ca240

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"os"
1010
"path/filepath"
11+
"regexp"
1112
"strings"
1213

1314
"golang.org/x/exp/slices"
@@ -20,7 +21,11 @@ type page struct {
2021
text string
2122
}
2223

23-
func findMatchingFiles(rootPath string, substring string) ([]string, error) {
24+
/*
25+
findMatchingFiles finds all files in rootPath that contain substring
26+
ignoreRegexp is an expression that is evaluated on **relative** path of files within the graph (e.g. `.git/HEAD` or `logseq/.bkp/something.md`) if it matches, the file is not processed
27+
*/
28+
func findMatchingFiles(rootPath string, substring string, ignoreRegexp *regexp.Regexp) ([]string, error) {
2429
var result []string
2530
err := filepath.WalkDir(rootPath, func(path string, d fs.DirEntry, walkError error) error {
2631
if walkError != nil {
@@ -29,6 +34,13 @@ func findMatchingFiles(rootPath string, substring string) ([]string, error) {
2934
if d.IsDir() {
3035
return nil
3136
}
37+
relativePath, err := filepath.Rel(rootPath, path)
38+
if err != nil {
39+
return err
40+
}
41+
if ignoreRegexp.MatchString(filepath.ToSlash(relativePath)) {
42+
return nil
43+
}
3244
file, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
3345
if err != nil {
3446
return err
@@ -62,7 +74,7 @@ func main() {
6274
flag.Usage()
6375
os.Exit(1)
6476
}
65-
publicFiles, err := findMatchingFiles(*graphPath, "public::")
77+
publicFiles, err := findMatchingFiles(*graphPath, "public::", regexp.MustCompile(`^(logseq|.git)/`))
6678
if err != nil {
6779
log.Fatalf("Error during walking through a folder %v", err)
6880
}

0 commit comments

Comments
 (0)