feat: also parse folder content

This commit is contained in:
Max Richter
2025-10-04 13:16:16 +02:00
parent a5acef77a2
commit fa283d5dd7
4 changed files with 30 additions and 2 deletions

View File

@@ -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,
})
}

View File

@@ -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 {