forked from tangled.org/core
this repo has no description

implement cache busting for tw.css

- proper tabindex for login page form
- overflow for handles in profile page

Changed files
+39 -7
appview
pages
+1
appview/pages/funcmap.go
···
}
return template.HTML(data)
},
+
"cssContentHash": CssContentHash,
}
}
+22 -1
appview/pages/pages.go
···
import (
"bytes"
+
"crypto/sha256"
"embed"
+
"encoding/hex"
"fmt"
"html/template"
"io"
···
func Cache(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-
if strings.HasSuffix(r.URL.Path, ".css") {
+
path := strings.Split(r.URL.Path, "?")[0]
+
+
if strings.HasSuffix(path, ".css") {
// on day for css files
w.Header().Set("Cache-Control", "public, max-age=86400")
} else {
···
}
h.ServeHTTP(w, r)
})
+
}
+
+
func CssContentHash() string {
+
cssFile, err := Files.Open("static/tw.css")
+
if err != nil {
+
log.Printf("Error opening CSS file: %v", err)
+
return ""
+
}
+
defer cssFile.Close()
+
+
hasher := sha256.New()
+
if _, err := io.Copy(hasher, cssFile); err != nil {
+
log.Printf("Error hashing CSS file: %v", err)
+
return ""
+
}
+
+
return hex.EncodeToString(hasher.Sum(nil))[:8] // Use first 8 chars of hash
}
func (p *Pages) Error500(w io.Writer) error {
+1 -2
appview/pages/templates/layouts/base.html
···
content="width=device-width, initial-scale=1.0"
/>
<script src="/static/htmx.min.js"></script>
-
<link href="/static/tw.css" rel="stylesheet" type="text/css" />
-
+
<link rel="stylesheet" href="/static/tw.css?{{ cssContentHash }}" type="text/css" />
<title>{{ block "title" . }}{{ end }} · tangled</title>
{{ block "extrameta" . }}{{ end }}
</head>
+10 -2
appview/pages/templates/user/login.html
···
content="width=device-width, initial-scale=1.0"
/>
<script src="/static/htmx.min.js"></script>
-
<link rel="stylesheet" href="/static/tw.css" type="text/css" />
+
<link rel="stylesheet" href="/static/tw.css?{{ cssContentHash }}" type="text/css" />
<title>login</title>
</head>
<body class="flex items-center justify-center min-h-screen">
···
>
<div class="flex flex-col">
<label for="handle">handle</label>
-
<input type="text" id="handle" name="handle" required />
+
<input
+
type="text"
+
id="handle"
+
name="handle"
+
tabindex="1"
+
required
+
/>
<span class="text-xs text-gray-500 mt-1">
You need to use your
<a href="https://bsky.app">Bluesky</a> handle to log
···
type="password"
id="app_password"
name="app_password"
+
tabindex="2"
required
/>
<span class="text-xs text-gray-500 mt-1">
···
class="btn w-full my-2 mt-6"
type="submit"
id="login-button"
+
tabindex="3"
>
<span>login</span>
</button>
+5 -2
appview/pages/templates/user/profile.html
···
<img class="w-3/4 rounded-full p-2" src="{{ .AvatarUri }}" />
{{ end }}
</div>
-
<p class="text-xl font-bold text-center dark:text-white">
-
{{ truncateAt30 (didOrHandle .UserDid .UserHandle) }}
+
<p
+
title="{{ didOrHandle .UserDid .UserHandle }}"
+
class="text-lg font-bold text-center dark:text-white overflow-hidden text-ellipsis whitespace-nowrap max-w-full"
+
>
+
{{ didOrHandle .UserDid .UserHandle }}
</p>
<div class="text-sm text-center dark:text-gray-300">
<span>{{ .ProfileStats.Followers }} followers</span>