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
|
||||||
Log.Debugf("reading file: %s", inFile)
|
inFile := "InputString"
|
||||||
|
|
||||||
input, err := ioutil.ReadFile(inFile)
|
if file != "" {
|
||||||
if err != nil {
|
inFile = conf.InputPath + "/" + file
|
||||||
Log.Panicf("could not read '%s':%s", inFile, err)
|
Log.Debugf("reading file: %s", inFile)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
input, err = ioutil.ReadFile(inFile)
|
||||||
|
if err != nil {
|
||||||
|
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,66 +52,109 @@ 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 {
|
||||||
oDirSlug := slug.Slug(outDir.String())
|
ctxMapKey := ""
|
||||||
navPath := path.Clean((*currentContext)["CurrentPath"].(string) + "/" + oDirSlug)
|
for i, p := range param {
|
||||||
outputPath := path.Clean(currentTreeNodeConfig.OutputPath + "/" + oDirSlug)
|
switch i {
|
||||||
CreateDirectory(outputPath)
|
case 0:
|
||||||
|
ctxMapKey = p.String()
|
||||||
newContext := make(map[string]interface{})
|
}
|
||||||
if err := config.Merge(&newContext, *currentContext); err != nil {
|
|
||||||
Log.Panicf("unable to merge context")
|
|
||||||
}
|
}
|
||||||
newContext[subCtxName.String()] = ctx
|
|
||||||
newContext["CurrentPath"] = navPath
|
|
||||||
|
|
||||||
newNodeConfig := new(config.PathConfigTree)
|
newNodeConfig := new(config.PathConfigTree)
|
||||||
if err := config.Merge(newNodeConfig, currentTreeNodeConfig); err != nil {
|
fillNodeConfig(
|
||||||
Log.Panicf("unable to merge tree node config")
|
|
||||||
}
|
|
||||||
newNodeConfig.OutputPath = outputPath
|
|
||||||
|
|
||||||
// remember old to set after recursion
|
|
||||||
oldContext := currentContext
|
|
||||||
oldNodeConfig := currentTreeNodeConfig
|
|
||||||
result, err := RenderTemplate(
|
|
||||||
templateFilename.String(),
|
|
||||||
newNodeConfig,
|
newNodeConfig,
|
||||||
|
currentTreeNodeConfig.InputPath,
|
||||||
|
currentTreeNodeConfig.OutputPath,
|
||||||
|
outDir.String(),
|
||||||
currentPathConfig,
|
currentPathConfig,
|
||||||
&newContext,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if newNodeConfig.Config.Data == nil {
|
||||||
panic(err)
|
newNodeConfig.Config.Data = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
currentContext = oldContext
|
if ctxMapKey != "" {
|
||||||
currentTreeNodeConfig = oldNodeConfig
|
// as submap in Data
|
||||||
|
newNodeConfig.Config.Data[ctxMapKey] = ctx.Interface()
|
||||||
result = FixAssetsPath(
|
} else if m, ok := ctx.Interface().(map[string]interface{}); ok {
|
||||||
result,
|
// direct set data
|
||||||
navPath,
|
newNodeConfig.Config.Data = m
|
||||||
)
|
|
||||||
//spew.Dump(result)
|
|
||||||
|
|
||||||
// build output filename
|
|
||||||
outputFilename := "index.html"
|
|
||||||
|
|
||||||
var indexOutputFile *string
|
|
||||||
if i := currentPathConfig.Index; i != nil {
|
|
||||||
indexOutputFile = i.OutputFile
|
|
||||||
}
|
}
|
||||||
|
tplFilename := templateFilename.String()
|
||||||
|
|
||||||
if indexOutputFile != nil && *indexOutputFile != "" {
|
// fake via normal file behavior
|
||||||
outputFilename = *indexOutputFile
|
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{
|
||||||
outFile := outputPath + "/" + outputFilename
|
InputFile: &indexInFile,
|
||||||
Log.Debugf("using '%s' as output file", outFile)
|
OutputFile: &indexOutFile,
|
||||||
|
|
||||||
Log.Noticef("writing to output file: %s", outFile)
|
|
||||||
err = ioutil.WriteFile(outFile, []byte(result), 0644)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("could not write to output file '%s': %s", outFile, err)
|
|
||||||
}
|
}
|
||||||
|
newNodeConfig.Hidden = true
|
||||||
|
|
||||||
|
currentTreeNodeConfig.Sub = append(currentTreeNodeConfig.Sub, newNodeConfig)
|
||||||
|
spew.Dump(currentTreeNodeConfig)
|
||||||
|
|
||||||
|
/*
|
||||||
|
oDirSlug := slug.Slug(outDir.String())
|
||||||
|
navPath := path.Clean((*currentContext)["CurrentPath"].(string) + "/" + oDirSlug)
|
||||||
|
|
||||||
|
CreateDirectory(newNodeConfig.OutputPath)
|
||||||
|
|
||||||
|
newContext := make(map[string]interface{})
|
||||||
|
if err := config.Merge(&newContext, *currentContext); err != nil {
|
||||||
|
Log.Panicf("unable to merge context")
|
||||||
|
}
|
||||||
|
newContext[subCtxName.String()] = ctx
|
||||||
|
newContext["CurrentPath"] = navPath
|
||||||
|
|
||||||
|
// remember old to set after recursion
|
||||||
|
oldContext := currentContext
|
||||||
|
oldNodeConfig := currentTreeNodeConfig
|
||||||
|
result, err := RenderTemplate(
|
||||||
|
templateFilename.String(),
|
||||||
|
newNodeConfig,
|
||||||
|
currentPathConfig,
|
||||||
|
&newContext,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
currentContext = oldContext
|
||||||
|
currentTreeNodeConfig = oldNodeConfig
|
||||||
|
|
||||||
|
result = FixAssetsPath(
|
||||||
|
result,
|
||||||
|
navPath,
|
||||||
|
)
|
||||||
|
//spew.Dump(result)
|
||||||
|
|
||||||
|
// build output filename
|
||||||
|
outputFilename := "index.html"
|
||||||
|
|
||||||
|
var indexOutputFile *string
|
||||||
|
if i := currentPathConfig.Index; i != nil {
|
||||||
|
indexOutputFile = i.OutputFile
|
||||||
|
}
|
||||||
|
|
||||||
|
if indexOutputFile != nil && *indexOutputFile != "" {
|
||||||
|
outputFilename = *indexOutputFile
|
||||||
|
}
|
||||||
|
|
||||||
|
outFile := newNodeConfig.OutputPath + "/" + outputFilename
|
||||||
|
Log.Debugf("using '%s' as output file", outFile)
|
||||||
|
|
||||||
|
Log.Noticef("writing to output file: %s", outFile)
|
||||||
|
err = ioutil.WriteFile(outFile, []byte(result), 0644)
|
||||||
|
if err != nil {
|
||||||
|
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