assets fix
This commit is contained in:
parent
b7f31e8416
commit
c35cfec291
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
BIN
example/assets/img/logo.png
Normal file
BIN
example/assets/img/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
@ -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 <base> used
|
||||
FromPath: "assets"
|
||||
ToPath: "assets"
|
||||
Action: "copy" # symlink, copy or move
|
||||
FixTemplate: # change path in html templates, no <base> used
|
||||
Find: "\\.\\./assets/"
|
||||
Replace: ""
|
||||
|
@ -14,6 +14,7 @@
|
||||
</meta>
|
||||
<body style="margin: 0; padding: 2;">
|
||||
<header style="background-color: lightgrey; padding: 20px;">
|
||||
<div><img src="../assets/img/logo.png" style="max-width: 80%; margin-bottom: 20px;"></div>
|
||||
<div><b>main Level 1</b></div>
|
||||
<ul>
|
||||
{{#each NavMap.de.SubMap.main.SubSlice }}
|
||||
|
50
main.go
50
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()
|
||||
|
||||
}
|
||||
|
1
vendor/github.com/otiai10/copy
generated
vendored
Submodule
1
vendor/github.com/otiai10/copy
generated
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7e9a647135a142c2669943d4a4d29be015ce9392
|
Loading…
Reference in New Issue
Block a user