From 938e597f3f2a799213ae69f5b9297283efcb878e Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Mon, 18 Mar 2019 15:35:17 +0100 Subject: [PATCH] reorganized code --- content.go | 10 +++++----- context.go | 8 ++++++-- mark2web/main.go | 2 +- navigation.go | 8 ++++---- tree.go | 2 ++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/content.go b/content.go index b8addc8..da44264 100644 --- a/content.go +++ b/content.go @@ -16,7 +16,7 @@ import ( // ReadContentDir walks through content directory and builds the tree of configurations func (node *TreeNode) ReadContentDir(inBase string, outBase string, dir string, conf *PathConfig) { - node.FillConfig(inBase, outBase, dir, conf) + node.fillConfig(inBase, outBase, dir, conf) files, err := ioutil.ReadDir(node.InputPath) if err != nil { @@ -61,7 +61,7 @@ func (node *TreeNode) ReadContentDir(inBase string, outBase string, dir string, } // ProcessContent walks recursivly through the input paths and processes all files for output -func (node *TreeNode) ProcessContent(rootConf *TreeNode) { +func (node *TreeNode) ProcessContent() { helper.CreateDirectory(node.OutputPath) curNavPath := strings.TrimPrefix(node.OutputPath, Config.Directories.Output) @@ -223,14 +223,14 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] navMap := make(map[string]*NavElement) navSlice := make([]*NavElement, 0) navActive := make([]*NavElement, 0) - BuildNavigation(rootConf, &navMap, &navSlice, &navActive, curNavPath) + buildNavigation(node.root, &navMap, &navSlice, &navActive, curNavPath) // read yaml header as data for template ctx := NewContext() ctx["This"] = newConfig.This ctx["Meta"] = newConfig.Meta ctx["Data"] = newConfig.Data - ctx["ColMap"] = rootConf.ColMap // root as NavMap and NavSlice, for sub go to NavElement.ColMap + ctx["ColMap"] = node.root.ColMap // root as NavMap and NavSlice, for sub go to NavElement.ColMap ctx["NavMap"] = navMap ctx["NavSlice"] = navSlice ctx["NavActive"] = navActive @@ -289,7 +289,7 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] i := 0 // sub can dynamically increase, so no for range for i < len(node.Sub) { - node.Sub[i].ProcessContent(rootConf) + node.Sub[i].ProcessContent() i++ } } diff --git a/context.go b/context.go index 274f20d..5e4dcbc 100644 --- a/context.go +++ b/context.go @@ -153,7 +153,11 @@ func (node *TreeNode) handleCollections() { } -func (node *TreeNode) FillConfig(inBase, outBase, dir string, conf *PathConfig) { +func (node *TreeNode) fillConfig(inBase, outBase, dir string, conf *PathConfig) { + if node.root == nil { + // this must be root + node.root = node + } inPath := inBase if dir != "" { inPath += "/" + dir @@ -225,7 +229,7 @@ func (node *TreeNode) FillConfig(inBase, outBase, dir string, conf *PathConfig) func Add2Nav(currentNode *TreeNode, pathConfig *PathConfig, tplFilename, outDir string, navname string, ctx interface{}, dataMapKey string, body string, hidden bool) { newNode := new(TreeNode) - newNode.FillConfig( + newNode.fillConfig( currentNode.InputPath, currentNode.OutputPath, outDir, diff --git a/mark2web/main.go b/mark2web/main.go index 2205b1e..728ab27 100644 --- a/mark2web/main.go +++ b/mark2web/main.go @@ -138,7 +138,7 @@ func main() { if _, err := os.Stat(filtersDir); !os.IsNotExist(err) { filter.RegisterFilters(filtersDir) } - tree.ProcessContent(tree) + tree.ProcessContent() mark2web.ProcessAssets() diff --git a/navigation.go b/navigation.go index 27659d0..1e62439 100644 --- a/navigation.go +++ b/navigation.go @@ -24,9 +24,9 @@ type NavElement struct { SubSlice *[]*NavElement } -// BuildNavigation builds the navigation trees for use in templates -func BuildNavigation(node *TreeNode, curNavMap *map[string]*NavElement, curNavSlice *[]*NavElement, navActive *[]*NavElement, activeNav string) { - for _, el := range node.Sub { +// buildNavigation builds the navigation trees for use in templates +func buildNavigation(tree *TreeNode, curNavMap *map[string]*NavElement, curNavSlice *[]*NavElement, navActive *[]*NavElement, activeNav string) { + for _, el := range tree.Sub { if el.Hidden { continue // ignore hidden nav points from collections } @@ -98,6 +98,6 @@ func BuildNavigation(node *TreeNode, curNavMap *map[string]*NavElement, curNavSl *curNavSlice = append(*curNavSlice, &navEl) } - BuildNavigation(el, &subMap, &subSlice, navActive, activeNav) + buildNavigation(el, &subMap, &subSlice, navActive, activeNav) } } diff --git a/tree.go b/tree.go index 69d5f12..77c24cd 100644 --- a/tree.go +++ b/tree.go @@ -13,4 +13,6 @@ type TreeNode struct { Config *PathConfig Sub []*TreeNode + + root *TreeNode // shows always to root of tree }