added body to fnRender

This commit is contained in:
Sebastian Frank 2019-02-28 15:13:59 +01:00
parent e943271561
commit 5acc4083aa
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3
9 changed files with 36 additions and 10 deletions

View File

@ -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

View File

@ -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":

View File

@ -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 {

1
helper/markdown.go Normal file
View File

@ -0,0 +1 @@
package helper

View File

@ -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 {

View File

@ -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
}

View File

@ -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

View File

@ -10,7 +10,7 @@
{{ e.teaser|markdown }}
{% if e.body %}
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
{{ 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 %}
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
{{ fnRender("base_blog_details.html", e.title, e) }}
{{ fnRender("base_blog_details.html", e.title, e, "details", e.body) }}
{% endif %}
{% endfor %}
{% endblock part1 %}

View File

@ -2,9 +2,9 @@
{% block part0 %}
<h1>{{ Data.title }}</h1>
{{ Data.teaser|markdown }}
{{ Data.details.teaser|markdown }}
{% endblock part0 %}
{% block part1 %}
{{ Data.body|markdown }}
{{ Body }}
{% endblock part1 %}