|
1 | 1 | import { Metadata } from "next"; |
2 | 2 | import Link from "next/link"; |
3 | 3 | import Image from "next/image"; |
4 | | -import { getAllPosts, formatDate } from "@/lib/blog"; |
| 4 | +import { FiEye, FiHeart } from "react-icons/fi"; |
| 5 | +import { getAllPosts, formatDate, getPostsStats } from "@/lib/blog"; |
5 | 6 | import styles from "./page.module.css"; |
6 | 7 |
|
7 | 8 | export const metadata: Metadata = { |
8 | 9 | title: "Blog | Oleksandr Ratushnyi", |
9 | 10 | description: "Articles about web development, JavaScript, React, and more.", |
10 | 11 | }; |
11 | 12 |
|
12 | | -export default function BlogPage() { |
| 13 | +export default async function BlogPage() { |
13 | 14 | const posts = getAllPosts(); |
| 15 | + const slugs = posts.map((post) => post.slug); |
| 16 | + const stats = await getPostsStats(slugs); |
14 | 17 |
|
15 | 18 | return ( |
16 | 19 | <main className={styles.main}> |
@@ -52,6 +55,16 @@ export default function BlogPage() { |
52 | 55 | <span className={styles.separator}>·</span> |
53 | 56 | <span className={styles.readingTime}>{post.readingTime}</span> |
54 | 57 | </div> |
| 58 | + <div className={styles.stats}> |
| 59 | + <span className={styles.stat}> |
| 60 | + <FiEye className={styles.statIcon} /> |
| 61 | + {stats[post.slug]?.views ?? 0} |
| 62 | + </span> |
| 63 | + <span className={styles.stat}> |
| 64 | + <FiHeart className={styles.statIcon} /> |
| 65 | + {stats[post.slug]?.likes ?? 0} |
| 66 | + </span> |
| 67 | + </div> |
55 | 68 | {post.tags.length > 0 && ( |
56 | 69 | <div className={styles.tags}> |
57 | 70 | {post.tags.slice(0, 3).map((tag) => ( |
|
0 commit comments