diff --git a/.gitmodules b/.gitmodules
index 67f2634..5c73323 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -31,3 +31,6 @@
[submodule "vendor/github.com/imdario/mergo"]
path = vendor/github.com/imdario/mergo
url = https://github.com/imdario/mergo
+[submodule "vendor/github.com/otiai10/copy"]
+ path = vendor/github.com/otiai10/copy
+ url = https://github.com/otiai10/copy
diff --git a/example/assets/img/logo.png b/example/assets/img/logo.png
new file mode 100644
index 0000000..164a187
Binary files /dev/null and b/example/assets/img/logo.png differ
diff --git a/example/config.yml b/example/config.yml
index 23ce083..7a9e071 100644
--- a/example/config.yml
+++ b/example/config.yml
@@ -2,6 +2,9 @@ Webserver:
Type: "apache" # generates .htaccess
Assets:
- Path: "/assets"
- DeployType: "symlink" # symlink, copy or move
- FixTemplate: True # change path in html templates, no used
+ FromPath: "assets"
+ ToPath: "assets"
+ Action: "copy" # symlink, copy or move
+ FixTemplate: # change path in html templates, no used
+ Find: "\\.\\./assets/"
+ Replace: ""
diff --git a/example/templates/index.html b/example/templates/index.html
index 9a6a54c..59ba59f 100644
--- a/example/templates/index.html
+++ b/example/templates/index.html
@@ -14,6 +14,7 @@
+
main Level 1
{{#each NavMap.de.SubMap.main.SubSlice }}
diff --git a/main.go b/main.go
index 6ddb046..3e28fae 100644
--- a/main.go
+++ b/main.go
@@ -13,6 +13,7 @@ import (
"github.com/aymerick/raymond"
"github.com/davecgh/go-spew/spew"
"github.com/op/go-logging"
+ cpy "github.com/otiai10/copy"
"gopkg.in/russross/blackfriday.v2"
"gopkg.in/yaml.v2"
)
@@ -27,13 +28,17 @@ var templateCache = make(map[string]*raymond.Template)
// GlobalConfig is config which is used only once in root dir
type GlobalConfig struct {
Webserver struct {
- Type *string `yaml:"Type"`
+ Type string `yaml:"Type"`
} `yaml:"Webserver"`
Assets struct {
- Path *string `yaml:"Path"`
- DeployType *string `yaml:"DeployType"`
- FixTemplate *bool `yaml:"FixTemplate"`
+ FromPath string `yaml:"FromPath"`
+ ToPath string `yaml:"ToPath"`
+ Action string `yaml:"Action"`
+ FixTemplate struct {
+ Find string `yaml:"Find"`
+ Replace string `yaml:"Replace"`
+ } `yaml:"FixTemplate"`
} `yaml:"Assets"`
}
@@ -402,6 +407,22 @@ func processContent(conf *PathConfigTree) {
log.Panicf("could not execute template '%s' for input file '%s': %s", templateFile, inFile, err)
}
+ if find := globalConfig.Assets.FixTemplate.Find; find != "" {
+ log.Debugf("fixing assets paths in '%s' for '%s'", templateFile, inFile)
+ tmpPath := ""
+ for i := len(strings.Split(curNavPath, "/")); i > 0; i-- {
+ tmpPath += "../"
+ }
+ regex, err := regexp.Compile(find)
+ if err != nil {
+ log.Panicf("could not compile regexp '%s' for assets path: %s", find, err)
+ }
+ repl := globalConfig.Assets.FixTemplate.Replace
+ repl = tmpPath + "/" + globalConfig.Assets.ToPath + "/" + repl
+ repl = path.Clean(repl) + "/"
+ result = regex.ReplaceAllString(result, repl)
+ }
+
log.Noticef("writing to output file: %s", outFile)
err = ioutil.WriteFile(outFile, []byte(result), 0644)
if err != nil {
@@ -417,6 +438,25 @@ func processContent(conf *PathConfigTree) {
}
}
+func processAssets() {
+ switch globalConfig.Assets.Action {
+ case "copy":
+ from := globalConfig.Assets.FromPath
+ to := globalConfig.Assets.ToPath
+ if !strings.HasPrefix(from, "/") {
+ from = *inDir + "/" + from
+ }
+ if !strings.HasPrefix(to, "/") {
+ to = *outDir + "/" + to
+ }
+ log.Noticef("copying assets from '%s' to '%s'", from, to)
+ err := cpy.Copy(from, to)
+ if err != nil {
+ log.Panicf("could not copy assets from '%s' to '%s': %s", from, to, err)
+ }
+ }
+}
+
func main() {
spew.Config.DisablePointerAddresses = true
spew.Config.DisableCapacities = true
@@ -535,4 +575,6 @@ func main() {
processContent(contentConfig)
+ processAssets()
+
}
diff --git a/vendor/github.com/otiai10/copy b/vendor/github.com/otiai10/copy
new file mode 160000
index 0000000..7e9a647
--- /dev/null
+++ b/vendor/github.com/otiai10/copy
@@ -0,0 +1 @@
+Subproject commit 7e9a647135a142c2669943d4a4d29be015ce9392