add dark-mode and theme switcher

This commit is contained in:
Patryk Hegenberg 2023-12-06 08:38:23 +01:00
parent 4f69762b1f
commit d60d1df51e
4 changed files with 62 additions and 10 deletions

26
main.go
View file

@ -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
}