aboutsummaryrefslogtreecommitdiffstats
path: root/internal/store/posts.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/store/posts.go')
-rw-r--r--internal/store/posts.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/store/posts.go b/internal/store/posts.go
index 06bea7f..9f3c4f9 100644
--- a/internal/store/posts.go
+++ b/internal/store/posts.go
@@ -66,6 +66,33 @@ func (s *Store) PublishedPosts(ctx context.Context, pageID int64, limit, offset
return posts, total, err
}
+// PostRef is the light-weight row the archive module lists.
+type PostRef struct {
+ Title string
+ Slug string
+ PageSlug string
+ CreatedAt time.Time
+}
+
+// PublishedPostIndex lists every published post of a blog, newest first, without bodies.
+func (s *Store) PublishedPostIndex(ctx context.Context, blogID int64) ([]PostRef, error) {
+ rows, err := s.db.Query(ctx, `SELECT p.title, p.slug, g.slug, p.created_at FROM posts p JOIN pages g ON g.id=p.page_id
+ WHERE g.blog_id=$1 AND p.published ORDER BY p.created_at DESC, p.id DESC`, blogID)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var out []PostRef
+ for rows.Next() {
+ var r PostRef
+ if err := rows.Scan(&r.Title, &r.Slug, &r.PageSlug, &r.CreatedAt); err != nil {
+ return nil, err
+ }
+ out = append(out, r)
+ }
+ return out, rows.Err()
+}
+
// RecentPublishedPosts returns the newest published posts across a whole blog (for feeds).
func (s *Store) RecentPublishedPosts(ctx context.Context, blogID int64, limit int) ([]Post, error) {
return s.collectPosts(ctx, `SELECT `+postCols+` FROM posts p JOIN pages g ON g.id=p.page_id