feat: also parse folder content
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.max-richter.dev/max/marka/parser"
|
||||
)
|
||||
|
||||
type LocalFsAdapter struct {
|
||||
@@ -32,11 +34,24 @@ func (l LocalFsAdapter) readDir(path string, root string) (FsResponse, error) {
|
||||
entryType = contentTypeFor(e.Name())
|
||||
}
|
||||
|
||||
var content any
|
||||
if !e.IsDir() && entryType == "application/markdown" {
|
||||
entryPath := filepath.Join(path, e.Name())
|
||||
fileContent, err := os.ReadFile(entryPath)
|
||||
if err == nil {
|
||||
parsedContent, err := parser.ParseFile(string(fileContent))
|
||||
if err == nil {
|
||||
content = parsedContent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out = append(out, FsDirEntry{
|
||||
Name: e.Name(),
|
||||
Type: entryType,
|
||||
IsDir: e.IsDir(),
|
||||
ModTime: info.ModTime(),
|
||||
Content: content,
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,7 @@ type FsDirEntry struct {
|
||||
Type string `json:"type"`
|
||||
IsDir bool `json:"isDir,omitempty"`
|
||||
ModTime time.Time `json:"modTime"`
|
||||
Content any `json:"content,omitempty"`
|
||||
}
|
||||
|
||||
type FsDir struct {
|
||||
|
Reference in New Issue
Block a user