move to embedded css, update hx state for spinner bug

This commit is contained in:
2025-08-17 14:32:33 +00:00
parent 749d68cdeb
commit 18d151e0cf
3 changed files with 22 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"embed"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@@ -11,11 +12,14 @@ import (
"git.valxntine.dev/valxntine/blog/templates" "git.valxntine.dev/valxntine/blog/templates"
) )
//go:embed static/*
var staticFS embed.FS
func main() { func main() {
mux := http.NewServeMux() mux := http.NewServeMux()
fs := http.FileServer(http.Dir("./static/")) staticHandler := http.FileServer(http.FS(staticFS))
mux.Handle("/static/", http.StripPrefix("/static/", fs)) mux.Handle("/static/", staticHandler)
mux.HandleFunc("/", handleHome) mux.HandleFunc("/", handleHome)
mux.HandleFunc("/posts/", handlePost) mux.HandleFunc("/posts/", handlePost)

View File

@@ -13,12 +13,20 @@ templ Layout(title string) {
<body> <body>
{ children... } { children... }
<script> <script>
document.body.addEventListener('htmx:beforeRequest', function(e) { document.body.addEventListener('htmx:beforeRequest', function(evt) {
e.detail.elt.classList.add('loading'); evt.detail.elt.classList.add('loading');
}); });
document.body.addEventListener('htmx:afterRequest', function(e) { document.body.addEventListener('htmx:afterRequest', function(evt) {
e.detail.elt.classList.remove('loading'); document.querySelectorAll('.loading').forEach(el => {
el.classList.remove('loading');
});
});
document.body.addEventListener('htmx:beforeSwap', function(evt) {
document.querySelectorAll('.loading').forEach(el => {
el.classList.remove('loading');
});
}); });
</script> </script>
</body> </body>

View File

@@ -50,7 +50,7 @@ func Layout(title string) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<script>\n document.body.addEventListener('htmx:beforeRequest', function(e) {\n e.detail.elt.classList.add('loading');\n });\n\n document.body.addEventListener('htmx:afterRequest', function(e) {\n e.detail.elt.classList.remove('loading');\n });\n </script></body></html>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<script>\n\t\t document.body.addEventListener('htmx:beforeRequest', function(evt) {\n\t evt.detail.elt.classList.add('loading');\n\t\t });\n \n\t\t document.body.addEventListener('htmx:afterRequest', function(evt) {\n\t\t document.querySelectorAll('.loading').forEach(el => {\n\t\t el.classList.remove('loading');\n\t\t });\n\t\t });\n \n\t\t document.body.addEventListener('htmx:beforeSwap', function(evt) {\n\t\t document.querySelectorAll('.loading').forEach(el => {\n\t\t el.classList.remove('loading');\n\t\t });\n\t\t });\n </script></body></html>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }