-
Notifications
You must be signed in to change notification settings - Fork 95
/
templates.go
52 lines (45 loc) · 1.2 KB
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package templates
import (
"embed"
"io/fs"
"os"
"path"
"path/filepath"
"runtime"
)
type (
Layout string
Page string
)
const (
LayoutMain Layout = "main"
LayoutAuth Layout = "auth"
LayoutHTMX Layout = "htmx"
)
const (
PageAbout Page = "about"
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"
)
//go:embed *
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)
}