blogposts: read tags
This commit is contained in:
parent
a33d490896
commit
8228bcdce3
@ -19,9 +19,11 @@ import (
|
||||
func TestNewBlogPosts(t *testing.T) {
|
||||
const (
|
||||
firstBody = `Title: Post 1
|
||||
Description: Description 1`
|
||||
Description: Description 1
|
||||
Tags: tag1, tag2`
|
||||
secondBody = `Title: Post 2
|
||||
Description: Description 2`
|
||||
Description: Description 2
|
||||
Tags: tag1, tag2`
|
||||
)
|
||||
|
||||
fs := fstest.MapFS{
|
||||
@ -41,6 +43,7 @@ Description: Description 2`
|
||||
assertPost(t, posts[0], Post{
|
||||
Title: "Post 1",
|
||||
Description: "Description 1",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,10 @@ type Post struct {
|
||||
}
|
||||
|
||||
const (
|
||||
titleSeparator = "Title: "
|
||||
descriptionSeparator = "Description: "
|
||||
titleLine = "Title: "
|
||||
descriptionLine = "Description: "
|
||||
tagsLine = "Tags: "
|
||||
tagSeparator = ","
|
||||
)
|
||||
|
||||
func getPost(fileSystem fs.FS, fileName string) (Post, error) {
|
||||
@ -37,9 +39,19 @@ func newPost(postFile io.Reader) (Post, error) {
|
||||
return strings.TrimPrefix(scanner.Text(), tagName)
|
||||
}
|
||||
|
||||
title := readMetaLine(titleLine)
|
||||
description := readMetaLine(descriptionLine)
|
||||
tagsOneLine := readMetaLine(tagsLine)
|
||||
|
||||
tags := strings.Split(tagsOneLine, ",")
|
||||
for i, tag := range tags {
|
||||
tags[i] = strings.TrimSpace(tag)
|
||||
}
|
||||
|
||||
post := Post{
|
||||
Title: readMetaLine(titleSeparator),
|
||||
Description: readMetaLine(descriptionSeparator),
|
||||
Title: title,
|
||||
Description: description,
|
||||
Tags: tags,
|
||||
}
|
||||
return post, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user