Merge pull request 'FEAT: directory stylesheet overrides' (#9) from supitszaire/indir:main into main

Reviewed-on: https://codeberg.org/arimelody/indir/pulls/9
This commit is contained in:
ari melody 2026-03-17 20:40:05 +01:00
commit 57f31343de
3 changed files with 26 additions and 4 deletions

View file

@ -16,17 +16,25 @@ indir [--host address] [--port port] [--root http_root] directory
--root http_root hosts on the specified subdirectory, i.e. `/files/`
```
## customization
## features
### readme
### file serving
indir has the possibility of automatically serving an `index.html` instead of displaying the directory view!
### customization
#### readme
drop a `README.md` into any directory and indir will render
it below the file listing with full markdown support!
#### custom css
using a 'index.css' file, you can customize the directory view!
---
## 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
- [x] fix mime-types for browser file view

11
main.go
View file

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

View file

@ -142,6 +142,9 @@
}
}
</style>
{{if .CSS}}
<style>{{.CSS}}</style>
{{end}}
</head>
<body>
<main>