From 778c8027a2ad57e5052befc24c37b75278c9d939 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Sun, 3 Dec 2023 22:36:42 +0200 Subject: [PATCH] Theme changing --- data/resume.yaml | 1 + main.go | 6 ++++++ structs.go => resume.go | 3 ++- templates/index.html | 6 +++++- 4 files changed, 14 insertions(+), 2 deletions(-) rename structs.go => resume.go (94%) diff --git a/data/resume.yaml b/data/resume.yaml index 588a73f..d1d47da 100644 --- a/data/resume.yaml +++ b/data/resume.yaml @@ -9,4 +9,5 @@ meta: theme-color: "#bd93f9" title: "Go-Resume - dynamic resume" description: "Software Developer" +theme: "light" diff --git a/main.go b/main.go index bb85a87..ca3d47e 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log/slog" "net/http" "slices" + "strings" ) //go:embed "static/css/*.css" "templates/*.html" @@ -46,6 +47,11 @@ func home(w http.ResponseWriter, r *http.Request) { slog.Error(err.Error()) http.Error(w, "Server error", http.StatusInternalServerError) } + // TODO: Theme from browser + if strings.HasSuffix(r.URL.Path, "/light") || strings.HasSuffix(r.URL.Path, "/dark") { + urlSlice := strings.Split(r.URL.Path, "/") + data.Theme = urlSlice[len(urlSlice)-1] + } err = tmpl.Execute(w, *data) if err != nil { slog.Error(err.Error()) diff --git a/structs.go b/resume.go similarity index 94% rename from structs.go rename to resume.go index fe9e0bd..259e73b 100644 --- a/structs.go +++ b/resume.go @@ -1,7 +1,8 @@ package main type Resume struct { - Meta Meta `yaml:"meta"` + Theme string `yaml:"theme"` + Meta *Meta `yaml:"meta"` } type job struct { diff --git a/templates/index.html b/templates/index.html index db0f3dc..c74beac 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,7 @@ {{ template "meta" .Meta }} - + @@ -146,7 +146,11 @@