- Timestamp:
- Sep 2, 2015, 5:35:26 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/testdata/blog/.test/index.html
r34 r35 1 <html> 2 <head> 3 <title>My blog</title> 4 <link href="styles.css" rel="stylesheet" type="text/css" /> 5 </head> 6 <body> 7 <p>Here goes list of posts</p> 8 <ul> 9 <li> 10 <a href="/posts/hello.html">First post</a> 11 </li> 12 <li> 13 <a href="/posts/update.html">Second post</a> 14 </li> 15 </ul> 16 </body> 17 </html> -
trunk/testdata/blog/about.md
r22 r35 1 1 title: About myself 2 2 date: 28-08-2015 3 --- 3 4 4 5 # {{title}} -
trunk/testdata/blog/posts/hello.md
r22 r35 1 1 title: First post 2 2 date: 28-08-2015 3 --- 3 4 4 5 # {{title}} -
trunk/testdata/blog/posts/update.md
r22 r35 1 1 title: Second post 2 2 date: 29-08-2015 3 --- 3 4 4 5 # {{title}} -
trunk/zs.go
r34 r35 17 17 "github.com/russross/blackfriday" 18 18 "github.com/yosssi/gcss" 19 "gopkg.in/yaml.v 1"19 "gopkg.in/yaml.v2" 20 20 ) 21 21 … … 116 116 v["output"] = filepath.Join(PUBDIR, v["url"]) 117 117 118 if sep := strings.Index(s, "\n\n"); sep == -1 { 118 delim := "\n---\n" 119 if sep := strings.Index(s, delim); sep == -1 { 119 120 return v, s, nil 120 121 } else { 121 122 header := s[:sep] 122 body := s[sep+len("\n\n"):] 123 body := s[sep+len(delim):] 124 123 125 vars := Vars{} 124 126 if err := yaml.Unmarshal([]byte(header), &vars); err != nil { 125 127 fmt.Println("ERROR: failed to parse header", err) 128 return nil, "", err 126 129 } else { 127 130 for key, value := range vars { 128 131 v[key] = value 132 log.Println(key, value) 129 133 } 130 134 } … … 227 231 return err 228 232 } 229 if body, err = render(body, v); err != nil {230 return err231 }232 233 233 a := amber.New() 234 234 if err := a.Parse(body); err != nil { 235 fmt.Println(body) 235 236 return err 236 237 } … … 240 241 return err 241 242 } 243 244 htmlBuf := &bytes.Buffer{} 245 if err := t.Execute(htmlBuf, v); err != nil { 246 return err 247 } 248 249 if body, err = render(string(htmlBuf.Bytes()), v); err != nil { 250 return err 251 } 252 242 253 if w == nil { 243 254 f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html"))) … … 248 259 w = f 249 260 } 250 return t.Execute(w, vars) 261 _, err = io.WriteString(w, body) 262 return err 251 263 } 252 264 -
trunk/zs_test.go
r34 r35 54 54 foo: bar 55 55 title: Hello, world! 56 56 --- 57 57 Some content in markdown 58 58 `: Vars{ … … 64 64 "__content": "Some content in markdown\n", 65 65 }, 66 `url: "example.com/foo.html" 67 66 ` 67 url: "example.com/foo.html" 68 --- 68 69 Hello 69 70 `: Vars{
Note:
See TracChangeset
for help on using the changeset viewer.