2023-12-10 06:33:34 -08:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2023-12-12 17:07:58 -08:00
|
|
|
"io/fs"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2023-12-10 06:33:34 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed *
|
2023-12-12 17:07:58 -08:00
|
|
|
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.
|
2024-06-22 07:34:26 -07:00
|
|
|
// This should only be used for local development in order to facilitate live reloading.
|
2023-12-12 17:07:58 -08:00
|
|
|
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)
|
|
|
|
}
|