FEAT: directory stylesheet overrides
This commit is contained in:
parent
523aa894d0
commit
eac93e08bb
3 changed files with 16 additions and 2 deletions
|
|
@ -27,6 +27,6 @@ it below the file listing with full markdown support!
|
||||||
## to-do:
|
## to-do:
|
||||||
- [x] use templates instead of hard-coded HTML (i was lazy)
|
- [x] use templates instead of hard-coded HTML (i was lazy)
|
||||||
- [x] directory header from readme file
|
- [x] directory header from readme file
|
||||||
- [ ] directory stylesheet overrides
|
- [x] directory stylesheet overrides
|
||||||
- [x] index.html serving support
|
- [x] index.html serving support
|
||||||
- [x] fix mime-types for browser file view
|
- [x] fix mime-types for browser file view
|
||||||
|
|
|
||||||
11
main.go
11
main.go
|
|
@ -29,6 +29,7 @@ type (
|
||||||
Root bool
|
Root bool
|
||||||
Files []*File
|
Files []*File
|
||||||
Readme template.HTML
|
Readme template.HTML
|
||||||
|
CSS template.CSS
|
||||||
}
|
}
|
||||||
|
|
||||||
File struct {
|
File struct {
|
||||||
|
|
@ -181,6 +182,15 @@ func main() {
|
||||||
return
|
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
|
// embeded readme
|
||||||
var readmeHTML template.HTML
|
var readmeHTML template.HTML
|
||||||
entries, err := os.ReadDir(fpath)
|
entries, err := os.ReadDir(fpath)
|
||||||
|
|
@ -205,6 +215,7 @@ func main() {
|
||||||
Name: r.URL.Path,
|
Name: r.URL.Path,
|
||||||
Files: []*File{},
|
Files: []*File{},
|
||||||
Readme: readmeHTML,
|
Readme: readmeHTML,
|
||||||
|
CSS: customCSS,
|
||||||
}
|
}
|
||||||
|
|
||||||
fsDir := os.DirFS(fpath)
|
fsDir := os.DirFS(fpath)
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
{{if .CSS}}
|
||||||
|
<style>{{.CSS}}</style>
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue