summaryrefslogtreecommitdiff
path: root/pages/local.go
diff options
context:
space:
mode:
Diffstat (limited to 'pages/local.go')
-rw-r--r--pages/local.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/pages/local.go b/pages/local.go
new file mode 100644
index 0000000..ccd0f41
--- /dev/null
+++ b/pages/local.go
@@ -0,0 +1,58 @@
+package pages
+
+import (
+ "fmt"
+ "github.com/spf13/pflag"
+ "gopkg.in/fsnotify/fsnotify.v1"
+ "html/template"
+ "os"
+)
+
+var Local = pflag.BoolP("local", "l", false, "use local files instead of embedded")
+
+var Templates = map[string]func(content string){
+ "pages/create.gohtml": func(content string) {
+ template.Must(tmpl.New("create").Parse(content))
+ },
+ "pages/landing.gohtml": func(content string) {
+ template.Must(tmpl.New("landing").Parse(content))
+ },
+ "pages/style.gohtml": func(content string) {
+ template.Must(tmpl.Parse(content))
+ },
+}
+
+func SetupLocal() {
+ if *Local {
+
+ watcher, err := fsnotify.NewWatcher()
+ if err != nil {
+ panic(err)
+ }
+ for page := range Templates {
+ watcher.Add(page)
+ }
+
+ go func() {
+ for {
+ select {
+ case ev := <-watcher.Events:
+ newContent, err := os.ReadFile(ev.Name)
+ if err != nil {
+ fmt.Printf("error: %vn", err)
+ continue
+ }
+ Templates[ev.Name](string(newContent))
+ if err != nil {
+ fmt.Printf("error: %vn", err)
+ } else {
+ fmt.Printf("updated: %vn", ev.Name)
+
+ }
+
+ }
+ }
+ }()
+
+ }
+}