Restore local live reloading of templates.
This commit is contained in:
parent
29fbadbadd
commit
5f877c3d38
5 changed files with 63 additions and 21 deletions
|
|
@ -2,7 +2,28 @@ package templates
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
//go:embed *
|
||||
var Templates embed.FS
|
||||
var templates embed.FS
|
||||
|
||||
// Get returns a file system containing all templates via embed.FS
|
||||
func Get() embed.FS {
|
||||
return templates
|
||||
}
|
||||
|
||||
// GetOS returns a file system containing all templates which will load the files directly from the operating system.
|
||||
// This should only be used for local development in order to faciliate live reloading.
|
||||
func GetOS() fs.FS {
|
||||
// Gets the complete templates directory path
|
||||
// This is needed in case this is called from a package outside of main, such as within tests
|
||||
_, b, _, _ := runtime.Caller(0)
|
||||
d := path.Join(path.Dir(b))
|
||||
p := filepath.Join(filepath.Dir(d), "templates")
|
||||
return os.DirFS(p)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue