From eac93e08bb788f47f3765ba608650c4e79e9f2f1 Mon Sep 17 00:00:00 2001 From: zaire Date: Tue, 17 Mar 2026 20:16:28 +0100 Subject: [PATCH] FEAT: directory stylesheet overrides --- README.md | 4 ++-- main.go | 11 +++++++++++ templates/dir.html | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f6825ec..c72e245 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,6 @@ it below the file listing with full markdown support! ## to-do: - [x] use templates instead of hard-coded HTML (i was lazy) - [x] directory header from readme file -- [ ] directory stylesheet overrides +- [x] directory stylesheet overrides - [x] index.html serving support -- [x] fix mime-types for browser file view \ No newline at end of file +- [x] fix mime-types for browser file view diff --git a/main.go b/main.go index d01ac12..cc2247e 100755 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ type ( Root bool Files []*File Readme template.HTML + CSS template.CSS } File struct { @@ -181,6 +182,15 @@ func main() { return } + // load index.css if present + var customCSS template.CSS + cssPath := filepath.Join(fpath, "index.css") + if cssInfo, err := os.Stat(cssPath); err == nil && !cssInfo.IsDir() { + if src, err := os.ReadFile(cssPath); err == nil { + customCSS = template.CSS(src) + } + } + // embeded readme var readmeHTML template.HTML entries, err := os.ReadDir(fpath) @@ -205,6 +215,7 @@ func main() { Name: r.URL.Path, Files: []*File{}, Readme: readmeHTML, + CSS: customCSS, } fsDir := os.DirFS(fpath) diff --git a/templates/dir.html b/templates/dir.html index a885117..bd812e3 100644 --- a/templates/dir.html +++ b/templates/dir.html @@ -142,6 +142,9 @@ } } + {{if .CSS}} + + {{end}}