-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlog.tsx
More file actions
250 lines (227 loc) · 9.29 KB
/
Blog.tsx
File metadata and controls
250 lines (227 loc) · 9.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import {
Card,
CardContent,
} from "./ui/card";
import { Badge } from "./ui/badge";
import { User, ArrowRight, Calendar, Clock } from "lucide-react";
import { Button } from "./ui/button";
import { ImageWithFallback } from "./figma/ImageWithFallback";
import { blogPosts } from "../data/blogPosts";
import { useLanguage } from "./LanguageProvider";
import { useState } from "react";
import { motion } from "framer-motion";
interface BlogProps {
onPostClick: (postId: number) => void;
}
const INITIAL_POSTS = 2;
export function Blog({ onPostClick }: BlogProps) {
const { language } = useLanguage();
const [visiblePosts, setVisiblePosts] = useState(INITIAL_POSTS);
const t = {
title: { en: "Blog", es: "Blog" },
subtitle: {
en: "Articles, tutorials and news about free software, security and open technology",
es: "Artículos, tutoriales y noticias sobre software libre, seguridad y tecnología abierta",
},
readMore: { en: "Read more", es: "Leer más" },
backToBlog: { en: "Back to Blog", es: "Volver al Blog" },
noImage: { en: "No image", es: "Sin imagen" },
loadMore: { en: "Load more articles", es: "Cargar más artículos" },
showLess: { en: "Show less", es: "Mostrar menos" },
};
const getLocalizedPost = (post: typeof blogPosts[0]) => ({
...post,
title: post.title[language] || post.title.es || "",
excerpt: post.excerpt[language] || post.excerpt.es || "",
authors: post.authors[language] || post.authors.es || [],
date: post.date[language] || post.date.es || "",
readTime: post.readTime[language] || post.readTime.es || "",
content: post.content[language] || post.content.es || "",
tags: post.tags[language] || post.tags.es || [],
});
const featuredPost = blogPosts[0];
const gridPosts = blogPosts.slice(1, 1 + visiblePosts);
const hasMore = blogPosts.length > 1 + visiblePosts;
const handleLoadMore = () => {
setVisiblePosts(blogPosts.length - 1);
};
const handleShowLess = () => {
setVisiblePosts(INITIAL_POSTS);
};
const handleViewPost = (postId: number) => {
onPostClick(postId);
};
return (
<section id="blog" className="py-20 bg-background min-h-screen">
<div className="container mx-auto px-4 sm:px-6 lg:px-8">
{/* Header */}
<div className="text-center space-y-4 mb-12 mt-8">
<h1 className="text-5xl sm:text-6xl">
{t.title[language]}
</h1>
<p className="text-xl text-muted-foreground max-w-2xl mx-auto">
{t.subtitle[language]}
</p>
</div>
{/* Featured Post */}
<Card
className="overflow-hidden hover:shadow-xl transition-all duration-300 border-border/60 max-w-5xl mx-auto mb-12"
onClick={() => handleViewPost(featuredPost.id)}
>
<div className="grid md:grid-cols-2 gap-0">
<div className="aspect-video md:aspect-auto relative overflow-hidden cursor-pointer">
<ImageWithFallback
src={featuredPost.image}
alt={getLocalizedPost(featuredPost).title}
className="w-full h-full object-cover hover:scale-105 transition-transform duration-300"
/>
<Badge className="absolute top-4 left-4 shadow-lg bg-primary">
{language === 'en' ? 'Featured' : 'Destacado'}
</Badge>
</div>
<motion.div
className="p-8 flex flex-col justify-between"
initial={{ opacity: 0, y: 16 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true }}
transition={{ delay: 0 }}
>
<div>
<h3 className="text-3xl mb-4">{getLocalizedPost(featuredPost).title}</h3>
<p className="text-muted-foreground mb-6 line-clamp-3">
{getLocalizedPost(featuredPost).excerpt}
</p>
<div className="flex items-center gap-6 text-sm text-muted-foreground mb-4">
<div className="flex items-center gap-2">
<User className="h-4 w-4" />
<span>{getLocalizedPost(featuredPost).authors[0]}</span>
</div>
<div className="flex items-center gap-2">
<Calendar className="h-4 w-4" />
<span>{getLocalizedPost(featuredPost).date}</span>
</div>
<div className="flex items-center gap-2">
<Clock className="h-4 w-4" />
<span>{getLocalizedPost(featuredPost).readTime} {language === 'en' ? 'read' : 'de lectura'}</span>
</div>
</div>
<div className="flex flex-wrap gap-2 mb-6">
{getLocalizedPost(featuredPost).tags.slice(0, 3).map((tag) => (
<Badge key={tag} variant="outline">{tag}</Badge>
))}
</div>
</div>
<Button className="gap-2 w-fit">
{language === 'en' ? 'Read Article' : 'Leer Artículo'} <ArrowRight className="h-4 w-4" />
</Button>
</motion.div>
</div>
</Card>
{/* Blog Posts Grid - Next 2 posts after featured */}
<div className="grid md:grid-cols-2 gap-8 mb-12 mt-8">
{gridPosts.map((post) => {
const localizedPost = getLocalizedPost(post);
return (
<Card
key={post.id}
className="flex flex-col overflow-hidden hover:shadow-lg transition-all duration-300 hover:scale-[1.02] group border-border/60 cursor-pointer"
onClick={() => onPostClick(post.id)}
>
{/* Image */}
<div className="aspect-video relative overflow-hidden">
{post.image ? (
<ImageWithFallback
src={post.image}
alt={localizedPost.title}
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
loading="lazy"
decoding="async"
/>
) : (
<div className="w-full h-full bg-muted flex items-center justify-center">
<span className="text-muted-foreground">
{t.noImage[language]}
</span>
</div>
)}
</div>
{/* Content */}
<CardContent className="flex flex-col flex-1 pt-2 px-4 pb-4">
{/* Title */}
<h3 className="text-xl leading-snug tracking-tight group-hover:text-primary transition-colors mb-2">
{localizedPost.title}
</h3>
{/* Excerpt */}
<p className="text-muted-foreground text-sm mt-1 mb-4">
{localizedPost.excerpt}
</p>
{/* Meta */}
<div className="flex flex-wrap items-center gap-6 mb-4 text-sm text-muted-foreground">
<div className="flex items-center gap-2">
<User className="h-4 w-4" />
<span>{localizedPost.authors[0]}</span>
</div>
<div className="flex items-center gap-2">
<Calendar className="h-4 w-4" />
<span>{localizedPost.date}</span>
</div>
<div className="flex items-center gap-2">
<Clock className="h-4 w-4" />
<span>{localizedPost.readTime}</span>
</div>
</div>
{/* Tags */}
<div className="hidden lg:flex flex-wrap gap-2 mb-4">
{localizedPost.tags.map((tag) => (
<Badge
key={tag}
variant="secondary"
className="text-xs"
>
{tag}
</Badge>
))}
</div>
<div className="flex-1" />
{/* Button */}
<Button
variant="ghost"
className="w-full gap-2 group-hover:bg-primary group-hover:text-primary-foreground transition-colors"
>
{t.readMore[language]}
<ArrowRight className="h-4 w-4" />
</Button>
</CardContent>
</Card>
);
})}
</div>
{/* Load More Button */}
{hasMore && (
<div className="text-center">
<Button
size="lg"
variant="outline"
className="gap-2"
onClick={handleLoadMore}
>
{t.loadMore[language]}
</Button>
</div>
)}
{visiblePosts > INITIAL_POSTS && (
<div className="text-center mt-4">
<Button
size="lg"
variant="outline"
className="gap-2"
onClick={handleShowLess}
>
{t.showLess[language]}
</Button>
</div>
)}
</div>
</section>
);
}