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
|
|
|
)
|
|
|
|
|
2023-12-16 08:07:20 -08:00
|
|
|
type (
|
|
|
|
Layout string
|
|
|
|
Page string
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
LayoutMain Layout = "main"
|
|
|
|
LayoutAuth Layout = "auth"
|
2023-12-18 17:59:40 -08:00
|
|
|
LayoutHTMX Layout = "htmx"
|
2023-12-16 08:07:20 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
PageAbout Page = "about"
|
2024-06-22 07:34:26 -07:00
|
|
|
PageCache Page = "cache"
|
2023-12-16 08:07:20 -08:00
|
|
|
PageContact Page = "contact"
|
|
|
|
PageError Page = "error"
|
|
|
|
PageForgotPassword Page = "forgot-password"
|
|
|
|
PageHome Page = "home"
|
|
|
|
PageLogin Page = "login"
|
|
|
|
PageRegister Page = "register"
|
|
|
|
PageResetPassword Page = "reset-password"
|
|
|
|
PageSearch Page = "search"
|
2024-06-22 07:34:26 -07:00
|
|
|
PageTask Page = "task"
|
2023-12-16 08:07:20 -08:00
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
}
|