2024-09-23 21:09:10 +00:00
|
|
|
package blogposts
|
|
|
|
|
2024-09-24 18:57:28 +00:00
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
)
|
2024-09-23 21:09:10 +00:00
|
|
|
|
2024-09-24 18:57:28 +00:00
|
|
|
func NewPostsFromFS(fileSystem fs.FS) ([]Post, error) {
|
|
|
|
dir, err := fs.ReadDir(fileSystem, ".")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var posts []Post
|
|
|
|
for _, f := range dir {
|
2024-09-24 19:04:06 +00:00
|
|
|
post, err := getPost(fileSystem, f.Name())
|
2024-09-24 18:57:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
posts = append(posts, post)
|
|
|
|
}
|
|
|
|
return posts, nil
|
|
|
|
}
|