made htmx logging a flag that can be toggled

This commit is contained in:
2026-01-24 16:55:36 +11:00
parent 038f8fd1a2
commit 3dc7cbe245
8 changed files with 50 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ type Flags struct {
ShowEnv bool
GenEnv string
EnvFile string
HTMXLog bool
// Database reset (destructive)
ResetDB bool
@@ -33,6 +34,7 @@ func SetupFlags() (*Flags, error) {
showEnv := flag.Bool("showenv", false, "Print all environment variable values and their documentation")
genEnv := flag.String("genenv", "", "Generate a .env file with all environment variables (specify filename)")
envfile := flag.String("envfile", ".env", "Specify a .env file to use for the configuration")
htmxlog := flag.Bool("htmxlog", false, "Run the server with all HTMX events logged")
// Database reset (destructive)
resetDB := flag.Bool("reset-db", false, "⚠️ DESTRUCTIVE: Drop and recreate all tables (dev only)")
@@ -76,6 +78,7 @@ func SetupFlags() (*Flags, error) {
ShowEnv: *showEnv,
GenEnv: *genEnv,
EnvFile: *envfile,
HTMXLog: *htmxlog,
ResetDB: *resetDB,
MigrateUp: *migrateUp,
MigrateRollback: *migrateRollback,

View File

@@ -3,10 +3,12 @@ package layout
import "git.haelnorr.com/h/oslstats/internal/view/component/popup"
import "git.haelnorr.com/h/oslstats/internal/view/component/nav"
import "git.haelnorr.com/h/oslstats/internal/view/component/footer"
import "git.haelnorr.com/h/oslstats/pkg/contexts"
// Global page layout. Includes HTML document settings, header tags
// navbar and footer
templ Global(title string) {
{{ htmxLogging := contexts.HTMXLog(ctx) }}
<!DOCTYPE html>
<html
lang="en"
@@ -27,10 +29,11 @@ templ Global(title string) {
<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/persist@3.x.x/dist/cdn.min.js"></script>
<script src="https://unpkg.com/alpinejs" defer></script>
<script>
// uncomment this line to enable logging of htmx events
// htmx.logAll();
</script>
if htmxLogging {
<script>
htmx.logAll();
</script>
}
<script>
const bodyData = {
showError500: false,