mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 21:19:19 +00:00
serve bundled index.html
This commit is contained in:
parent
06458065d6
commit
58946bac36
19
bundle.go
19
bundle.go
@ -10,6 +10,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
htemplate "html/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
var code_template = `// autogenerated. do not edit!
|
var code_template = `// autogenerated. do not edit!
|
||||||
@ -46,10 +47,8 @@ func encode(b []byte) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
outfile := "server/assets_bundle.go"
|
|
||||||
assets := make([]asset, 0)
|
assets := make([]asset, 0)
|
||||||
filepatterns := []string{
|
filepatterns := []string{
|
||||||
"assets/index.html",
|
|
||||||
"assets/graphicarts/*.svg",
|
"assets/graphicarts/*.svg",
|
||||||
"assets/graphicarts/*.png",
|
"assets/graphicarts/*.png",
|
||||||
"assets/javascripts/*.js",
|
"assets/javascripts/*.js",
|
||||||
@ -74,8 +73,22 @@ func main() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var indexbuf bytes.Buffer
|
||||||
|
htemplate.Must(htemplate.New("index.html").Delims("{%", "%}").Funcs(htemplate.FuncMap{
|
||||||
|
"inline": func(svg string) htemplate.HTML {
|
||||||
|
content, _ := ioutil.ReadFile("assets/graphicarts/" + svg)
|
||||||
|
return htemplate.HTML(content)
|
||||||
|
},
|
||||||
|
}).ParseFiles("assets/index.html")).Execute(&indexbuf, nil)
|
||||||
|
indexcontent := indexbuf.Bytes()
|
||||||
|
assets = append(assets, asset{
|
||||||
|
Name: "index.html",
|
||||||
|
Etag: shasum(indexcontent),
|
||||||
|
Body: encode(indexcontent),
|
||||||
|
})
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
template := template.Must(template.New("code").Parse(code_template))
|
template := template.Must(template.New("code").Parse(code_template))
|
||||||
template.Execute(&buf, assets)
|
template.Execute(&buf, assets)
|
||||||
ioutil.WriteFile(outfile, buf.Bytes(), 0644)
|
ioutil.WriteFile("server/assets_bundle.go", buf.Bytes(), 0644)
|
||||||
}
|
}
|
||||||
|
@ -89,17 +89,22 @@ type ItemUpdateForm struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
t := template.Must(template.New("index.html").Delims("{%", "%}").Funcs(template.FuncMap{
|
if assets != nil {
|
||||||
"inline": func(svg string) template.HTML {
|
asset := assets["index.html"]
|
||||||
if asset, ok := assets["graphicarts/" + svg]; ok {
|
|
||||||
return template.HTML(*asset.text())
|
rw.Header().Set("Content-Type", "text/html")
|
||||||
}
|
rw.Header().Set("Content-Encoding", "gzip")
|
||||||
content, _ := ioutil.ReadFile("assets/graphicarts/" + svg)
|
rw.Write(*asset.gzip())
|
||||||
return template.HTML(content)
|
} else {
|
||||||
},
|
t := template.Must(template.New("index.html").Delims("{%", "%}").Funcs(template.FuncMap{
|
||||||
}).ParseFiles("assets/index.html"))
|
"inline": func(svg string) template.HTML {
|
||||||
rw.Header().Set("Content-Type", "text/html")
|
content, _ := ioutil.ReadFile("assets/graphicarts/" + svg)
|
||||||
t.Execute(rw, nil)
|
return template.HTML(content)
|
||||||
|
},
|
||||||
|
}).ParseFiles("assets/index.html"))
|
||||||
|
rw.Header().Set("Content-Type", "text/html")
|
||||||
|
t.Execute(rw, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func StaticHandler(rw http.ResponseWriter, req *http.Request) {
|
func StaticHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user