taggart

Simple golang tagging filesystem webapp
Log | Files | Refs

commit 58f70b39c2581907705309227f18ade31e47e336
parent 011f4ec03141e37b5466cb062900dfe7fc9178b8
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Sun, 28 Sep 2025 13:09:49 +0100

Support and display multiple tag values

Diffstat:
Mmain.go | 6+++---
Mstatic/style.css | 5+++--
Mtemplates/file.html | 13++++++++-----
3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/main.go b/main.go @@ -32,7 +32,7 @@ type File struct { EscapedFilename string Path string Description string - Tags map[string]string + Tags map[string][]string } type Config struct { @@ -526,7 +526,7 @@ func fileHandler(w http.ResponseWriter, r *http.Request) { return } - f.Tags = make(map[string]string) + f.Tags = make(map[string][]string) rows, _ := db.Query(` SELECT c.name, t.value FROM tags t @@ -536,7 +536,7 @@ func fileHandler(w http.ResponseWriter, r *http.Request) { for rows.Next() { var cat, val string rows.Scan(&cat, &val) - f.Tags[cat] = val + f.Tags[cat] = append(f.Tags[cat], val) } rows.Close() diff --git a/static/style.css b/static/style.css @@ -39,4 +39,5 @@ div#no-description {color: #666; font-style: italic; margin-bottom: 10px; paddin button#edit-description-btn {background: #007cba; color: white; padding: 6px 12px; border: none; border-radius: 3px; cursor: pointer; font-size: 14px;} textarea#description-textarea {width: 100%; max-width: 600px; padding: 8px; border: 1px solid #ccc; border-radius: 3px; font-family: inherit; resize: vertical;} input.description-save {background: #28a745; color: white; padding: 8px 16px; border: none; border-radius: 3px; cursor: pointer;} -button.description-cancel {background: #6c757d; color: white; padding: 8px 16px; border: none; border-radius: 3px; cursor: pointer;} -\ No newline at end of file +button.description-cancel {background: #6c757d; color: white; padding: 8px 16px; border: none; border-radius: 3px; cursor: pointer;} +button.delete-tag {border:none; background:none; color:red; cursor:pointer; padding:0; margin-left:2px;} +\ No newline at end of file diff --git a/templates/file.html b/templates/file.html @@ -72,11 +72,14 @@ <h3>Tags</h3> <ul> -{{range $k, $v := .Data.File.Tags}} - <li>{{$k}}: {{$v}} - <form style="display:inline" method="post" action="/file/{{$.Data.File.ID}}/tag/{{$k}}/{{$v}}/delete"> - <button type="submit">Remove</button> - </form> +{{range $k, $vs := .Data.File.Tags}} + <li> + {{$k}}: + {{range $i, $v := $vs}} + {{if $i}}, {{end}} + <form method="post" action="/file/{{$.Data.File.ID}}/tag/{{$k}}/{{$v}}/delete" style="display:inline;"><button class="delete-tag" type="submit">[x]</button></form> + <a href="/tag/{{$k}}/{{$v}}">{{$v}}</a> + {{end}} </li> {{else}} <li>No tags yet</li>