diff --git a/config/tree.go b/config/tree.go index dff0376..f658273 100644 --- a/config/tree.go +++ b/config/tree.go @@ -55,13 +55,14 @@ type PathConfig struct { Filename *FilenameConfig `yaml:"Filename"` Markdown *MarkdownConfig `yaml:"Markdown"` - Data interface{} `yaml:"Data"` + Data map[string]interface{} `yaml:"Data"` } // PathConfigTree is complete config tree of content dir type PathConfigTree struct { InputPath string OutputPath string + Hidden bool // for collections which are not part of the navigation InputFiles []string OtherFiles []string diff --git a/helper/content.go b/helper/content.go index fc6c394..c74d4a7 100644 --- a/helper/content.go +++ b/helper/content.go @@ -164,14 +164,20 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] } for _, file := range conf.InputFiles { - inFile := conf.InputPath + "/" + file - Log.Debugf("reading file: %s", inFile) + var input []byte + inFile := "InputString" - input, err := ioutil.ReadFile(inFile) - if err != nil { - Log.Panicf("could not read '%s':%s", inFile, err) + if file != "" { + inFile = conf.InputPath + "/" + file + 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) @@ -179,7 +185,7 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] yamlData := regex.Find(input) if string(yamlData) != "" { Log.Debugf("found yaml header in '%s', merging config", inFile) - err = yaml.Unmarshal(yamlData, newConfig) + err := yaml.Unmarshal(yamlData, newConfig) if err != nil { 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 } - if indexInputFile != nil && *indexInputFile == file && indexOutputFile != nil && *indexOutputFile != "" { + if indexInputFile != nil && + *indexInputFile == file && + indexOutputFile != nil && + *indexOutputFile != "" { outputFilename = *indexOutputFile } else { if stripRegex != nil && *stripRegex != "" { @@ -336,7 +345,9 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L] } } - for _, el := range conf.Sub { - ProcessContent(rootConf, el) + i := 0 + for i < len(conf.Sub) { + ProcessContent(rootConf, conf.Sub[i]) + i++ } } diff --git a/helper/navigation.go b/helper/navigation.go index 8e8b6fe..f331afb 100644 --- a/helper/navigation.go +++ b/helper/navigation.go @@ -23,6 +23,10 @@ type NavElement struct { func BuildNavigation(conf *config.PathConfigTree, curNavMap *map[string]*NavElement, curNavSlice *[]*NavElement, navActive *[]*NavElement, activeNav string) { for _, el := range conf.Sub { + if el.Hidden { + continue // ignore hidden nav points from collections + } + var ignNav *string if p := el.Config.Path; p != nil { ignNav = p.IgnoreForNav diff --git a/helper/template_functions.go b/helper/template_functions.go index ebd6236..3f33e27 100644 --- a/helper/template_functions.go +++ b/helper/template_functions.go @@ -4,14 +4,11 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" - "path" "strings" "gitbase.de/apairon/mark2web/config" "github.com/davecgh/go-spew/spew" - "github.com/extemporalgenome/slug" "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 -func RenderFn(templateFilename, outDir, subCtxName, ctx *pongo2.Value) *pongo2.Value { - oDirSlug := slug.Slug(outDir.String()) - navPath := path.Clean((*currentContext)["CurrentPath"].(string) + "/" + oDirSlug) - outputPath := path.Clean(currentTreeNodeConfig.OutputPath + "/" + oDirSlug) - CreateDirectory(outputPath) - - newContext := make(map[string]interface{}) - if err := config.Merge(&newContext, *currentContext); err != nil { - Log.Panicf("unable to merge context") +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() + } } - newContext[subCtxName.String()] = ctx - 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 - oldContext := currentContext - oldNodeConfig := currentTreeNodeConfig - result, err := RenderTemplate( - templateFilename.String(), + fillNodeConfig( newNodeConfig, + currentTreeNodeConfig.InputPath, + currentTreeNodeConfig.OutputPath, + outDir.String(), currentPathConfig, - &newContext, ) - if err != nil { - panic(err) + if newNodeConfig.Config.Data == nil { + newNodeConfig.Config.Data = make(map[string]interface{}) } - 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 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() - if indexOutputFile != nil && *indexOutputFile != "" { - outputFilename = *indexOutputFile + // 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 + } } - - outFile := 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) + 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()) + 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) } diff --git a/website/project-files/css/main.css b/website/project-files/css/main.css index db90f87..839bf24 100755 --- a/website/project-files/css/main.css +++ b/website/project-files/css/main.css @@ -65,6 +65,7 @@ hr {height:1px; background:none; border-bottom:dotted 1px #666; margin-bottom:20 .btn { padding:8px 15px; background:#464645; + border: 1px solid #fff; color:#FFF; transition:all 0.3s; text-transform:none; diff --git a/website/templates/base_blog.html b/website/templates/base_blog.html index ef21eea..3ddbcb3 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, "details", e) }} + {{ fnRender("base_blog_details.html", e.title, e) }} {% endif %} {% endfor %} {% endblock part0 %} @@ -27,7 +27,7 @@ {{ e.teaser|markdown }} {% if e.body %} mehr lesen - {{ fnRender("base_blog_details.html", e.title, "details", e) }} + {{ fnRender("base_blog_details.html", e.title, e) }} {% endif %} {% endfor %} {% endblock part1 %} diff --git a/website/templates/base_blog_details.html b/website/templates/base_blog_details.html index ee0c782..6e5f2f2 100644 --- a/website/templates/base_blog_details.html +++ b/website/templates/base_blog_details.html @@ -1,10 +1,10 @@ {% extends 'base.html' %} {% block part0 %} -

{{ details.title }}

- {{ details.teaser|markdown }} +

{{ Data.title }}

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