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"
title: "Go-Resume - dynamic resume"
description: "Software Developer"
theme: "light"

View File

@ -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())

View File

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

View File

@ -3,7 +3,7 @@
<head>
{{ template "meta" .Meta }}
<link rel="stylesheet" href="/static/css/dark-style.css" />
<link rel="stylesheet" href="/static/css/{{ .Theme }}-style.css" />
</head>
<body id="body-app">
@ -146,7 +146,11 @@
<footer class="footer">
<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>
{{ end }}
<br />
Copyright © 2018-2019 by
<a href="https://mazipan.space">Irfan Maulana</a>