add dark-mode and theme switcher
This commit is contained in:
parent
4f69762b1f
commit
d60d1df51e
4 changed files with 62 additions and 10 deletions
26
main.go
26
main.go
|
|
@ -14,12 +14,15 @@ var (
|
|||
chars []model.Character
|
||||
//go:embed templates/*.html
|
||||
//go:embed images/*
|
||||
content embed.FS
|
||||
content embed.FS
|
||||
//go:embed static/*
|
||||
static embed.FS
|
||||
Monsters []model.Monster
|
||||
)
|
||||
|
||||
func main() {
|
||||
filename := ""
|
||||
log.Printf("Eingebunden is %v\n", static)
|
||||
|
||||
http.HandleFunc("/", handlers.FormHandler(content, &Monsters, filename))
|
||||
http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename))
|
||||
|
|
@ -29,6 +32,27 @@ func main() {
|
|||
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
||||
http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters))
|
||||
|
||||
// Lade die CSS-Datei
|
||||
css, err := loadCSS(static)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Füge eine Route für die CSS-Datei hinzu
|
||||
http.HandleFunc("/static/darkly_bulmawatch.css", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css")
|
||||
w.Write([]byte(css))
|
||||
})
|
||||
|
||||
log.Print("Server gestartet, erreichbar unter http://localhost:8080")
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
||||
// loadCSS liest die CSS-Datei aus dem eingebetteten Dateisystem.
|
||||
func loadCSS(content embed.FS) (string, error) {
|
||||
file, err := content.ReadFile("static/darkly_bulmawatch.css")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(file), nil
|
||||
}
|
||||
|
|
|
|||
7
static/darkly_bulmawatch.css
Normal file
7
static/darkly_bulmawatch.css
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -9,7 +9,8 @@
|
|||
<script src="https://unpkg.com/htmx.org@1.9.9"
|
||||
integrity="sha384-QFjmbokDn2DjBjq+fM+8LUIVrAgqcNW2s0PjAxHETgRn9l4fvX31ZxDxvwQnyMOX"
|
||||
crossorigin="anonymous"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
||||
<link id="customStylesheet" rel="stylesheet" href="/static/darkly_bulmawatch.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -26,14 +26,11 @@
|
|||
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item">
|
||||
<div class="buttons">
|
||||
<a class="button is-primary">
|
||||
<strong>Sign up</strong>
|
||||
</a>
|
||||
<a class="button is-light">
|
||||
Log in
|
||||
</a>
|
||||
</div>
|
||||
<button id="switchButton" class="button is-light">
|
||||
<span id="stylesheetIcon" class="icon">
|
||||
<i class="fas fa-sun"></i>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -54,5 +51,28 @@
|
|||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const switchButton = document.getElementById("switchButton");
|
||||
const stylesheetIcon = document.getElementById("stylesheetIcon");
|
||||
|
||||
if (switchButton) {
|
||||
switchButton.addEventListener('click', switchStylesheet);
|
||||
}
|
||||
|
||||
function switchStylesheet() {
|
||||
const link = document.getElementById("customStylesheet");
|
||||
|
||||
// Ändere das Icon basierend auf dem aktuellen Stylesheet
|
||||
if (link.getAttribute("href") === "/static/darkly_bulmawatch.css") {
|
||||
link.setAttribute("href", "https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css");
|
||||
stylesheetIcon.innerHTML = '<i class="fas fa-moon"></i>'; // Zum Mond-Icon wechseln
|
||||
} else {
|
||||
link.setAttribute("href", "/static/darkly_bulmawatch.css");
|
||||
stylesheetIcon.innerHTML = '<i class="fas fa-sun"></i>'; // Zum Sonnen-Icon wechseln
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</header>
|
||||
{{ end }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue