-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
348 lines (322 loc) · 13.3 KB
/
Copy pathindex.tsx
File metadata and controls
348 lines (322 loc) · 13.3 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
"use client";
import { FC, useEffect, useState } from "react";
import { Content, asDate, isFilled } from "@prismicio/client";
import * as prismic from "@prismicio/client";
import { SliceComponentProps, PrismicRichText } from "@prismicio/react";
import { motion } from "framer-motion";
import { useAtlas } from "@/components/atlas/AtlasProvider";
import Link from "next/link";
import { FaCalendarAlt, FaClock, FaTag, FaArrowRight, FaNewspaper } from "react-icons/fa";
/**
* Props for `BlogPosts`.
*/
export type BlogPostsProps = SliceComponentProps<Content.BlogpostsSlice>;
/**
* Component for "BlogPosts" Slices.
*/
const BlogPosts: FC<BlogPostsProps> = ({ slice }) => {
const { announce, speak, config } = useAtlas();
const [selectedTag, setSelectedTag] = useState<string>("all");
const [expandedPost, setExpandedPost] = useState<number | null>(null);
// Format date helper
const formatDate = (dateField: prismic.DateField) => {
if (!dateField) return "No date";
const date = asDate(dateField);
return date?.toLocaleDateString("en-NZ", {
year: "numeric",
month: "long",
day: "numeric"
}) || "No date";
};
// Calculate reading time (rough estimate)
const calculateReadingTime = (content: any) => {
if (!isFilled.richText(content)) return "1 min read";
const text = content
.map((block: any) => block.text || "")
.join(" ");
const wordsPerMinute = 200;
const words = text.split(/\s+/).length;
const minutes = Math.ceil(words / wordsPerMinute);
return `${minutes} min read`;
};
// Extract unique tags from all blog posts
const allTags = slice.items && slice.items.length > 0
? Array.from(new Set(
slice.items.flatMap((item: any) =>
item.post_tags && isFilled.keyText(item.post_tags)
? item.post_tags.split(',').map((tag: string) => tag.trim()).filter(Boolean)
: []
)
))
: [];
// Voice command registration
useEffect(() => {
if (!config.assistant.enabled) return;
const commands = [
{
pattern: /read.*blog|show.*articles?|display.*posts?/i,
action: () => {
announce("Here are my latest blog posts and articles");
if (isFilled.keyText(slice.primary?.title)) {
speak(slice.primary.title);
}
}
},
{
pattern: /filter.*tag|show.*(\w+).*posts?/i,
action: (match: string) => {
const tagMatch = match.match(/show.*(\w+).*posts?/i);
if (tagMatch?.[1] && allTags.includes(tagMatch[1])) {
setSelectedTag(tagMatch[1]);
announce(`Filtering posts by ${tagMatch[1]}`);
}
}
}
];
// Register commands with ATLAS
commands.forEach(cmd => {
// Command registration would happen here
});
}, [config.assistant.enabled, announce, speak, slice.primary, allTags]);
const containerVariants = {
hidden: { opacity: 0 },
visible: {
opacity: 1,
transition: {
staggerChildren: 0.1,
delayChildren: 0.2
}
}
};
const itemVariants = {
hidden: {
opacity: 0,
y: 20,
scale: 0.95
},
visible: {
opacity: 1,
y: 0,
scale: 1,
transition: {
type: "spring" as const,
stiffness: 100,
damping: 15
}
}
};
return (
<section
data-slice-type={slice.slice_type}
data-slice-variation={slice.variation}
className="relative py-20 overflow-hidden"
aria-label="Blog Posts Section"
>
{/* ATLAS HUD Background */}
<div className="absolute inset-0 bg-gradient-to-br from-slate-900 via-blue-950/50 to-slate-900" />
{/* Arc Reactor Grid Pattern */}
<div className="absolute inset-0 opacity-10">
<div className="absolute inset-0" style={{
backgroundImage: `
linear-gradient(90deg, #00d4ff 1px, transparent 1px),
linear-gradient(#00d4ff 1px, transparent 1px)
`,
backgroundSize: '50px 50px'
}} />
</div>
<div className="relative container mx-auto px-4 max-w-7xl">
{/* Header */}
<motion.div
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6 }}
className="text-center mb-12"
>
<div className="inline-flex items-center gap-3 mb-4">
<FaNewspaper className="text-3xl text-cyan-400" />
<h2 className="text-4xl font-orbitron font-bold bg-gradient-to-r from-cyan-400 to-blue-500 bg-clip-text text-transparent">
{isFilled.keyText(slice.primary?.title)
? slice.primary.title
: "Blog Posts"}
</h2>
</div>
{isFilled.keyText(slice.primary?.excerpt) && (
<p className="text-lg text-cyan-200/80 max-w-3xl mx-auto mt-4 font-inter">
{slice.primary.excerpt}
</p>
)}
</motion.div>
{/* Tag Filter */}
{allTags.length > 0 && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6, delay: 0.2 }}
className="flex flex-wrap justify-center gap-3 mb-12"
>
<button
onClick={() => setSelectedTag("all")}
className={`px-4 py-2 rounded-full font-inter text-sm transition-all duration-300 ${
selectedTag === "all"
? "bg-cyan-500 text-slate-900 shadow-lg shadow-cyan-500/50"
: "bg-slate-800/50 text-cyan-300 hover:bg-slate-700/50 border border-cyan-500/30"
}`}
aria-pressed={selectedTag === "all"}
>
All Posts
</button>
{allTags.map((tag: string, index: number) => (
<button
key={index}
onClick={() => setSelectedTag(tag)}
className={`px-4 py-2 rounded-full font-inter text-sm transition-all duration-300 ${
selectedTag === tag
? "bg-cyan-500 text-slate-900 shadow-lg shadow-cyan-500/50"
: "bg-slate-800/50 text-cyan-300 hover:bg-slate-700/50 border border-cyan-500/30"
}`}
aria-pressed={selectedTag === tag}
>
<FaTag className="inline mr-2" />
{tag}
</button>
))}
</motion.div>
)}
{/* Blog Posts Grid */}
{slice.items && slice.items.length > 0 ? (
<motion.div
variants={containerVariants}
initial="hidden"
animate="visible"
className="grid gap-8 md:grid-cols-2 lg:grid-cols-3"
>
{slice.items
.filter((item: any) => {
if (selectedTag === "all") return true;
if (!item.post_tags || !isFilled.keyText(item.post_tags)) return false;
const tags = item.post_tags.split(',').map((tag: string) => tag.trim());
return tags.includes(selectedTag);
})
.map((item: any, index: number) => (
<motion.article
key={index}
variants={itemVariants}
className="relative group"
onMouseEnter={() => setExpandedPost(index)}
onMouseLeave={() => setExpandedPost(null)}
>
<div className="relative bg-gradient-to-br from-slate-800/50 to-slate-900/50 backdrop-blur-md rounded-xl border border-cyan-500/30 overflow-hidden transition-all duration-500 hover:border-cyan-400 hover:shadow-2xl hover:shadow-cyan-500/20 h-full">
{/* Featured Image */}
{isFilled.image(item.featured_image) && (
<div className="relative h-48 overflow-hidden">
<img
src={item.featured_image.url}
alt={item.featured_image.alt || item.post_title || "Blog post"}
className="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
/>
<div className="absolute inset-0 bg-gradient-to-t from-slate-900/60 to-transparent" />
</div>
)}
{/* Holographic Effect */}
<div className="absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity duration-500">
<div className="absolute inset-0 bg-gradient-to-r from-transparent via-cyan-500/10 to-transparent animate-pulse" />
</div>
<div className="p-6 flex flex-col h-full">
{/* Post Header */}
<div className="flex flex-wrap items-center gap-4 mb-4 text-sm text-cyan-300/70">
{item.publish_date && (
<div className="flex items-center gap-2">
<FaCalendarAlt className="text-cyan-400" />
<time dateTime={item.publish_date}>
{formatDate(item.publish_date)}
</time>
</div>
)}
{item.post_content && (
<div className="flex items-center gap-2">
<FaClock className="text-cyan-400" />
<span>{calculateReadingTime(item.post_content)}</span>
</div>
)}
</div>
{/* Post Title */}
{isFilled.keyText(item.post_title) && (
<h3 className="text-xl font-orbitron font-bold text-cyan-100 mb-3 group-hover:text-cyan-300 transition-colors">
{item.post_title}
</h3>
)}
{/* Post Excerpt */}
{isFilled.keyText(item.post_excerpt) && (
<p className="text-cyan-200/70 mb-4 line-clamp-3 flex-grow">
{item.post_excerpt}
</p>
)}
{/* Post Content Preview */}
{isFilled.richText(item.post_content) && (
<div className="rich-text prose prose-invert prose-sm max-w-none line-clamp-3 mb-4">
<PrismicRichText
field={item.post_content}
components={{
paragraph: ({ children }) => (
<p className="text-cyan-100/60 text-sm leading-relaxed">{children}</p>
),
strong: ({ children }) => (
<strong className="text-cyan-300 font-medium">{children}</strong>
),
em: ({ children }) => (
<em className="text-cyan-200 italic">{children}</em>
)
}}
/>
</div>
)}
{/* Tags */}
{isFilled.keyText(item.post_tags) && (
<div className="flex flex-wrap gap-2 mt-auto">
{item.post_tags.split(',').map((tag: string, tagIndex: number) => {
const trimmedTag = tag.trim();
return trimmedTag && (
<span
key={tagIndex}
className="px-2 py-1 bg-cyan-500/20 text-cyan-300 rounded-full text-xs font-inter border border-cyan-500/30"
>
<FaTag className="inline mr-1" />
{trimmedTag}
</span>
);
}).slice(0, 3)}
{item.post_tags.split(',').length > 3 && (
<span className="px-2 py-1 text-cyan-300/50 text-xs">
+{item.post_tags.split(',').length - 3} more
</span>
)}
</div>
)}
</div>
{/* ATLAS Integration Indicator */}
<div className="absolute top-4 right-4 opacity-0 group-hover:opacity-100 transition-opacity">
<div className="p-2 bg-cyan-500/20 rounded-lg border border-cyan-500/30">
<span className="text-xs text-cyan-300 font-mono">ATLAS READY</span>
</div>
</div>
</div>
</motion.article>
))}
</motion.div>
) : (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.6 }}
className="text-center py-12"
>
<p className="text-cyan-300/70 text-lg">
No blog posts available yet. Check back soon!
</p>
</motion.div>
)}
</div>
</section>
);
};
export default BlogPosts;