Don't make assets configurable

This commit is contained in:
Maximilian Friedersdorff 2025-06-25 21:30:57 +01:00
parent da11dbd1c8
commit 868d2a7bbd
4 changed files with 16 additions and 18 deletions

View file

@ -24,7 +24,7 @@ func main() {
router.Handle("/", http.RedirectHandler("/notes/", http.StatusFound)) router.Handle("/", http.RedirectHandler("/notes/", http.StatusFound))
router.Handle("/notes/", http.StripPrefix("/notes", notesRouter)) router.Handle("/notes/", http.StripPrefix("/notes", notesRouter))
router.Handle( router.Handle(
conf.Conf.Static.Root, "/static/",
logger( logger(
http.StripPrefix( http.StripPrefix(
"/static", "/static",

View file

@ -5,15 +5,6 @@ protocol = "tcp"
[templates] [templates]
dir = "/usr/share/gonotes/templates" dir = "/usr/share/gonotes/templates"
base = "base.tmpl.html"
[static] [static]
dir = "/var/www/gonotes/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!

View file

@ -58,17 +58,24 @@ type Config struct {
Extension string Extension string
NotesDir string NotesDir string
Templates struct { Templates struct {
Dir string Dir string
Base string
} }
Static struct { Static struct {
Dir string Dir string
Root string Root string
Assets []Asset
} }
} }
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) { func LoadConfig(path string) {
var err error var err error
@ -83,7 +90,7 @@ func LoadConfig(path string) {
log.Fatal(err) log.Fatal(err)
} }
for _, asset := range Conf.Static.Assets { for _, asset := range assets {
asset.FetchIfNotExists(Conf.Static.Dir) asset.FetchIfNotExists(Conf.Static.Dir)
} }
} }

View file

@ -13,7 +13,7 @@ type Ctx map[string]any
func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error { func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
files := []string{ 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), filepath.Join(conf.Conf.Templates.Dir, tmpl),
} }