Embed templates and static files
This commit is contained in:
parent
868d2a7bbd
commit
8edd857d22
11 changed files with 31 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
|
|
@ -17,7 +18,7 @@ type Asset struct {
|
|||
Url string
|
||||
}
|
||||
|
||||
func (asset *Asset) FetchIfNotExists(staticPath string) {
|
||||
func (asset *Asset) fetchIfNotExists(staticPath string) {
|
||||
destPath := filepath.Join(staticPath, asset.Path)
|
||||
|
||||
err := os.MkdirAll(path.Dir(destPath), os.FileMode(0750))
|
||||
|
|
@ -57,13 +58,9 @@ type Config struct {
|
|||
Protocol string
|
||||
Extension string
|
||||
NotesDir string
|
||||
Templates struct {
|
||||
Static struct {
|
||||
Dir string
|
||||
}
|
||||
Static struct {
|
||||
Dir string
|
||||
Root string
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -75,6 +72,10 @@ var (
|
|||
{Path: "icons/eye.svg", Url: "https://raw.githubusercontent.com/twbs/icons/refs/heads/main/icons/eye.svg"},
|
||||
}
|
||||
BaseTemplate string = "base.tmpl.html"
|
||||
//go:embed static/*
|
||||
Static embed.FS
|
||||
//go:embed templates/*
|
||||
Templates embed.FS
|
||||
)
|
||||
|
||||
func LoadConfig(path string) {
|
||||
|
|
@ -89,8 +90,10 @@ func LoadConfig(path string) {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func FetchAssets() {
|
||||
for _, asset := range assets {
|
||||
asset.FetchIfNotExists(Conf.Static.Dir)
|
||||
asset.fetchIfNotExists("./internal/conf/static")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue