Don't make assets configurable
This commit is contained in:
parent
da11dbd1c8
commit
868d2a7bbd
4 changed files with 16 additions and 18 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue