Theme changing

This commit is contained in:
Jarno Rankinen 2023-12-03 22:36:42 +02:00
parent 2080180985
commit 778c8027a2
4 changed files with 14 additions and 2 deletions

View File

@ -9,4 +9,5 @@ meta:
theme-color: "#bd93f9" theme-color: "#bd93f9"
title: "Go-Resume - dynamic resume" title: "Go-Resume - dynamic resume"
description: "Software Developer" description: "Software Developer"
theme: "light"

View File

@ -6,6 +6,7 @@ import (
"log/slog" "log/slog"
"net/http" "net/http"
"slices" "slices"
"strings"
) )
//go:embed "static/css/*.css" "templates/*.html" //go:embed "static/css/*.css" "templates/*.html"
@ -46,6 +47,11 @@ func home(w http.ResponseWriter, r *http.Request) {
slog.Error(err.Error()) slog.Error(err.Error())
http.Error(w, "Server error", http.StatusInternalServerError) 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) err = tmpl.Execute(w, *data)
if err != nil { if err != nil {
slog.Error(err.Error()) slog.Error(err.Error())

View File

@ -1,7 +1,8 @@
package main package main
type Resume struct { type Resume struct {
Meta Meta `yaml:"meta"` Theme string `yaml:"theme"`
Meta *Meta `yaml:"meta"`
} }
type job struct { type job struct {

View File

@ -3,7 +3,7 @@
<head> <head>
{{ template "meta" .Meta }} {{ template "meta" .Meta }}
<link rel="stylesheet" href="/static/css/dark-style.css" /> <link rel="stylesheet" href="/static/css/{{ .Theme }}-style.css" />
</head> </head>
<body id="body-app"> <body id="body-app">
@ -146,7 +146,11 @@
<footer class="footer"> <footer class="footer">
<div class="content has-text-centered"> <div class="content has-text-centered">
{{ if eq .Theme "light" }}
<a href="/dark">See Dark Theme</a>
{{ else }}
<a href="/light">See Light Theme</a> <a href="/light">See Light Theme</a>
{{ end }}
<br /> <br />
Copyright © 2018-2019 by Copyright © 2018-2019 by
<a href="https://mazipan.space">Irfan Maulana</a> <a href="https://mazipan.space">Irfan Maulana</a>