Skip to content

Commit d02ca35

Browse files
committedDec 20, 2023
fix: pass theme as variable to template
1 parent a51feb6 commit d02ca35

File tree

5 files changed

+6
-3
lines changed

5 files changed

+6
-3
lines changed
 

‎cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
const (
33-
version = "v0.0.12"
33+
version = "v0.0.13"
3434
)
3535

3636
var (

‎internal/handlers/home.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func Home(w http.ResponseWriter, r *http.Request) {
3030
Title: "vimbin - a pastebin with vim motion",
3131
Content: config.App.Storage.Content.Get(),
3232
Token: config.App.Server.Api.Token.Get(),
33+
Theme: config.App.Server.Web.Theme,
3334
}
3435

3536
if err := config.App.HtmlTemplate.Execute(w, page); err != nil {

‎internal/handlers/structs.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ type Page struct {
88
Title string // Title is the title of the page.
99
Content string // Content is the content of the page.
1010
Token string // Token is the API token.
11+
Theme string // Theme is the theme of the page.
1112
}

‎web/static/js/vimbin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ document.addEventListener("DOMContentLoaded", function () {
66
: "default";
77
}
88

9-
// Function to set the theme based on the initial color scheme
9+
// Function to set the theme based on the initial color scheme or the 'theme' variable
1010
function setThemeBasedOnColorScheme() {
11-
const preferredTheme = getPreferredTheme();
11+
const preferredTheme = theme || getPreferredTheme();
1212
console.log(`Setting theme to '${preferredTheme}'`);
1313

1414
editor.setOption("theme", preferredTheme);

‎web/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h2>{{.Title}}</h2>
3838
<script src="static/js/vimbin.js"></script>
3939
<script>
4040
var apiToken = "{{.Token}}";
41+
var theme = "{{.Theme}}";
4142
</script>
4243
</footer>
4344
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.