diff --git a/testdata/blog/.test/index.html b/testdata/blog/.test/index.html
index e69de29..30af02e 100644
--- a/testdata/blog/.test/index.html
+++ b/testdata/blog/.test/index.html
@@ -0,0 +1,17 @@
+
+
+ My blog
+
+
+
+ Here goes list of posts
+
+
+
diff --git a/testdata/blog/about.md b/testdata/blog/about.md
index 93c2a0d..858efe8 100644
--- a/testdata/blog/about.md
+++ b/testdata/blog/about.md
@@ -1,5 +1,6 @@
title: About myself
date: 28-08-2015
+---
# {{title}}
diff --git a/testdata/blog/posts/hello.md b/testdata/blog/posts/hello.md
index 99bfa38..f4d9230 100644
--- a/testdata/blog/posts/hello.md
+++ b/testdata/blog/posts/hello.md
@@ -1,5 +1,6 @@
title: First post
date: 28-08-2015
+---
# {{title}}
diff --git a/testdata/blog/posts/update.md b/testdata/blog/posts/update.md
index 58b25ea..1d04487 100644
--- a/testdata/blog/posts/update.md
+++ b/testdata/blog/posts/update.md
@@ -1,5 +1,6 @@
title: Second post
date: 29-08-2015
+---
# {{title}}
diff --git a/zs.go b/zs.go
index 8071ca9..f5e4836 100644
--- a/zs.go
+++ b/zs.go
@@ -16,7 +16,7 @@ import (
"github.com/eknkc/amber"
"github.com/russross/blackfriday"
"github.com/yosssi/gcss"
- "gopkg.in/yaml.v1"
+ "gopkg.in/yaml.v2"
)
const (
@@ -115,17 +115,21 @@ func getVars(path string, globals Vars) (Vars, string, error) {
v["url"] = path[:len(path)-len(filepath.Ext(path))] + ".html"
v["output"] = filepath.Join(PUBDIR, v["url"])
- if sep := strings.Index(s, "\n\n"); sep == -1 {
+ delim := "\n---\n"
+ if sep := strings.Index(s, delim); sep == -1 {
return v, s, nil
} else {
header := s[:sep]
- body := s[sep+len("\n\n"):]
+ body := s[sep+len(delim):]
+
vars := Vars{}
if err := yaml.Unmarshal([]byte(header), &vars); err != nil {
fmt.Println("ERROR: failed to parse header", err)
+ return nil, "", err
} else {
for key, value := range vars {
v[key] = value
+ log.Println(key, value)
}
}
if strings.HasPrefix(v["url"], "./") {
@@ -226,12 +230,9 @@ func buildAmber(path string, w io.Writer, vars Vars) error {
if err != nil {
return err
}
- if body, err = render(body, v); err != nil {
- return err
- }
-
a := amber.New()
if err := a.Parse(body); err != nil {
+ fmt.Println(body)
return err
}
@@ -239,6 +240,16 @@ func buildAmber(path string, w io.Writer, vars Vars) error {
if err != nil {
return err
}
+
+ htmlBuf := &bytes.Buffer{}
+ if err := t.Execute(htmlBuf, v); err != nil {
+ return err
+ }
+
+ if body, err = render(string(htmlBuf.Bytes()), v); err != nil {
+ return err
+ }
+
if w == nil {
f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html")))
if err != nil {
@@ -247,7 +258,8 @@ func buildAmber(path string, w io.Writer, vars Vars) error {
defer f.Close()
w = f
}
- return t.Execute(w, vars)
+ _, err = io.WriteString(w, body)
+ return err
}
// Compiles .gcss into .css
diff --git a/zs_test.go b/zs_test.go
index a74d19a..ada7564 100644
--- a/zs_test.go
+++ b/zs_test.go
@@ -53,7 +53,7 @@ func TestVars(t *testing.T) {
`
foo: bar
title: Hello, world!
-
+---
Some content in markdown
`: Vars{
"foo": "bar",
@@ -63,8 +63,9 @@ Some content in markdown
"output": filepath.Join(PUBDIR, "test.html"),
"__content": "Some content in markdown\n",
},
- `url: "example.com/foo.html"
-
+ `
+url: "example.com/foo.html"
+---
Hello
`: Vars{
"url": "example.com/foo.html",