optimized code
This commit is contained in:
parent
0dfe0f8142
commit
ada333a0e1
@ -21,7 +21,7 @@ import (
|
||||
func parseImageParams(str string) (*mark2web.ImagingConfig, error) {
|
||||
p := mark2web.ImagingConfig{}
|
||||
if str == "" {
|
||||
helper.Merge(&p, mark2web.CurrentPathConfig.Imaging)
|
||||
helper.Merge(&p, mark2web.CurrentTreeNode.Config.Imaging)
|
||||
// Filename and Format are only valid for current image
|
||||
p.Filename = ""
|
||||
p.Format = ""
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
func MarkdownFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||
chromaRenderer := false
|
||||
chromaStyle := "monokai"
|
||||
if m := mark2web.CurrentPathConfig.Markdown; m != nil {
|
||||
if m := mark2web.CurrentTreeNode.Config.Markdown; m != nil {
|
||||
if m.ChromaRenderer != nil && *m.ChromaRenderer {
|
||||
chromaRenderer = true
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
|
||||
var CurrentContext *pongo2.Context
|
||||
var CurrentTreeNode *TreeNode
|
||||
var CurrentPathConfig *PathConfig
|
||||
|
||||
func NewContext() pongo2.Context {
|
||||
ctx := pongo2.Context{
|
||||
@ -146,17 +145,17 @@ func (node *TreeNode) handleCollections() {
|
||||
}
|
||||
}
|
||||
|
||||
Add2Nav(node, node.Config, tpl, goTo, navname, colEl, dataKey, body, navT.Hidden)
|
||||
node.addSubNode(tpl, goTo, navname, colEl, dataKey, body, navT.Hidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (node *TreeNode) fillConfig(inBase, outBase, dir string, conf *PathConfig) {
|
||||
func (node *TreeNode) fillConfig(inBase, outBase, subDir string, conf *PathConfig) {
|
||||
inPath := inBase
|
||||
if dir != "" {
|
||||
inPath += "/" + dir
|
||||
if subDir != "" {
|
||||
inPath += "/" + subDir
|
||||
}
|
||||
|
||||
helper.Log.Infof("reading input directory: %s", inPath)
|
||||
@ -194,14 +193,14 @@ func (node *TreeNode) fillConfig(inBase, outBase, dir string, conf *PathConfig)
|
||||
node.Config = newConfig
|
||||
|
||||
// calc outDir
|
||||
stripedDir := dir
|
||||
stripedDir := subDir
|
||||
var regexStr *string
|
||||
if newConfig.Path != nil {
|
||||
regexStr = newConfig.Path.Strip
|
||||
}
|
||||
if regexStr != nil && *regexStr != "" {
|
||||
if regex, err := regexp.Compile(*regexStr); err != nil {
|
||||
helper.Log.Panicf("error compiling path.strip regex '%s' from '%s': %s", *regexStr, inBase+"/"+dir, err)
|
||||
helper.Log.Panicf("error compiling path.strip regex '%s' from '%s': %s", *regexStr, inBase+"/"+subDir, err)
|
||||
} else {
|
||||
stripedDir = regex.ReplaceAllString(stripedDir, "$1")
|
||||
}
|
||||
@ -223,14 +222,14 @@ func (node *TreeNode) fillConfig(inBase, outBase, dir string, conf *PathConfig)
|
||||
node.handleCollections()
|
||||
}
|
||||
|
||||
func Add2Nav(currentNode *TreeNode, pathConfig *PathConfig, tplFilename, outDir string, navname string, ctx interface{}, dataMapKey string, body string, hidden bool) {
|
||||
func (node *TreeNode) addSubNode(tplFilename, subDir string, navname string, ctx interface{}, dataMapKey string, body string, hideInNav bool) {
|
||||
newNode := new(TreeNode)
|
||||
newNode.root = currentNode.root
|
||||
newNode.root = node.root
|
||||
newNode.fillConfig(
|
||||
currentNode.InputPath,
|
||||
currentNode.OutputPath,
|
||||
outDir,
|
||||
pathConfig,
|
||||
node.InputPath,
|
||||
node.OutputPath,
|
||||
subDir,
|
||||
node.Config,
|
||||
)
|
||||
if navname != "" {
|
||||
newNode.Config.This = ThisPathConfig{
|
||||
@ -263,7 +262,7 @@ func Add2Nav(currentNode *TreeNode, pathConfig *PathConfig, tplFilename, outDir
|
||||
OutputFile: &indexOutFile,
|
||||
InputString: &body,
|
||||
}
|
||||
newNode.Hidden = hidden
|
||||
newNode.Hidden = hideInNav
|
||||
|
||||
currentNode.Sub = append(currentNode.Sub, newNode)
|
||||
node.Sub = append(node.Sub, newNode)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ func RequestFn(url *pongo2.Value, args ...*pongo2.Value) *pongo2.Value {
|
||||
}
|
||||
|
||||
// RenderFn renders a pongo2 template with additional context
|
||||
func RenderFn(templateFilename, outDir, ctx *pongo2.Value, param ...*pongo2.Value) *pongo2.Value {
|
||||
func RenderFn(templateFilename, subDir, ctx *pongo2.Value, param ...*pongo2.Value) *pongo2.Value {
|
||||
dataMapKey := ""
|
||||
body := ""
|
||||
|
||||
@ -25,7 +25,7 @@ func RenderFn(templateFilename, outDir, ctx *pongo2.Value, param ...*pongo2.Valu
|
||||
}
|
||||
}
|
||||
|
||||
Add2Nav(CurrentTreeNode, CurrentPathConfig, templateFilename.String(), outDir.String(), "", ctx.Interface(), dataMapKey, body, true)
|
||||
CurrentTreeNode.addSubNode(templateFilename.String(), subDir.String(), "", ctx.Interface(), dataMapKey, body, true)
|
||||
|
||||
return pongo2.AsValue(nil)
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ func SetTemplateDir(dir string) {
|
||||
func renderTemplate(filename string, node *TreeNode, pathConfig *PathConfig, ctx *pongo2.Context) (string, error) {
|
||||
CurrentContext = ctx
|
||||
CurrentTreeNode = node
|
||||
CurrentPathConfig = pathConfig
|
||||
templateFile := templateDir + "/" + filename
|
||||
template := templateCache[templateFile]
|
||||
if template == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user