diff --git a/cmd/server/main.go b/cmd/server/main.go index 8d33e7f..6fddcba 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( - "/static/", + conf.Conf.Static.Root, logger( http.StripPrefix( "/static", diff --git a/conf.example.toml b/conf.example.toml index 1685e75..98cc612 100644 --- a/conf.example.toml +++ b/conf.example.toml @@ -5,6 +5,15 @@ 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 896c209..212129f 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -58,24 +58,17 @@ type Config struct { Extension string NotesDir string Templates struct { - Dir string + Dir string + Base string } Static struct { - Dir string - Root string + Dir string + Root string + Assets []Asset } } -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" -) +var Conf Config func LoadConfig(path string) { var err error @@ -90,7 +83,7 @@ func LoadConfig(path string) { log.Fatal(err) } - for _, asset := range assets { + for _, asset := range Conf.Static.Assets { asset.FetchIfNotExists(Conf.Static.Dir) } } diff --git a/internal/templ/templ.go b/internal/templ/templ.go index deb1e0c..d794ede 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.BaseTemplate), + filepath.Join(conf.Conf.Templates.Dir, conf.Conf.Templates.Base), filepath.Join(conf.Conf.Templates.Dir, tmpl), } diff --git a/templates/list.tmpl.html b/templates/list.tmpl.html index 1c4bb44..f705d90 100644 --- a/templates/list.tmpl.html +++ b/templates/list.tmpl.html @@ -5,7 +5,7 @@ {{$title}} - Edit + Edit {{end}}