From 6e896ae0e108eef385b46c26e770dc191ae936ba Mon Sep 17 00:00:00 2001 From: ewy Date: Thu, 9 Apr 2026 21:01:59 +0200 Subject: add more css --- pages/local.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 pages/local.go (limited to 'pages/local.go') 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) + + } + + } + } + }() + + } +} -- cgit v1.3