Mercurial > yakumo_izuru > aya
changeset 34:ed40ca93db1e draft
added explicit yaml separator, fixed amber compilation sequence
author | zaitsev.serge |
---|---|
date | Wed, 02 Sep 2015 17:35:26 +0000 |
parents | e3c902a7380d |
children | 0498cb3afc1d |
files | testdata/blog/.test/index.html testdata/blog/about.md testdata/blog/posts/hello.md testdata/blog/posts/update.md zs.go zs_test.go |
diffstat | 6 files changed, 44 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/testdata/blog/.test/index.html Wed Sep 02 17:05:09 2015 +0000 +++ b/testdata/blog/.test/index.html Wed Sep 02 17:35:26 2015 +0000 @@ -0,0 +1,17 @@ +<html> + <head> + <title>My blog</title> + <link href="styles.css" rel="stylesheet" type="text/css" /> + </head> + <body> + <p>Here goes list of posts</p> + <ul> + <li> + <a href="/posts/hello.html">First post</a> + </li> + <li> + <a href="/posts/update.html">Second post</a> + </li> + </ul> + </body> +</html>
--- a/testdata/blog/about.md Wed Sep 02 17:05:09 2015 +0000 +++ b/testdata/blog/about.md Wed Sep 02 17:35:26 2015 +0000 @@ -1,5 +1,6 @@ title: About myself date: 28-08-2015 +--- # {{title}}
--- a/testdata/blog/posts/hello.md Wed Sep 02 17:05:09 2015 +0000 +++ b/testdata/blog/posts/hello.md Wed Sep 02 17:35:26 2015 +0000 @@ -1,5 +1,6 @@ title: First post date: 28-08-2015 +--- # {{title}}
--- a/testdata/blog/posts/update.md Wed Sep 02 17:05:09 2015 +0000 +++ b/testdata/blog/posts/update.md Wed Sep 02 17:35:26 2015 +0000 @@ -1,5 +1,6 @@ title: Second post date: 29-08-2015 +--- # {{title}}
--- a/zs.go Wed Sep 02 17:05:09 2015 +0000 +++ b/zs.go Wed Sep 02 17:35:26 2015 +0000 @@ -16,7 +16,7 @@ "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 @@ 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 @@ 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 @@ 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 @@ defer f.Close() w = f } - return t.Execute(w, vars) + _, err = io.WriteString(w, body) + return err } // Compiles .gcss into .css
--- a/zs_test.go Wed Sep 02 17:05:09 2015 +0000 +++ b/zs_test.go Wed Sep 02 17:35:26 2015 +0000 @@ -53,7 +53,7 @@ ` foo: bar title: Hello, world! - +--- Some content in markdown `: Vars{ "foo": "bar", @@ -63,8 +63,9 @@ "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",