From 7dbaa95a90669c82d4b0c2f5733120befc65c086 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Fri, 15 Feb 2019 12:11:27 +0100 Subject: [PATCH] do not copy config.yml --- main.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index cbbbc20..932e974 100644 --- a/main.go +++ b/main.go @@ -101,6 +101,16 @@ type PathConfigTree struct { var contentConfig = new(PathConfigTree) +func backToRoot(curNavPath string) string { + tmpPath := "" + if curNavPath != "" { + for i := strings.Count(curNavPath, "/") + 1; i > 0; i-- { + tmpPath += "../" + } + } + return tmpPath +} + func readContentDir(inBase string, outBase string, dir string, conf *PathConfig, tree *PathConfigTree) { inPath := inBase if dir != "" { @@ -172,7 +182,7 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig, // first only files for _, f := range files { p := inPath + "/" + f.Name() - if !f.IsDir() { + if !f.IsDir() && f.Name() != "config.yml" { switch path.Ext(f.Name()) { case ".md": log.Debugf(".MD %s", p) @@ -274,11 +284,8 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu if activeNav != "" && activeNav != "/" { // calculate relative path - tmpPath := "" - for i := len(strings.Split(activeNav, "/")); i > 0; i-- { - tmpPath += "../" - } - navEl.GoTo = tmpPath + navEl.GoTo + bToRoot := backToRoot(activeNav) + navEl.GoTo = bToRoot + navEl.GoTo navEl.GoTo = path.Clean(navEl.GoTo) } @@ -436,18 +443,13 @@ func processContent(conf *PathConfigTree) { if find := globalConfig.Assets.FixTemplate.Find; find != "" { log.Debugf("fixing assets paths in '%s' for '%s'", templateFile, inFile) - tmpPath := "" - if curNavPath != "" { - for i := len(strings.Split(curNavPath, "/")); i > 0; i-- { - tmpPath += "../" - } - } + bToRoot := backToRoot(curNavPath) 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 = bToRoot + globalConfig.Assets.ToPath + "/" + repl repl = path.Clean(repl) + "/" log.Debugf("new assets paths: %s", repl) result = regex.ReplaceAllString(result, repl)