feat: daily vani
This commit is contained in:
@@ -87,6 +87,22 @@ func (r *VaniRepo) Insert(ctx context.Context, pick *model.VaniPick) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BookTitle resolves a book code to its display title (from book_meta.data.title),
|
||||
// or "" if unknown. Used to label a prose pick with its book name.
|
||||
func (r *VaniRepo) BookTitle(ctx context.Context, book string) string {
|
||||
var raw bson.M
|
||||
if err := r.mongo.Collection("book_meta").
|
||||
FindOne(ctx, bson.D{{Key: "book", Value: book}}).Decode(&raw); err != nil {
|
||||
return ""
|
||||
}
|
||||
if data, ok := raw["data"].(bson.M); ok {
|
||||
if t, ok := data["title"].(string); ok {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// --- Mongo: random candidate sampling ---
|
||||
|
||||
// excludeIDs turns hex _id strings into a $nin ObjectID array.
|
||||
|
||||
@@ -87,7 +87,7 @@ func (s *VaniService) choose(ctx context.Context, exclude map[string][]string, d
|
||||
}
|
||||
case "prose":
|
||||
if p, err := s.repo.SampleProse(ctx, exclude["prose"]); err == nil && p != nil {
|
||||
return prosePick(p, day)
|
||||
return prosePick(p, s.repo.BookTitle(ctx, p.Book), day)
|
||||
}
|
||||
case "transcript":
|
||||
if t, err := s.repo.SampleTranscript(ctx, exclude["transcript"]); err == nil && t != nil {
|
||||
@@ -120,7 +120,7 @@ func versePick(v *repository.VerseDoc, day time.Time) *model.VaniPick {
|
||||
}
|
||||
}
|
||||
|
||||
func prosePick(p *repository.ProseChapterDoc, day time.Time) *model.VaniPick {
|
||||
func prosePick(p *repository.ProseChapterDoc, bookTitle string, day time.Time) *model.VaniPick {
|
||||
first := ""
|
||||
if len(p.Paragraphs) > 0 {
|
||||
first = p.Paragraphs[0]
|
||||
@@ -130,11 +130,12 @@ func prosePick(p *repository.ProseChapterDoc, day time.Time) *model.VaniPick {
|
||||
Kind: "prose",
|
||||
RefID: "prose:" + p.ID.Hex(),
|
||||
Payload: model.VaniPayload{
|
||||
Kind: "prose",
|
||||
Label: "Chapter",
|
||||
Title: p.Title,
|
||||
Subtitle: excerpt(first, 140),
|
||||
Href: proseURL(p.Book, p.Volume, p.Type, p.Slug),
|
||||
Kind: "prose",
|
||||
Label: "Chapter",
|
||||
Title: p.Title,
|
||||
Subtitle: excerpt(first, 140),
|
||||
Href: proseURL(p.Book, p.Volume, p.Type, p.Slug),
|
||||
BookTitle: bookTitle,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user