multipart markdown documents

This commit is contained in:
Sebastian Frank 2019-02-13 19:14:23 +01:00
parent bf2a836cdc
commit 26418217ac
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3
3 changed files with 22 additions and 3 deletions
example
content/de/main/02_Leistungen_und_Referenzen
templates
main.go

@ -11,4 +11,10 @@ Template: mitBild.html
# Leistungen
Hier stehen die ***Referenzen***, dsfdfsadfasdf.
Hier stehen die ***Referenzen***, dsfdfsadfasdf.
---
### Hinweis
Das hier ist der `BodyPart.[1]`

@ -9,7 +9,11 @@
<img src="{{ Data.bild }}" id="dataImg">
{{/if}}
{{{ Body }}}
{{{ BodyParts.[0] }}}
{{#if BodyParts.[1] }}
<div class="info">{{{ BodyParts.[1] }}}</div>
{{/if}}
</div>

11
main.go

@ -355,7 +355,7 @@ func processContent(conf *PathConfigTree) {
newConfig := new(PathConfig)
regex := regexp.MustCompile("(?sm)^---(.*)^---")
regex := regexp.MustCompile("(?s)^---(.*?)\\r?\\n\\r?---\\r?\\n\\r?")
yamlData := regex.Find(input)
if string(yamlData) != "" {
log.Debugf("found yaml header in '%s', merging config", inFile)
@ -417,6 +417,14 @@ func processContent(conf *PathConfigTree) {
//html := blackfriday.Run(input, blackfriday.WithRenderer(bfchroma.NewRenderer()))
html := blackfriday.Run(input)
// use --- for splitting document in markdown parts
regex := regexp.MustCompile("\\r?\\n\\r?---\\r?\\n\\r?")
inputParts := regex.Split(string(input), -1)
htmlParts := make([]string, 0)
for _, iPart := range inputParts {
htmlParts = append(htmlParts, string(blackfriday.Run([]byte(iPart))))
}
log.Debugf("rendering template '%s' for '%s'", *newConfig.Template, outFile)
templateFile := *inDir + "/templates/" + *newConfig.Template
template := templateCache[templateFile]
@ -449,6 +457,7 @@ func processContent(conf *PathConfigTree) {
ctx["NavSlice"] = navSlice
ctx["NavActive"] = navActive
ctx["Body"] = string(html)
ctx["BodyParts"] = htmlParts
result, err := template.Exec(ctx)
if err != nil {