render paths via fnRender correct
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d78ecf4682
commit
e943271561
@ -55,13 +55,14 @@ type PathConfig struct {
|
|||||||
Filename *FilenameConfig `yaml:"Filename"`
|
Filename *FilenameConfig `yaml:"Filename"`
|
||||||
Markdown *MarkdownConfig `yaml:"Markdown"`
|
Markdown *MarkdownConfig `yaml:"Markdown"`
|
||||||
|
|
||||||
Data interface{} `yaml:"Data"`
|
Data map[string]interface{} `yaml:"Data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathConfigTree is complete config tree of content dir
|
// PathConfigTree is complete config tree of content dir
|
||||||
type PathConfigTree struct {
|
type PathConfigTree struct {
|
||||||
InputPath string
|
InputPath string
|
||||||
OutputPath string
|
OutputPath string
|
||||||
|
Hidden bool // for collections which are not part of the navigation
|
||||||
|
|
||||||
InputFiles []string
|
InputFiles []string
|
||||||
OtherFiles []string
|
OtherFiles []string
|
||||||
|
@ -164,14 +164,20 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range conf.InputFiles {
|
for _, file := range conf.InputFiles {
|
||||||
inFile := conf.InputPath + "/" + file
|
var input []byte
|
||||||
|
inFile := "InputString"
|
||||||
|
|
||||||
|
if file != "" {
|
||||||
|
inFile = conf.InputPath + "/" + file
|
||||||
Log.Debugf("reading file: %s", inFile)
|
Log.Debugf("reading file: %s", inFile)
|
||||||
|
|
||||||
input, err := ioutil.ReadFile(inFile)
|
var err error
|
||||||
|
input, err = ioutil.ReadFile(inFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Panicf("could not read '%s':%s", inFile, err)
|
Log.Panicf("could not read '%s':%s", inFile, err)
|
||||||
}
|
}
|
||||||
Log.Infof("processing input file '%s'", inFile)
|
Log.Infof("processing input file '%s'", inFile)
|
||||||
|
}
|
||||||
|
|
||||||
newConfig := new(config.PathConfig)
|
newConfig := new(config.PathConfig)
|
||||||
|
|
||||||
@ -179,7 +185,7 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
|
|||||||
yamlData := regex.Find(input)
|
yamlData := regex.Find(input)
|
||||||
if string(yamlData) != "" {
|
if string(yamlData) != "" {
|
||||||
Log.Debugf("found yaml header in '%s', merging config", inFile)
|
Log.Debugf("found yaml header in '%s', merging config", inFile)
|
||||||
err = yaml.Unmarshal(yamlData, newConfig)
|
err := yaml.Unmarshal(yamlData, newConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Panicf("could not parse YAML header from '%s': %s", inFile, err)
|
Log.Panicf("could not parse YAML header from '%s': %s", inFile, err)
|
||||||
}
|
}
|
||||||
@ -228,7 +234,10 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
|
|||||||
indexOutputFile = i.OutputFile
|
indexOutputFile = i.OutputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if indexInputFile != nil && *indexInputFile == file && indexOutputFile != nil && *indexOutputFile != "" {
|
if indexInputFile != nil &&
|
||||||
|
*indexInputFile == file &&
|
||||||
|
indexOutputFile != nil &&
|
||||||
|
*indexOutputFile != "" {
|
||||||
outputFilename = *indexOutputFile
|
outputFilename = *indexOutputFile
|
||||||
} else {
|
} else {
|
||||||
if stripRegex != nil && *stripRegex != "" {
|
if stripRegex != nil && *stripRegex != "" {
|
||||||
@ -336,7 +345,9 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, el := range conf.Sub {
|
i := 0
|
||||||
ProcessContent(rootConf, el)
|
for i < len(conf.Sub) {
|
||||||
|
ProcessContent(rootConf, conf.Sub[i])
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,10 @@ type NavElement struct {
|
|||||||
|
|
||||||
func BuildNavigation(conf *config.PathConfigTree, curNavMap *map[string]*NavElement, curNavSlice *[]*NavElement, navActive *[]*NavElement, activeNav string) {
|
func BuildNavigation(conf *config.PathConfigTree, curNavMap *map[string]*NavElement, curNavSlice *[]*NavElement, navActive *[]*NavElement, activeNav string) {
|
||||||
for _, el := range conf.Sub {
|
for _, el := range conf.Sub {
|
||||||
|
if el.Hidden {
|
||||||
|
continue // ignore hidden nav points from collections
|
||||||
|
}
|
||||||
|
|
||||||
var ignNav *string
|
var ignNav *string
|
||||||
if p := el.Config.Path; p != nil {
|
if p := el.Config.Path; p != nil {
|
||||||
ignNav = p.IgnoreForNav
|
ignNav = p.IgnoreForNav
|
||||||
|
@ -4,14 +4,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitbase.de/apairon/mark2web/config"
|
"gitbase.de/apairon/mark2web/config"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/extemporalgenome/slug"
|
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,11 +52,59 @@ func RequestFn(url *pongo2.Value, args ...*pongo2.Value) *pongo2.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RenderFn renders a pongo2 template with additional context
|
// RenderFn renders a pongo2 template with additional context
|
||||||
func RenderFn(templateFilename, outDir, subCtxName, ctx *pongo2.Value) *pongo2.Value {
|
func RenderFn(templateFilename, outDir, ctx *pongo2.Value, param ...*pongo2.Value) *pongo2.Value {
|
||||||
|
ctxMapKey := ""
|
||||||
|
for i, p := range param {
|
||||||
|
switch i {
|
||||||
|
case 0:
|
||||||
|
ctxMapKey = p.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newNodeConfig := new(config.PathConfigTree)
|
||||||
|
fillNodeConfig(
|
||||||
|
newNodeConfig,
|
||||||
|
currentTreeNodeConfig.InputPath,
|
||||||
|
currentTreeNodeConfig.OutputPath,
|
||||||
|
outDir.String(),
|
||||||
|
currentPathConfig,
|
||||||
|
)
|
||||||
|
if newNodeConfig.Config.Data == nil {
|
||||||
|
newNodeConfig.Config.Data = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
if ctxMapKey != "" {
|
||||||
|
// as submap in Data
|
||||||
|
newNodeConfig.Config.Data[ctxMapKey] = ctx.Interface()
|
||||||
|
} else if m, ok := ctx.Interface().(map[string]interface{}); ok {
|
||||||
|
// direct set data
|
||||||
|
newNodeConfig.Config.Data = m
|
||||||
|
}
|
||||||
|
tplFilename := templateFilename.String()
|
||||||
|
|
||||||
|
// fake via normal file behavior
|
||||||
|
newNodeConfig.Config.Template = &tplFilename
|
||||||
|
newNodeConfig.InputFiles = []string{""} // empty file is special for use InputString
|
||||||
|
indexInFile := ""
|
||||||
|
indexOutFile := "index.html"
|
||||||
|
if idx := newNodeConfig.Config.Index; idx != nil {
|
||||||
|
if idx.OutputFile != nil && *idx.OutputFile != "" {
|
||||||
|
indexOutFile = *idx.OutputFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newNodeConfig.Config.Index = &config.IndexConfig{
|
||||||
|
InputFile: &indexInFile,
|
||||||
|
OutputFile: &indexOutFile,
|
||||||
|
}
|
||||||
|
newNodeConfig.Hidden = true
|
||||||
|
|
||||||
|
currentTreeNodeConfig.Sub = append(currentTreeNodeConfig.Sub, newNodeConfig)
|
||||||
|
spew.Dump(currentTreeNodeConfig)
|
||||||
|
|
||||||
|
/*
|
||||||
oDirSlug := slug.Slug(outDir.String())
|
oDirSlug := slug.Slug(outDir.String())
|
||||||
navPath := path.Clean((*currentContext)["CurrentPath"].(string) + "/" + oDirSlug)
|
navPath := path.Clean((*currentContext)["CurrentPath"].(string) + "/" + oDirSlug)
|
||||||
outputPath := path.Clean(currentTreeNodeConfig.OutputPath + "/" + oDirSlug)
|
|
||||||
CreateDirectory(outputPath)
|
CreateDirectory(newNodeConfig.OutputPath)
|
||||||
|
|
||||||
newContext := make(map[string]interface{})
|
newContext := make(map[string]interface{})
|
||||||
if err := config.Merge(&newContext, *currentContext); err != nil {
|
if err := config.Merge(&newContext, *currentContext); err != nil {
|
||||||
@ -68,12 +113,6 @@ func RenderFn(templateFilename, outDir, subCtxName, ctx *pongo2.Value) *pongo2.V
|
|||||||
newContext[subCtxName.String()] = ctx
|
newContext[subCtxName.String()] = ctx
|
||||||
newContext["CurrentPath"] = navPath
|
newContext["CurrentPath"] = navPath
|
||||||
|
|
||||||
newNodeConfig := new(config.PathConfigTree)
|
|
||||||
if err := config.Merge(newNodeConfig, currentTreeNodeConfig); err != nil {
|
|
||||||
Log.Panicf("unable to merge tree node config")
|
|
||||||
}
|
|
||||||
newNodeConfig.OutputPath = outputPath
|
|
||||||
|
|
||||||
// remember old to set after recursion
|
// remember old to set after recursion
|
||||||
oldContext := currentContext
|
oldContext := currentContext
|
||||||
oldNodeConfig := currentTreeNodeConfig
|
oldNodeConfig := currentTreeNodeConfig
|
||||||
@ -107,7 +146,7 @@ func RenderFn(templateFilename, outDir, subCtxName, ctx *pongo2.Value) *pongo2.V
|
|||||||
outputFilename = *indexOutputFile
|
outputFilename = *indexOutputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
outFile := outputPath + "/" + outputFilename
|
outFile := newNodeConfig.OutputPath + "/" + outputFilename
|
||||||
Log.Debugf("using '%s' as output file", outFile)
|
Log.Debugf("using '%s' as output file", outFile)
|
||||||
|
|
||||||
Log.Noticef("writing to output file: %s", outFile)
|
Log.Noticef("writing to output file: %s", outFile)
|
||||||
@ -115,6 +154,7 @@ func RenderFn(templateFilename, outDir, subCtxName, ctx *pongo2.Value) *pongo2.V
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("could not write to output file '%s': %s", outFile, err)
|
log.Panicf("could not write to output file '%s': %s", outFile, err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return pongo2.AsValue(nil)
|
return pongo2.AsValue(nil)
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ hr {height:1px; background:none; border-bottom:dotted 1px #666; margin-bottom:20
|
|||||||
.btn {
|
.btn {
|
||||||
padding:8px 15px;
|
padding:8px 15px;
|
||||||
background:#464645;
|
background:#464645;
|
||||||
|
border: 1px solid #fff;
|
||||||
color:#FFF;
|
color:#FFF;
|
||||||
transition:all 0.3s;
|
transition:all 0.3s;
|
||||||
text-transform:none;
|
text-transform:none;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
{{ e.teaser|markdown }}
|
{{ e.teaser|markdown }}
|
||||||
{% if e.body %}
|
{% if e.body %}
|
||||||
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
|
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
|
||||||
{{ fnRender("base_blog_details.html", e.title, "details", e) }}
|
{{ fnRender("base_blog_details.html", e.title, e) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock part0 %}
|
{% endblock part0 %}
|
||||||
@ -27,7 +27,7 @@
|
|||||||
{{ e.teaser|markdown }}
|
{{ e.teaser|markdown }}
|
||||||
{% if e.body %}
|
{% if e.body %}
|
||||||
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
|
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
|
||||||
{{ fnRender("base_blog_details.html", e.title, "details", e) }}
|
{{ fnRender("base_blog_details.html", e.title, e) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock part1 %}
|
{% endblock part1 %}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block part0 %}
|
{% block part0 %}
|
||||||
<h1>{{ details.title }}</h1>
|
<h1>{{ Data.title }}</h1>
|
||||||
{{ details.teaser|markdown }}
|
{{ Data.teaser|markdown }}
|
||||||
{% endblock part0 %}
|
{% endblock part0 %}
|
||||||
|
|
||||||
{% block part1 %}
|
{% block part1 %}
|
||||||
{{ details.body|markdown }}
|
{{ Data.body|markdown }}
|
||||||
{% endblock part1 %}
|
{% endblock part1 %}
|
Loading…
Reference in New Issue
Block a user