From 868d2a7bbd9fe2daa4bee3fd40b4224cef93fef8 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Wed, 25 Jun 2025 21:30:57 +0100 Subject: [PATCH] Don't make assets configurable --- cmd/server/main.go | 2 +- conf.example.toml | 9 --------- internal/conf/conf.go | 21 ++++++++++++++------- internal/templ/templ.go | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 6fddcba..8d33e7f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -24,7 +24,7 @@ func main() { router.Handle("/", http.RedirectHandler("/notes/", http.StatusFound)) router.Handle("/notes/", http.StripPrefix("/notes", notesRouter)) router.Handle( - conf.Conf.Static.Root, + "/static/", logger( http.StripPrefix( "/static", diff --git a/conf.example.toml b/conf.example.toml index 98cc612..1685e75 100644 --- a/conf.example.toml +++ b/conf.example.toml @@ -5,15 +5,6 @@ protocol = "tcp" [templates] dir = "/usr/share/gonotes/templates" -base = "base.tmpl.html" [static] dir = "/var/www/gonotes/static" - -assets = [ - { path = "css/bootstrap.min.css", url = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" }, - { path = "css/tiny-mde.min.css", url = "https://unpkg.com/tiny-markdown-editor/dist/tiny-mde.min.css" }, - { path = "js/tiny-mde.min.js", url = "https://unpkg.com/tiny-markdown-editor/dist/tiny-mde.min.js" }, - { path = "icons/pencil-square.svg", url = "https://raw.githubusercontent.com/twbs/icons/refs/heads/main/icons/pencil-square.svg" }, -] -# These are not for changing! diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 212129f..896c209 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -58,17 +58,24 @@ type Config struct { Extension string NotesDir string Templates struct { - Dir string - Base string + Dir string } Static struct { - Dir string - Root string - Assets []Asset + Dir string + Root string } } -var Conf Config +var ( + Conf Config + assets []Asset = []Asset{ + {Path: "css/bootstrap.min.css", Url: "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"}, + {Path: "css/tiny-mde.min.css", Url: "https://unpkg.com/tiny-markdown-editor/dist/tiny-mde.min.css"}, + {Path: "js/tiny-mde.min.js", Url: "https://unpkg.com/tiny-markdown-editor/dist/tiny-mde.min.js"}, + {Path: "icons/eye.svg", Url: "https://raw.githubusercontent.com/twbs/icons/refs/heads/main/icons/eye.svg"}, + } + BaseTemplate string = "base.tmpl.html" +) func LoadConfig(path string) { var err error @@ -83,7 +90,7 @@ func LoadConfig(path string) { log.Fatal(err) } - for _, asset := range Conf.Static.Assets { + for _, asset := range assets { asset.FetchIfNotExists(Conf.Static.Dir) } } diff --git a/internal/templ/templ.go b/internal/templ/templ.go index d794ede..deb1e0c 100644 --- a/internal/templ/templ.go +++ b/internal/templ/templ.go @@ -13,7 +13,7 @@ type Ctx map[string]any func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error { files := []string{ - filepath.Join(conf.Conf.Templates.Dir, conf.Conf.Templates.Base), + filepath.Join(conf.Conf.Templates.Dir, conf.BaseTemplate), filepath.Join(conf.Conf.Templates.Dir, tmpl), }