diff --git a/internal/microblog/microblog.go b/internal/microblog/microblog.go index ebdc7d7..09a6ee9 100644 --- a/internal/microblog/microblog.go +++ b/internal/microblog/microblog.go @@ -20,11 +20,12 @@ const ( sourceNostr source = "nostr" ) -var supportedSources = []source{ - sourceNostr, - // TODO: Add support for BlueSky and Mastodon - // SourceBlueSky, - // SourceMastodon, +var supportedSources = map[source]bool{ + sourceNostr: true, + sourcePleroma: false, + sourceBlueSky: false, + sourceMastodon: false, + sourcePixelfed: false, } // Post represents a single blog post @@ -46,6 +47,10 @@ type pbPost struct { Posted string `json:"posted"` } +type nostrPost struct { + Content string `json:"content"` +} + // MicroBlog manages blog posts type MicroBlog struct { pbClient *pocketbase.PocketBaseClient @@ -124,7 +129,25 @@ func (mb *MicroBlog) GetRecentPosts(limit int) ([]post, error) { return nil, fmt.Errorf("failed to decode response: %w", err) } slog.Info("Posts from pocketbase", "rawPosts", rawPosts) - return nil, fmt.Errorf("todo: %w", err) + + var filteredPosts []post + for _, p := range rawPosts { + if p.Source == SourceNostr { + var nostrPost nostrPost + if err := json.Unmarshal(p.FullPost, &nostrPost); err != nil { + slog.Error("Problem unmarshalling nostr post", "error", err) + continue + } + filteredPosts = append(filteredPosts, post{ + ID: p.ID, + RemoteID: p.RemoteID, + Content: nostrPost.Content, + Timestamp: time.Now(), + }) + continue + } + } + return filteredPosts, nil } // HandleBlogRequest handles Gemini requests for the microblog diff --git a/test_pocketbase.go b/test_pocketbase.go index df5caa4..5edddf0 100644 --- a/test_pocketbase.go +++ b/test_pocketbase.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "log" + "log/slog" "gemini_site/internal/microblog" "gemini_site/internal/pocketbase" @@ -11,14 +11,13 @@ import ( func main() { pbClient := pocketbase.NewPocketBaseClient() mb := microblog.NewMicroBlog(pbClient) - res, err := mb.GetRecentPosts(2) + res, err := mb.GetRecentPosts(10) // res, err := pbClient.GetList("micro_blog_posts", 1, 10, "-posted") - fmt.Println("Getting page 1 of microblog posts") + fmt.Println("Getting page 1 of microblog posts, 10 posts") // posts, err := client.GetPosts(1) if err != nil { - log.Printf("Error getting posts: %v", err) + slog.Error("Error getting posts", "error", err) } else { - fmt.Printf("Got first page of microblog posts\n") - fmt.Printf("First post: %v\n", res) + slog.Info("Got microblog posts", "posts", res) } }