tag listing and item getting ready
Former-commit-id: f1134377a7afa6202c0f7180885912456add33fe
This commit is contained in:
37
rss/feed.go
37
rss/feed.go
@@ -23,6 +23,27 @@ type Feed struct {
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func TaggedFeeds(tag string) ([]*Feed, error) {
|
||||
db := config.Values().DB
|
||||
feedNames, err := db.List([]string{nsFeeds})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results := []*Feed{}
|
||||
for _, feedName := range feedNames {
|
||||
f := newFeed(feedName)
|
||||
if err := f.Load(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range f.Tags {
|
||||
if f.Tags[i] == tag {
|
||||
results = append(results, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func newFeed(key string) *Feed {
|
||||
return &Feed{
|
||||
Key: key,
|
||||
@@ -102,6 +123,22 @@ func (f *Feed) save() error {
|
||||
return db.Set(f.Key, b, nsFeeds)
|
||||
}
|
||||
|
||||
func (f *Feed) Items(limit int) ([]*Item, error) {
|
||||
keys, err := f.List(limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results := []*Item{}
|
||||
for j := range keys {
|
||||
i := &Item{}
|
||||
if err := i.Load(keys[j], f.Key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results = append(results, i)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (f *Feed) List(limit int) ([]string, error) {
|
||||
keys, err := config.Values().DB.List([]string{nsItems, f.Key})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user