router_static.go: do multiple rounds of templating
This commit is contained in:
parent
c21329ac4e
commit
93595f3877
@ -27,6 +27,8 @@ type staticHtmlPlugs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func staticRouterInit(router *mux.Router) error {
|
func staticRouterInit(router *mux.Router) error {
|
||||||
|
subdir := pathStrip(os.Getenv("ORIGIN"))
|
||||||
|
|
||||||
asset := make(map[string][]byte)
|
asset := make(map[string][]byte)
|
||||||
gzippedAsset := make(map[string][]byte)
|
gzippedAsset := make(map[string][]byte)
|
||||||
|
|
||||||
@ -57,8 +59,6 @@ func staticRouterInit(router *mux.Router) error {
|
|||||||
|
|
||||||
gzip := (os.Getenv("GZIP_STATIC") == "true")
|
gzip := (os.Getenv("GZIP_STATIC") == "true")
|
||||||
|
|
||||||
subdir := pathStrip(os.Getenv("ORIGIN"))
|
|
||||||
|
|
||||||
asset[subdir+p] = []byte(prefix + string(contents))
|
asset[subdir+p] = []byte(prefix + string(contents))
|
||||||
if gzip {
|
if gzip {
|
||||||
gzippedAsset[subdir+p], err = gzipStatic(asset[subdir+p])
|
gzippedAsset[subdir+p], err = gzipStatic(asset[subdir+p])
|
||||||
@ -101,6 +101,10 @@ func staticRouterInit(router *mux.Router) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
html := make(map[string]string)
|
html := make(map[string]string)
|
||||||
|
for _, page := range pages {
|
||||||
|
html[subdir+page] = ""
|
||||||
|
}
|
||||||
|
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
sl := string(os.PathSeparator)
|
sl := string(os.PathSeparator)
|
||||||
page = sl + page
|
page = sl + page
|
||||||
@ -112,7 +116,10 @@ func staticRouterInit(router *mux.Router) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.New(page).Delims("[[[", "]]]").Parse(string(contents))
|
result := string(contents)
|
||||||
|
|
||||||
|
for {
|
||||||
|
t, err := template.New(page).Delims("[[[", "]]]").Parse(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("cannot parse %s%s template: %v", os.Getenv("STATIC"), file, err)
|
logger.Errorf("cannot parse %s%s template: %v", os.Getenv("STATIC"), file, err)
|
||||||
return err
|
return err
|
||||||
@ -125,9 +132,14 @@ func staticRouterInit(router *mux.Router) error {
|
|||||||
Footer: template.HTML(string(footer)),
|
Footer: template.HTML(string(footer)),
|
||||||
})
|
})
|
||||||
|
|
||||||
subdir := pathStrip(os.Getenv("ORIGIN"))
|
result = buf.String()
|
||||||
|
if result == html[subdir+page] {
|
||||||
html[subdir+page] = buf.String()
|
break
|
||||||
|
} else {
|
||||||
|
html[subdir+page] = result
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
|
Loading…
Reference in New Issue
Block a user