diff --git a/src/components/LatestArticles.tsx b/src/components/LatestArticles.tsx new file mode 100644 index 0000000..2e2f27b --- /dev/null +++ b/src/components/LatestArticles.tsx @@ -0,0 +1,99 @@ +import { Link } from 'react-router-dom'; +import { nip19 } from 'nostr-tools'; +import type { NostrEvent } from '@nostrify/nostrify'; +import { Card, CardContent, CardHeader } from '@/components/ui/card'; +import { Badge } from '@/components/ui/badge'; +import { Calendar, Newspaper } from 'lucide-react'; + +interface LatestArticlesProps { + posts: NostrEvent[]; +} + +export function LatestArticles({ posts }: LatestArticlesProps) { + return ( +
+ {/* Section Header */} +
+ +
+

Latest Articles

+

+ Discover the most recent stories from the community +

+
+
+ + {/* Posts Grid */} +
+ {posts.map((post) => { + const title = post.tags.find(([name]) => name === 'title')?.[1] || 'Untitled'; + const summary = post.tags.find(([name]) => name === 'summary')?.[1]; + const image = post.tags.find(([name]) => name === 'image')?.[1]; + const publishedAt = post.tags.find(([name]) => name === 'published_at')?.[1]; + const identifier = post.tags.find(([name]) => name === 'd')?.[1] || ''; + const hashtags = post.tags + .filter(([name]) => name === 't') + .map(([, value]) => value) + .slice(0, 3); + + const date = publishedAt + ? new Date(parseInt(publishedAt) * 1000) + : new Date(post.created_at * 1000); + + const naddr = nip19.naddrEncode({ + kind: 30023, + pubkey: post.pubkey, + identifier, + }); + + return ( + + + {image && ( +
+ {title} +
+ )} + +

+ {title} +

+ {summary && ( +

+ {summary} +

+ )} +
+ +
+ + +
+ {hashtags.length > 0 && ( +
+ {hashtags.map((tag) => ( + + #{tag} + + ))} +
+ )} +
+
+ + ); + })} +
+
+ ); +} diff --git a/src/pages/BlogHomePage.tsx b/src/pages/BlogHomePage.tsx index ad69dae..a4ba561 100644 --- a/src/pages/BlogHomePage.tsx +++ b/src/pages/BlogHomePage.tsx @@ -1,12 +1,9 @@ -import { Link } from 'react-router-dom'; -import { nip19 } from 'nostr-tools'; import { useBlogPosts } from '@/hooks/useBlogPosts'; import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; -import { Badge } from '@/components/ui/badge'; -import { Calendar } from 'lucide-react'; import { RelaySelector } from '@/components/RelaySelector'; import { SearchBar } from '@/components/SearchBar'; +import { LatestArticles } from '@/components/LatestArticles'; export default function BlogHomePage() { const { data: posts, isLoading } = useBlogPosts(); @@ -70,77 +67,8 @@ export default function BlogHomePage() { - {/* Posts grid */} -
- {posts.map((post) => { - const title = post.tags.find(([name]) => name === 'title')?.[1] || 'Untitled'; - const summary = post.tags.find(([name]) => name === 'summary')?.[1]; - const image = post.tags.find(([name]) => name === 'image')?.[1]; - const publishedAt = post.tags.find(([name]) => name === 'published_at')?.[1]; - const identifier = post.tags.find(([name]) => name === 'd')?.[1] || ''; - const hashtags = post.tags - .filter(([name]) => name === 't') - .map(([, value]) => value) - .slice(0, 3); - - const date = publishedAt - ? new Date(parseInt(publishedAt) * 1000) - : new Date(post.created_at * 1000); - - const naddr = nip19.naddrEncode({ - kind: 30023, - pubkey: post.pubkey, - identifier, - }); - - return ( - - - {image && ( -
- {title} -
- )} - -

- {title} -

- {summary && ( -

- {summary} -

- )} -
- -
- - -
- {hashtags.length > 0 && ( -
- {hashtags.map((tag) => ( - - #{tag} - - ))} -
- )} -
-
- - ); - })} -
+ {/* Latest Articles */} + );