-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregator.go
47 lines (37 loc) · 858 Bytes
/
aggregator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package aggregator
import (
"fmt"
"io/fs"
"os"
"path/filepath"
)
// Common markdown extension
const (
markdownExt = ".md"
errorMessagePathNotFound = "posts path [%s] not found"
)
// AggregatePostPaths scans a posts folder recursively, gathering the markdown files,
// providing an array of their paths
func AggregatePostPaths(postsDirectory string) ([]string, error) {
paths := make([]string, 0)
if _, err := os.Stat(postsDirectory); err != nil {
return nil, fmt.Errorf(errorMessagePathNotFound, postsDirectory)
}
err := filepath.WalkDir(
postsDirectory,
func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
}
if filepath.Ext(path) != markdownExt {
return nil
}
paths = append(paths, path)
return nil
},
)
if err != nil {
return nil, err
}
return paths, nil
}