// read meta data, from meta.md,nav.md and comment.md // they are global values. func (b *Builder) readMeta(ctx *Context) { blocks, err := b.parseFile("meta.md") if err != nil { ctx.Error = err return } ctx.Meta, ctx.Navs, ctx.Authors, ctx.Comment, err = model.NewAllMeta(blocks) if err != nil { ctx.Error = err return } for _, n := range ctx.Navs { n.Link = fixSuffix(n.Link) } }
func TestParseMeta(t *testing.T) { Convey("parse meta", t, func() { bytes, err := ioutil.ReadFile("../source/meta.md") So(err, ShouldBeNil) blocks, err := p2.Parse(bytes) So(err, ShouldBeNil) Convey("check meta block", func() { So(blocks, ShouldHaveLength, 1) So(blocks[0].Type(), ShouldEqual, parser.BLOCK_INI) Convey("use meta block", func() { b, ok := blocks[0].(parser.MetaBlock) So(ok, ShouldBeTrue) So(b.Item("meta", "title"), ShouldEqual, "Pugo.Static") meta, _, _, _, err := model.NewAllMeta(blocks) So(err, ShouldBeNil) So(meta.Title, ShouldEqual, b.Item("meta", "title")) }) }) }) }