stromboli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit fcfd19a43bab65644879713adf011cb9479144bf
parent 4c74e03585b9d2f05c3b3db46efeb3105250d13a
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Sun, 17 May 2026 18:32:55 +0100

I hate capital letters in my address bar

Diffstat:
Mmain.go | 32++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/main.go b/main.go @@ -78,10 +78,38 @@ func main() { log.Fatal(http.ListenAndServe(":"+*port, nil)) } +// Attempt to find the original path, even though we've removed the case +func resolvePathCaseInsensitive(base, relPath string) string { + segments := strings.Split(filepath.ToSlash(relPath), "/") + real := "" + for _, seg := range segments { + if seg == "" { + continue + } + entries, err := os.ReadDir(filepath.Join(base, real)) + if err != nil { + return relPath + } + matched := seg // fallback: keep as-is + for _, e := range entries { + if strings.EqualFold(e.Name(), seg) { + matched = e.Name() + break + } + } + if real == "" { + real = matched + } else { + real = real + "/" + matched + } + } + return real +} + func handleIndex(w http.ResponseWriter, r *http.Request) { // Find initial browse path from the URL path, stripping first slash, and using hyphens urlPath := strings.TrimPrefix(r.URL.Path, "/") - initialPath := strings.ReplaceAll(urlPath, "-", " ") + initialPath := resolvePathCaseInsensitive(rootDir, strings.ReplaceAll(urlPath, "-", " ")) tmpl := `<!DOCTYPE html> <html> @@ -354,7 +382,7 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { function browse(path = '') { currentPath = path; - const urlPath = path ? '/' + path.replace(/ /g, '-') : '/'; + const urlPath = path ? '/' + path.replace(/ /g, '-').toLowerCase() : '/'; history.pushState({ path }, '', urlPath); fetch('/api/browse?path=' + encodeURIComponent(path))