diff --git a/config/tree.go b/config/tree.go index f658273..037645d 100644 --- a/config/tree.go +++ b/config/tree.go @@ -15,8 +15,9 @@ type ThisPathConfig struct { // IndexConfig describes index input and output file type IndexConfig struct { - InputFile *string `yaml:"InputFile"` - OutputFile *string `yaml:"OutputFile"` + InputFile *string `yaml:"InputFile"` + InputString *string `yaml:"InputString"` + OutputFile *string `yaml:"OutputFile"` } // MetaData describes meta data for current site/tree node diff --git a/helper/assets.go b/helper/assets.go index e4220c8..541cebf 100644 --- a/helper/assets.go +++ b/helper/assets.go @@ -7,6 +7,7 @@ import ( cpy "github.com/otiai10/copy" ) +// ProcessAssets copies the assets from input to output dir func ProcessAssets() { switch config.Config.Assets.Action { case "copy": diff --git a/helper/content.go b/helper/content.go index c74d4a7..7a4350a 100644 --- a/helper/content.go +++ b/helper/content.go @@ -86,6 +86,7 @@ func fillNodeConfig(node *config.PathConfigTree, inBase, outBase, dir string, co } +// ReadContentDir walks through content directory and builds the tree of configurations func ReadContentDir(inBase string, outBase string, dir string, conf *config.PathConfig, tree *config.PathConfigTree) { fillNodeConfig(tree, inBase, outBase, dir, conf) @@ -131,6 +132,7 @@ func ReadContentDir(inBase string, outBase string, dir string, conf *config.Path } } +// ProcessContent walks recursivly through the input paths and processes all files for output func ProcessContent(rootConf, conf *config.PathConfigTree) { CreateDirectory(conf.OutputPath) @@ -177,6 +179,17 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] Log.Panicf("could not read '%s':%s", inFile, err) } Log.Infof("processing input file '%s'", inFile) + } else { + // use input string if available and input filename == "" + var inputString *string + if i := conf.Config.Index; i != nil { + inputString = i.InputString + } + if inputString != nil { + Log.Debugf("using input string instead of file") + input = []byte(*inputString) + spew.Dump(string(input)) + } } newConfig := new(config.PathConfig) @@ -184,6 +197,9 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] regex := regexp.MustCompile("(?s)^---(.*?)\\r?\\n\\r?---\\r?\\n\\r?") yamlData := regex.Find(input) if string(yamlData) != "" { + // replace tabs + yamlData = bytes.Replace(yamlData, []byte("\t"), []byte(" "), -1) + Log.Debugf("found yaml header in '%s', merging config", inFile) err := yaml.Unmarshal(yamlData, newConfig) if err != nil { diff --git a/helper/markdown.go b/helper/markdown.go new file mode 100644 index 0000000..947317d --- /dev/null +++ b/helper/markdown.go @@ -0,0 +1 @@ +package helper diff --git a/helper/navigation.go b/helper/navigation.go index f331afb..7f3ada5 100644 --- a/helper/navigation.go +++ b/helper/navigation.go @@ -8,6 +8,7 @@ import ( "gitbase.de/apairon/mark2web/config" ) +// NavElement is one element with ist attributes and subs type NavElement struct { Navname string GoTo string @@ -21,6 +22,7 @@ type NavElement struct { SubSlice *[]*NavElement } +// BuildNavigation builds the navigation trees for use in templates func BuildNavigation(conf *config.PathConfigTree, curNavMap *map[string]*NavElement, curNavSlice *[]*NavElement, navActive *[]*NavElement, activeNav string) { for _, el := range conf.Sub { if el.Hidden { diff --git a/helper/render.go b/helper/render.go index c8b243f..3b3b06c 100644 --- a/helper/render.go +++ b/helper/render.go @@ -67,7 +67,7 @@ func FixAssetsPath(str, curNavPath string) string { repl = path.Clean(repl) + "/" Log.Debugf("new assets paths: %s", repl) return regex.ReplaceAllString(str, repl) - } else { - return str } + + return str } diff --git a/helper/template_functions.go b/helper/template_functions.go index 3f33e27..01ed2d7 100644 --- a/helper/template_functions.go +++ b/helper/template_functions.go @@ -54,10 +54,14 @@ 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 { ctxMapKey := "" + body := "" + for i, p := range param { switch i { case 0: ctxMapKey = p.String() + case 1: + body = p.String() } } @@ -92,8 +96,9 @@ func RenderFn(templateFilename, outDir, ctx *pongo2.Value, param ...*pongo2.Valu } } newNodeConfig.Config.Index = &config.IndexConfig{ - InputFile: &indexInFile, - OutputFile: &indexOutFile, + InputFile: &indexInFile, + OutputFile: &indexOutFile, + InputString: &body, } newNodeConfig.Hidden = true diff --git a/website/templates/base_blog.html b/website/templates/base_blog.html index 3ddbcb3..7783709 100644 --- a/website/templates/base_blog.html +++ b/website/templates/base_blog.html @@ -10,7 +10,7 @@ {{ e.teaser|markdown }} {% if e.body %} mehr lesen - {{ fnRender("base_blog_details.html", e.title, e) }} + {{ fnRender("base_blog_details.html", e.title, e, "details", e.body) }} {% endif %} {% endfor %} {% endblock part0 %} @@ -27,7 +27,7 @@ {{ e.teaser|markdown }} {% if e.body %} mehr lesen - {{ fnRender("base_blog_details.html", e.title, e) }} + {{ fnRender("base_blog_details.html", e.title, e, "details", e.body) }} {% endif %} {% endfor %} {% endblock part1 %} diff --git a/website/templates/base_blog_details.html b/website/templates/base_blog_details.html index 6e5f2f2..4e6b100 100644 --- a/website/templates/base_blog_details.html +++ b/website/templates/base_blog_details.html @@ -2,9 +2,9 @@ {% block part0 %}

{{ Data.title }}

- {{ Data.teaser|markdown }} + {{ Data.details.teaser|markdown }} {% endblock part0 %} {% block part1 %} - {{ Data.body|markdown }} + {{ Body }} {% endblock part1 %} \ No newline at end of file