Initial commit: Lookbook personal collection app
Pinterest-like app for saving images, videos, quotes, and embeds. Features: - Go backend with PostgreSQL, SSR templates - Console-based admin auth (login/logout via browser console) - Item types: images, videos (ffmpeg transcoding), quotes, embeds - Media stored as BLOBs in PostgreSQL - OpenGraph metadata extraction for links - Embed detection for YouTube, Vimeo, Twitter/X - Masonry grid layout, item detail pages - Tag system with filtering - Refresh metadata endpoint with change warnings - Replace media endpoint for updating item images/videos
This commit is contained in:
commit
cdcc5b5293
45 changed files with 4634 additions and 0 deletions
43
internal/static/static.go
Normal file
43
internal/static/static.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package static
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"embed"
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed css/* js/* fonts/*
|
||||
var staticFS embed.FS
|
||||
|
||||
// Version is set via -ldflags in production
|
||||
var Version string
|
||||
|
||||
func init() {
|
||||
if Version == "" {
|
||||
h := sha256.Sum256([]byte(time.Now().String()))
|
||||
Version = hex.EncodeToString(h[:4])
|
||||
}
|
||||
}
|
||||
|
||||
func VersionedPath(path string) string {
|
||||
return "/static/" + Version + "/" + path
|
||||
}
|
||||
|
||||
func Handler() http.Handler {
|
||||
fileServer := http.FileServer(http.FS(staticFS))
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Strip version prefix: /static/{version}/file.css -> /file.css
|
||||
path := r.URL.Path
|
||||
path = strings.TrimPrefix(path, "/static/")
|
||||
if idx := strings.Index(path, "/"); idx != -1 {
|
||||
path = path[idx:]
|
||||
}
|
||||
r.URL.Path = path
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue