diff --git a/api/router_static.go b/api/router_static.go index fa9d9a3..bcc6a99 100644 --- a/api/router_static.go +++ b/api/router_static.go @@ -27,6 +27,8 @@ type staticHtmlPlugs struct { } func staticRouterInit(router *mux.Router) error { + subdir := pathStrip(os.Getenv("ORIGIN")) + asset := 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") - subdir := pathStrip(os.Getenv("ORIGIN")) - asset[subdir+p] = []byte(prefix + string(contents)) if gzip { gzippedAsset[subdir+p], err = gzipStatic(asset[subdir+p]) @@ -101,6 +101,10 @@ func staticRouterInit(router *mux.Router) error { } html := make(map[string]string) + for _, page := range pages { + html[subdir+page] = "" + } + for _, page := range pages { sl := string(os.PathSeparator) page = sl + page @@ -112,22 +116,30 @@ func staticRouterInit(router *mux.Router) error { return err } - t, err := template.New(page).Delims("[[[", "]]]").Parse(string(contents)) - if err != nil { - logger.Errorf("cannot parse %s%s template: %v", os.Getenv("STATIC"), file, err) - return err + result := string(contents) + + for { + t, err := template.New(page).Delims("[[[", "]]]").Parse(result) + if err != nil { + logger.Errorf("cannot parse %s%s template: %v", os.Getenv("STATIC"), file, err) + return err + } + + var buf bytes.Buffer + t.Execute(&buf, &staticHtmlPlugs{ + Origin: os.Getenv("ORIGIN"), + CdnPrefix: os.Getenv("CDN_PREFIX"), + Footer: template.HTML(string(footer)), + }) + + result = buf.String() + if result == html[subdir+page] { + break + } else { + html[subdir+page] = result + continue + } } - - var buf bytes.Buffer - t.Execute(&buf, &staticHtmlPlugs{ - Origin: os.Getenv("ORIGIN"), - CdnPrefix: os.Getenv("CDN_PREFIX"), - Footer: template.HTML(string(footer)), - }) - - subdir := pathStrip(os.Getenv("ORIGIN")) - - html[subdir+page] = buf.String() } for _, page := range pages {