// GetAllPosts returns all posts from the storage system by name. func GetAllPosts(root string) []Post { var posts []Post for _, f := range util.ReadDir(root) { posts = append(posts, preparePost(f)) } return posts }
func TestParsePostSlugAndType(t *testing.T) { files := util.ReadDir("../fixtures/posts") file := files[0] slug, ty := ParsePostSlugAndType(file.Info.Name()) expect(t, slug, "test-post-1") expect(t, ty, "md") }
// GetPost returns a single post from the storage system by name. func GetPost(name, root string) Post { var post Post for _, f := range util.ReadDir(root) { if f.Filename == name { post = preparePost(f) break } } return post }
func TestParsePostHeadMatter(t *testing.T) { files := util.ReadDir("../fixtures/posts") file := files[0] contents, err := ioutil.ReadFile(file.Filename) if err != nil { t.Errorf("Error reading file '%v'", file.Filename) } hm, _ := ParsePostHeadMatter(contents) expect(t, hm.Title, "Test Post 1") expect(t, hm.Date, "2014-04-16 22:00:00") }