ref: b881ccc61dad23f9a33fd05c8aa00213d591adce
parent: ea391fd0eead3ce2ccbfe6594dfc9cf1c6e02b92
author: Philip Silva <philip.silva@protonmail.com>
date: Wed Jun 2 13:43:53 EDT 2021
add css files
--- a/browser/fs/fs.go
+++ b/browser/fs/fs.go
@@ -15,6 +15,7 @@
oFS *fs.FS
un string
gn string
+ cssDir *fs.StaticDir
jsDir *fs.StaticDir
html string
)
@@ -48,21 +49,38 @@
},
)
root.AddChild(h)
- d, err := fs.CreateStaticDir(oFS, root, un, "js", 0500|proto.DMDIR, 0)
+ d, err := fs.CreateStaticDir(oFS, root, un, "css", 0500|proto.DMDIR, 0)
if err != nil {
log.Errorf("create static dir: %w", err)
return
}
+ cssDir = d.(*fs.StaticDir)
+ root.AddChild(cssDir)
+ d, err = fs.CreateStaticDir(oFS, root, un, "js", 0500|proto.DMDIR, 0)
+ if err != nil {
+ log.Errorf("create static dir: %w", err)
+ return
+ }
jsDir = d.(*fs.StaticDir)
root.AddChild(jsDir)
}
-func Update(htm string, js []string) {
+func Update(htm string, css []string, js []string) {
mu.Lock()
defer mu.Unlock()
html = htm
-
+ for name := range cssDir.Children() {
+ cssDir.DeleteChild(name)
+ }
+ for i, s := range css {
+ fn := fmt.Sprintf("%d.css", i)
+ f := fs.NewStaticFile(
+ oFS.NewStat(fn, un, gn, 0400),
+ []byte(s),
+ )
+ cssDir.AddChild(f)
+ }
for name := range jsDir.Children() {
jsDir.DeleteChild(name)
}
--- a/browser/website.go
+++ b/browser/website.go
@@ -150,7 +150,7 @@
w.UI = scroller
}
- fs.Update(htm, js)
+ fs.Update(htm, csss, js)
log.Flush()
}