commit 78f3710bd0f32b8ed6ba1cb918b2b9abdd47a4a0
parent d86307026457570d31659ab9438e9e21436c336b
Author: breadcat <breadcat@users.noreply.github.com>
Date: Fri, 14 Nov 2025 17:36:50 +0000
Actually get around to implementing gallery size
Diffstat:
7 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/main.go b/main.go
@@ -65,6 +65,7 @@ type PageData struct {
Files []File
Tags map[string][]TagDisplay
Pagination *Pagination
+ GallerySize string
}
type Pagination struct {
@@ -223,7 +224,7 @@ func getUntaggedFilesPaginated(page, perPage int) ([]File, int, error) {
func buildPageData(title string, data interface{}) PageData {
tagMap, _ := getTagData()
- return PageData{Title: title, Data: data, Tags: tagMap}
+ return PageData{Title: title, Data: data, Tags: tagMap, GallerySize: config.GallerySize,}
}
func buildPageDataWithPagination(title string, data interface{}, page, total, perPage int) PageData {
@@ -342,6 +343,20 @@ func main() {
}
return false
},
+ "dict": func(values ...interface{}) (map[string]interface{}, error) {
+ if len(values)%2 != 0 {
+ return nil, fmt.Errorf("dict requires an even number of args")
+ }
+ dict := make(map[string]interface{}, len(values)/2)
+ for i := 0; i < len(values); i += 2 {
+ key, ok := values[i].(string)
+ if !ok {
+ return nil, fmt.Errorf("dict keys must be strings")
+ }
+ dict[key] = values[i+1]
+ }
+ return dict, nil
+ },
}).ParseGlob("templates/*.html"))
http.HandleFunc("/", listFilesHandler)
diff --git a/static/style.css b/static/style.css
@@ -43,12 +43,13 @@ nav ul { font-size: 0; }
nav ul li { font-size: 1rem; }
/* gallery styling */
-div.gallery-item a{overflow:hidden;text-overflow:ellipsis}
+div.gallery-item {padding:1rem}
+div.gallery-item a{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
div.gallery-item a svg{filter: invert(100%);}
div.gallery-item,div.gallery-item a,nav ul li,nav>ul>li{display:inline-block}
-div.gallery-item,div.gallery-item a{width:250px;display:inline-block}
+div.gallery-item,div.gallery-item a{display:inline-block}
div.play-button {position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 0; height: 0; border-left: 15px solid white; border-top: 10px solid transparent; border-bottom: 10px solid transparent; opacity: 0.8;}
-div.gallery-video {position: relative; display: inline-block; width: 150px; max-width: 100%;}
+div.gallery-video {position: relative; display: inline-block}
/* descriptions */
div.description-section {margin: 20px 0; padding: 15px;}
diff --git a/templates/_gallery.html b/templates/_gallery.html
@@ -1,10 +1,21 @@
{{define "_gallery"}}
- <div class="gallery-item">
- <a href="/file/{{.ID}}" title="{{.Filename}}">
- {{if hasAnySuffix .Filename ".jpg" ".jpeg" ".png" ".gif" ".webp"}}<img src="/uploads/{{.EscapedFilename}}" style="max-width:150px">
- {{else if hasAnySuffix .Filename ".mp4" ".webm" ".mov" ".m4v"}}<div class="gallery-video"><img src="/uploads/thumbnails/{{.EscapedFilename}}.jpg" style="width: 100%; display: block;" /><div class="play-button"></div></div>
- {{else if hasAnySuffix .Filename ".txt" ".md"}}<svg width="64" height="64" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"><rect width="64" height="64" fill="#f5f5f5" rx="8"/><rect x="4" y="4" width="56" height="56" fill="none" stroke="#666" stroke-width="2" rx="6"/><text x="32" y="42" font-family="sans-serif" font-size="26" font-weight="600" fill="#333" text-anchor="middle">Aa</text></svg>
- {{end}}
- <br>{{.Filename}}</a>
- </div>
-{{end}}
-\ No newline at end of file
+<div class="gallery-item">
+ <a href="/file/{{.File.ID}}" title="{{.File.Filename}}">
+ {{if hasAnySuffix .File.Filename ".jpg" ".jpeg" ".png" ".gif" ".webp"}}
+ <img src="/uploads/{{.File.EscapedFilename}}">
+ {{else if hasAnySuffix .File.Filename ".mp4" ".webm" ".mov" ".m4v"}}
+ <div class="gallery-video">
+ <img src="/uploads/thumbnails/{{.File.EscapedFilename}}.jpg">
+ <div class="play-button"></div>
+ </div>
+ {{else if hasAnySuffix .File.Filename ".txt" ".md"}}
+ <svg width="64" height="64" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
+ <rect width="64" height="64" fill="#f5f5f5" rx="8"/>
+ <rect x="4" y="4" width="56" height="56" fill="none" stroke="#666" stroke-width="2" rx="6"/>
+ <text x="32" y="42" font-family="sans-serif" font-size="26"
+ font-weight="600" fill="#333" text-anchor="middle">Aa</text>
+ </svg>
+ {{end}}
+ </a>
+</div>
+{{end}}
diff --git a/templates/_header.html b/templates/_header.html
@@ -6,6 +6,10 @@
<title>{{if .Title}}{{.Title}} - Taggart{{else}}Taggart{{end}}</title>
<link href="/static/style.css" rel="stylesheet">
<meta name="viewport" content="width=device-width,initial-scale=1" />
+ <style>
+ :root { --gallery-size: {{ .GallerySize }}; }
+ div.gallery-item, div.gallery img, div.gallery-item a{ max-width: var(--gallery-size); max-height: var(--gallery-size); }
+ </style>
</head>
<body>
<nav>
diff --git a/templates/list.html b/templates/list.html
@@ -5,7 +5,7 @@
<h2>Tagged Files</h2>
<div class="gallery">
{{range .Data.Tagged}}
-{{template "_gallery" .}}
+{{template "_gallery" dict "File" . "Page" $}}
{{else}}
<p>No tagged files yet.</p>
{{end}}
@@ -16,7 +16,7 @@
<h2>Untagged Files</h2>
<div class="gallery">
{{range .Data.Untagged}}
-{{template "_gallery" .}}
+{{template "_gallery" dict "File" . "Page" $}}
{{else}}
<li>No untagged files.</li>
{{end}}
diff --git a/templates/search.html b/templates/search.html
@@ -6,7 +6,7 @@
<h2>Found {{len .Files}} file{{if ne (len .Files) 1}}s{{end}}</h2>
<div class="gallery">
{{range .Files}}
- {{template "_gallery" .}}
+ {{template "_gallery" dict "File" . "Page" $}}
{{end}}
</div>
diff --git a/templates/untagged.html b/templates/untagged.html
@@ -3,7 +3,7 @@
<div class="gallery">
{{range .Data}}
-{{template "_gallery" .}}
+{{template "_gallery" dict "File" . "Page" $}}
{{else}}
<p>No untagged files.</p>
{{end}}