fixed yaml
This commit is contained in:
parent
6150fd377b
commit
35561aa97f
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -25,3 +25,9 @@
|
||||
[submodule "vendor/github.com/davecgh/go-spew"]
|
||||
path = vendor/github.com/davecgh/go-spew
|
||||
url = https://github.com/davecgh/go-spew
|
||||
[submodule "vendor/github.com/aymerick/raymond"]
|
||||
path = vendor/github.com/aymerick/raymond
|
||||
url = https://github.com/aymerick/raymond
|
||||
[submodule "vendor/github.com/imdario/mergo"]
|
||||
path = vendor/github.com/imdario/mergo
|
||||
url = https://github.com/imdario/mergo
|
||||
|
@ -1,7 +1,7 @@
|
||||
webserver:
|
||||
type: "apache" # generates .htaccess
|
||||
Webserver:
|
||||
Type: "apache" # generates .htaccess
|
||||
|
||||
assets:
|
||||
path: "/assets"
|
||||
deployType: "symlink" # symlink, copy or move
|
||||
fixTemplate: True # change path in html templates, no <base> used
|
||||
Assets:
|
||||
Path: "/assets"
|
||||
DeployType: "symlink" # symlink, copy or move
|
||||
FixTemplate: True # change path in html templates, no <base> used
|
||||
|
@ -1,20 +1,23 @@
|
||||
goTo: "/de/main/home"
|
||||
This:
|
||||
GoTo: "/de/main/home"
|
||||
|
||||
index:
|
||||
inputFile: "README.md"
|
||||
outputFile: "index.html"
|
||||
Index:
|
||||
InputFile: "README.md"
|
||||
OutputFile: "index.html"
|
||||
|
||||
meta:
|
||||
title: "global title"
|
||||
description: "global description of example website"
|
||||
keywords: "global keywords"
|
||||
Meta:
|
||||
Title: "global title"
|
||||
Description: "global description of example website"
|
||||
Keywords: "global keywords"
|
||||
|
||||
path:
|
||||
strip: "^[0-9]*_(.*)"
|
||||
ignoreForNav: "^_"
|
||||
Template: index.html
|
||||
|
||||
filename:
|
||||
strip: "(.*).md$"
|
||||
ignore: "^_"
|
||||
outputExtension: "html"
|
||||
Path:
|
||||
Strip: "^[0-9]*_(.*)"
|
||||
IgnoreForNav: "^_"
|
||||
|
||||
Filename:
|
||||
Strip: "(.*).md$"
|
||||
Ignore: "^_"
|
||||
OutputExtension: "html"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Home
|
||||
Meta:
|
||||
Title: Home
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Leistungen
|
||||
Meta:
|
||||
Title: Leistungen
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Adresse
|
||||
Meta:
|
||||
Title: Adresse
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Anfahrt
|
||||
Meta:
|
||||
Title: Anfahrt
|
||||
|
||||
---
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
goTo: adresse/
|
||||
This:
|
||||
GoTo: adresse/
|
@ -1 +1 @@
|
||||
goTo: /de/service/impressum/
|
||||
GoTo: /de/service/impressum/
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Datenschutz
|
||||
Meta:
|
||||
Title: Datenschutz
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: AGB's
|
||||
Meta:
|
||||
Title: AGB's
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Impressum
|
||||
Meta:
|
||||
Title: Impressum
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Home
|
||||
Meta:
|
||||
Title: Home
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Services
|
||||
Meta:
|
||||
Title: Services
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Contact
|
||||
Meta:
|
||||
Title: Contact
|
||||
|
||||
---
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
goTo: /en/service/imprint/
|
||||
This:
|
||||
GoTo: /en/service/imprint/
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Terms
|
||||
Meta:
|
||||
Title: Terms
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
navname: Imprint
|
||||
Meta:
|
||||
Title: Imprint
|
||||
|
||||
---
|
||||
|
||||
|
8
example/templates/index.html
Normal file
8
example/templates/index.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<meta>
|
||||
<title>{{ Meta.Title }}</title>
|
||||
</meta>
|
||||
<body>
|
||||
{{{ Body }}}
|
||||
</body>
|
||||
</html>
|
96
main.go
96
main.go
@ -8,7 +8,9 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/aymerick/raymond"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/op/go-logging"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
@ -19,47 +21,53 @@ var log = logging.MustGetLogger("myLogger")
|
||||
var inDir *string
|
||||
var outDir *string
|
||||
|
||||
var templateCache = make(map[string]*raymond.Template)
|
||||
|
||||
// GlobalConfig is config which is used only once in root dir
|
||||
type GlobalConfig struct {
|
||||
Webserver struct {
|
||||
Type *string `yaml:"type"`
|
||||
} `yaml:"webserver"`
|
||||
Type *string `yaml:"Type"`
|
||||
} `yaml:"Webserver"`
|
||||
|
||||
Assets struct {
|
||||
Path *string `yaml:"path"`
|
||||
DeployType *string `yaml:"deployType"`
|
||||
FixTemplate *bool `yaml:"fixTemplate"`
|
||||
} `yaml:"assets"`
|
||||
Path *string `yaml:"Path"`
|
||||
DeployType *string `yaml:"DeployType"`
|
||||
FixTemplate *bool `yaml:"FixTemplate"`
|
||||
} `yaml:"Assets"`
|
||||
}
|
||||
|
||||
var globalConfig = new(GlobalConfig)
|
||||
|
||||
// PathConfig of subdir
|
||||
type PathConfig struct {
|
||||
Navname *string `yaml:"navname"`
|
||||
GoTo *string `yaml:"goTo"`
|
||||
This struct {
|
||||
Navname *string `yaml:"Navname"`
|
||||
GoTo *string `yaml:"GoTo"`
|
||||
} `yaml:"This"`
|
||||
|
||||
Template *string `yaml:"Template"`
|
||||
|
||||
Index struct {
|
||||
InputFile *string `yaml:"inputFile"`
|
||||
OutputFile *string `yaml:"outputFile"`
|
||||
} `yaml:"index"`
|
||||
InputFile *string `yaml:"InputFile"`
|
||||
OutputFile *string `yaml:"OutputFile"`
|
||||
} `yaml:"Index"`
|
||||
|
||||
Meta struct {
|
||||
Title *string `yaml:"title"`
|
||||
Description *string `yaml:"description"`
|
||||
Keywords *string `yaml:"keywords"`
|
||||
} `yaml:"meta"`
|
||||
Title *string `yaml:"Title"`
|
||||
Description *string `yaml:"Description"`
|
||||
Keywords *string `yaml:"Keywords"`
|
||||
} `yaml:"Meta"`
|
||||
|
||||
Path struct {
|
||||
Strip *string `yaml:"strip"`
|
||||
IgnoreForNav *string `yaml:"ignoreForNav"`
|
||||
} `yaml:"path"`
|
||||
Strip *string `yaml:"Strip"`
|
||||
IgnoreForNav *string `yaml:"IgnoreForNav"`
|
||||
} `yaml:"Path"`
|
||||
|
||||
Filename struct {
|
||||
Strip *string `yaml:"strip"`
|
||||
Ignore *string `yaml:"ignore"`
|
||||
OutputExtension *string `yaml:"outputExtension"`
|
||||
} `yaml:"filename"`
|
||||
Strip *string `yaml:"Strip"`
|
||||
Ignore *string `yaml:"Ignore"`
|
||||
OutputExtension *string `yaml:"OutputExtension"`
|
||||
} `yaml:"Filename"`
|
||||
}
|
||||
|
||||
// PathConfigTree is complete config tree of content dir
|
||||
@ -74,7 +82,15 @@ type PathConfigTree struct {
|
||||
}
|
||||
|
||||
func mergeConfig(mergeInto *PathConfig, mergeFrom *PathConfig) {
|
||||
// goto is individual, so no merging here
|
||||
// navname, goto are individual, so no merging here
|
||||
|
||||
if mergeInto.Template == nil || *mergeInto.Template == "" { // always require a template
|
||||
mergeInto.Template = mergeFrom.Template
|
||||
}
|
||||
|
||||
if mergeInto.Index.InputFile == nil {
|
||||
mergeInto.Index.InputFile = mergeFrom.Index.InputFile
|
||||
}
|
||||
|
||||
if mergeInto.Index.InputFile == nil {
|
||||
mergeInto.Index.InputFile = mergeFrom.Index.InputFile
|
||||
@ -136,7 +152,9 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig,
|
||||
if _, err = os.Stat(configFile); os.IsNotExist(err) {
|
||||
log.Debug("no config.yml found in this directory, using upper configs")
|
||||
newConfig = conf
|
||||
|
||||
// remove this
|
||||
newConfig.This.GoTo = nil
|
||||
newConfig.This.Navname = nil
|
||||
} else {
|
||||
log.Debug("reading config...")
|
||||
data, err := ioutil.ReadFile(configFile)
|
||||
@ -242,9 +260,6 @@ func processContent(conf *PathConfigTree) {
|
||||
|
||||
log.Debug("merging config with upper config")
|
||||
mergeConfig(newConfig, conf.Config)
|
||||
if newConfig.GoTo == nil { // goto is also valid in header
|
||||
newConfig.GoTo = conf.Config.GoTo
|
||||
}
|
||||
log.Debug(spew.Sdump(newConfig))
|
||||
|
||||
input = regex.ReplaceAll(input, []byte(""))
|
||||
@ -296,8 +311,31 @@ func processContent(conf *PathConfigTree) {
|
||||
//html := blackfriday.Run(input, blackfriday.WithRenderer(bfchroma.NewRenderer()))
|
||||
html := blackfriday.Run(input)
|
||||
|
||||
log.Debugf("rendering template '%s' for '%s'", *newConfig.Template, outFile)
|
||||
templateFile := *inDir + "/templates/" + *newConfig.Template
|
||||
template := templateCache[templateFile]
|
||||
if template == nil {
|
||||
var err error
|
||||
if template, err = raymond.ParseFile(templateFile); err != nil {
|
||||
log.Panicf("could not parse template '%s': %s", templateFile, err)
|
||||
} else {
|
||||
templateCache[templateFile] = template
|
||||
}
|
||||
}
|
||||
|
||||
// read yaml header as data for template
|
||||
ctx := make(map[string]interface{})
|
||||
mergo.Map(&ctx, newConfig)
|
||||
ctx["Body"] = string(html)
|
||||
//log.Warning(spew.Sdump(ctx))
|
||||
|
||||
result, err := template.Exec(ctx)
|
||||
if err != nil {
|
||||
log.Panicf("could not execute template '%s' for input file '%s': %s", templateFile, inFile, err)
|
||||
}
|
||||
|
||||
log.Noticef("writing to output file: %s", outFile)
|
||||
err := ioutil.WriteFile(outFile, html, 0644)
|
||||
err = ioutil.WriteFile(outFile, []byte(result), 0644)
|
||||
if err != nil {
|
||||
log.Panicf("could not write to output file '%s': %s", outFile, err)
|
||||
}
|
||||
@ -403,6 +441,7 @@ func main() {
|
||||
|
||||
log.Debugf("reading input directory %s", *inDir)
|
||||
|
||||
defaultTemplate := "index.html"
|
||||
defaultInputFile := "README.md"
|
||||
defaultOutputFile := "index.html"
|
||||
defaultPathStrip := "^[0-9]*_(.*)"
|
||||
@ -412,6 +451,7 @@ func main() {
|
||||
defaultFilenameOutputExtension := "html"
|
||||
|
||||
defaultPathConfig := new(PathConfig)
|
||||
defaultPathConfig.Template = &defaultTemplate
|
||||
defaultPathConfig.Index.InputFile = &defaultInputFile
|
||||
defaultPathConfig.Index.OutputFile = &defaultOutputFile
|
||||
defaultPathConfig.Path.Strip = &defaultPathStrip
|
||||
|
1
vendor/github.com/aymerick/raymond
generated
vendored
Submodule
1
vendor/github.com/aymerick/raymond
generated
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit b565731e1464263de0bda75f2e45d97b54b60110
|
1
vendor/github.com/imdario/mergo
generated
vendored
Submodule
1
vendor/github.com/imdario/mergo
generated
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7c29201646fa3de8506f701213473dd407f19646
|
Loading…
Reference in New Issue
Block a user