From 7d408f5b7e22cf4eb94020c68cc7c84f023e4af2 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Tue, 12 Feb 2019 19:36:11 +0100 Subject: [PATCH] partials handling --- example/templates/index.html | 33 +++----------------------- example/templates/mitBild.html | 32 +++---------------------- example/templates/partials/footer.html | 8 +++++++ example/templates/partials/header.html | 9 +++++++ example/templates/partials/meta.html | 13 ++++++++++ main.go | 27 +++++++++++++++++++++ 6 files changed, 63 insertions(+), 59 deletions(-) create mode 100644 example/templates/partials/footer.html create mode 100644 example/templates/partials/header.html create mode 100644 example/templates/partials/meta.html diff --git a/example/templates/index.html b/example/templates/index.html index 59ba59f..85aded1 100644 --- a/example/templates/index.html +++ b/example/templates/index.html @@ -1,39 +1,12 @@ - - {{ Meta.Title }} - - - - + {{> meta.html }} -
-
-
main Level 1
- -
+ {{> header.html }}
{{{ Body }}}
- + {{> footer.html }} \ No newline at end of file diff --git a/example/templates/mitBild.html b/example/templates/mitBild.html index 7f52141..dacb69d 100644 --- a/example/templates/mitBild.html +++ b/example/templates/mitBild.html @@ -1,26 +1,7 @@ - - {{ Meta.Title }} - - - - + {{> meta.html }} -
-
main Level 1
- -
+ {{> header.html }}
{{{ Body }}} @@ -30,13 +11,6 @@
- + {{> footer.html }} \ No newline at end of file diff --git a/example/templates/partials/footer.html b/example/templates/partials/footer.html new file mode 100644 index 0000000..bf137af --- /dev/null +++ b/example/templates/partials/footer.html @@ -0,0 +1,8 @@ + diff --git a/example/templates/partials/header.html b/example/templates/partials/header.html new file mode 100644 index 0000000..148710c --- /dev/null +++ b/example/templates/partials/header.html @@ -0,0 +1,9 @@ +
+
+
main Level 1
+ +
diff --git a/example/templates/partials/meta.html b/example/templates/partials/meta.html new file mode 100644 index 0000000..a601114 --- /dev/null +++ b/example/templates/partials/meta.html @@ -0,0 +1,13 @@ + + {{ Meta.Title }} + + + + diff --git a/main.go b/main.go index 3e28fae..cb4a021 100644 --- a/main.go +++ b/main.go @@ -573,6 +573,33 @@ func main() { //spew.Dump(navMap) + partialsPath := *inDir + "/templates/partials" + if d, err := os.Stat(partialsPath); !os.IsNotExist(err) { + if d != nil && d.IsDir() { + log.Debugf("register template partials from '%s'", partialsPath) + if entries, err := ioutil.ReadDir(partialsPath); err == nil { + for _, f := range entries { + if !f.IsDir() { + pFile := partialsPath + "/" + f.Name() + log.Noticef("registering partial: %s", pFile) + pContent, err := ioutil.ReadFile(pFile) + if err != nil { + log.Panicf("could not read partial '%s': %s", pFile, err) + } + raymond.RegisterPartial(f.Name(), string(pContent)) + } + } + } else { + log.Panicf("could not read from partials directory '%s': %s", partialsPath, err) + } + } else if err == nil { + log.Panicf("template partials directory '%s' is not a directory", partialsPath) + } else { + log.Panicf("unknown error on partials directory '%s': %s", partialsPath, err) + } + + } + processContent(contentConfig) processAssets()