allow definition of primary feed/list

This commit is contained in:
Niko Abeler 2022-12-01 19:15:16 +01:00
parent 58cd92a4b4
commit 18a593d2b1
1 changed files with 17 additions and 19 deletions

36
user.go
View File

@ -20,13 +20,14 @@ type User struct {
} }
type UserConfig struct { type UserConfig struct {
Title string `yaml:"title"` Title string `yaml:"title"`
SubTitle string `yaml:"subtitle"` SubTitle string `yaml:"subtitle"`
HeaderColor string `yaml:"header_color"` HeaderColor string `yaml:"header_color"`
AuthorName string `yaml:"author_name"` AuthorName string `yaml:"author_name"`
Me []UserMe `yaml:"me"` Me []UserMe `yaml:"me"`
PassworHash string `yaml:"password_hash"` PassworHash string `yaml:"password_hash"`
Lists []PostList `yaml:"lists"` Lists []PostList `yaml:"lists"`
PrimaryListInclude []string `yaml:"primary_list_include"`
} }
type PostList struct { type PostList struct {
@ -240,19 +241,16 @@ func (user User) PublishedPosts() ([]*Post, error) {
} }
func (user User) PrimaryFeedPosts() ([]*Post, error) { func (user User) PrimaryFeedPosts() ([]*Post, error) {
posts, _ := user.PublishedPosts() config := user.Config()
include := config.PrimaryListInclude
// remove non-primary feed posts if len(include) == 0 {
n := 0 include = []string{"article", "reply"} // default before addition of this option
for _, post := range posts {
meta := post.Meta()
if meta.Type == "article" || meta.Type == "reply" {
posts[n] = post
n++
}
} }
posts = posts[:n] return user.GetPostsOfList(PostList{
return posts, nil Id: "",
Title: "",
Include: include,
})
} }
func (user User) GetPostsOfList(list PostList) ([]*Post, error) { func (user User) GetPostsOfList(list PostList) ([]*Post, error) {