From cb253a597259b144ea8795698a1aafd02920fd09 Mon Sep 17 00:00:00 2001 From: Dakota Walsh Date: Tue, 21 Mar 2023 14:23:48 +1300 Subject: [PATCH] inset images and link fix --- dir.tmpl | 12 ++++++------ main.go | 17 +++++++++-------- static/main.css | 8 ++++++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dir.tmpl b/dir.tmpl index bb79644..d9a6605 100644 --- a/dir.tmpl +++ b/dir.tmpl @@ -8,7 +8,7 @@
- + - - - {{ if .Path }} - {{.Path}} + + {{ if .Artist }} + + {{.Artist}} + {{ end }} -
    diff --git a/main.go b/main.go index e5c74e6..b8c11a7 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ type application struct { } type page struct { - Path string + Artist string Entries []entry } @@ -31,31 +31,32 @@ type entry struct { } func (app *application) dir(w http.ResponseWriter, r *http.Request) { - path := filepath.Join(app.content, filepath.Clean(r.URL.Path)) - info, err := os.Stat(path) + systempath := filepath.Join(app.content, filepath.Clean(r.URL.Path)) + info, err := os.Stat(systempath) if err != nil { app.errLog.Println(err) http.NotFound(w, r) return } if !info.IsDir() { - f, err := os.Open(path) + f, err := os.Open(systempath) if err != nil { app.errLog.Println(err) http.NotFound(w, r) return } - http.ServeContent(w, r, path, info.ModTime(), f) + http.ServeContent(w, r, systempath, info.ModTime(), f) return } - dirEntries, err := os.ReadDir(path) + dirEntries, err := os.ReadDir(systempath) if err != nil { app.errLog.Println(err) http.NotFound(w, r) return } + artist := strings.TrimPrefix(systempath, filepath.Clean(app.content)) var entries []entry for _, e := range dirEntries { name := e.Name() @@ -75,14 +76,14 @@ func (app *application) dir(w http.ResponseWriter, r *http.Request) { entries = append(entries, entry{ Name: name, - Path: e.Name(), + Path: filepath.Join(artist, e.Name()), Size: info.Size(), Time: info.ModTime().Format("Jan _2 15:04 2006"), }) } err = app.ts.Execute(w, page{ - Path: strings.TrimPrefix(path, filepath.Clean(app.content)), + Artist: artist, Entries: entries, }) if err != nil { diff --git a/static/main.css b/static/main.css index f2ec6a7..03aac22 100644 --- a/static/main.css +++ b/static/main.css @@ -8,13 +8,17 @@ img { image-rendering: pixelated; - height: calc(2rem + 2vw); + height: 100%; } -header > a:last-child { +.artist { float: right; } header > * { + height: calc(2rem + 2vw); + display: inline-block; margin: 0; + border-width: 3px; + border-style: inset; } body { -- 2.45.2