|
1 |
| -const BlogPage = () => { |
| 1 | +import { |
| 2 | + Badge, |
| 3 | + Box, |
| 4 | + Button, |
| 5 | + Card, |
| 6 | + Container, |
| 7 | + Flex, |
| 8 | + Grid, |
| 9 | + Heading, |
| 10 | + Section, |
| 11 | + Text, |
| 12 | +} from '@radix-ui/themes'; |
| 13 | +import { IconArrowLeft } from '@tabler/icons-react'; |
| 14 | +import Image from 'next/image'; |
| 15 | +import Link from 'next/link'; |
| 16 | +import { type FC } from 'react'; |
| 17 | + |
| 18 | +import { firstName, lastName } from '@/constants/me'; |
| 19 | +import { routes } from '@/constants/site-config'; |
| 20 | +import { getArticles } from '@/lib/queries'; |
| 21 | +import { dateFormatter } from '@/lib/utils'; |
| 22 | + |
| 23 | +const BlogPage: FC = async () => { |
| 24 | + const articles = await getArticles(); |
| 25 | + const featuredArticle = articles.reduce((highestViewedArticle, article) => |
| 26 | + article.view > highestViewedArticle.view ? article : highestViewedArticle, |
| 27 | + ); |
| 28 | + |
2 | 29 | return (
|
3 |
| - <div style={{ height: 3000 }}> |
4 |
| - <h1>Blog</h1> |
5 |
| - </div> |
| 30 | + <Container> |
| 31 | + <Section> |
| 32 | + <Button asChild highContrast size="3" variant="ghost"> |
| 33 | + <Link href={routes.home.pathname}> |
| 34 | + <IconArrowLeft size={20} /> |
| 35 | + {firstName} {lastName} |
| 36 | + </Link> |
| 37 | + </Button> |
| 38 | + <Card asChild mt="8" variant="ghost"> |
| 39 | + <Link href={`${routes.blog.pathname}/${featuredArticle.slug}`}> |
| 40 | + <Grid asChild columns={{ sm: '2' }} gapX="5" gapY="4"> |
| 41 | + <article> |
| 42 | + <div> |
| 43 | + <Box |
| 44 | + className="aspect-video overflow-hidden rounded-[var(--card-border-radius)]" |
| 45 | + position="relative" |
| 46 | + > |
| 47 | + {featuredArticle.coverPhoto ? ( |
| 48 | + <Image |
| 49 | + fill |
| 50 | + alt={featuredArticle.title} |
| 51 | + className="object-cover" |
| 52 | + src={featuredArticle.coverPhoto} |
| 53 | + /> |
| 54 | + ) : null} |
| 55 | + </Box> |
| 56 | + </div> |
| 57 | + <Flex direction="column" gap="3"> |
| 58 | + {featuredArticle.categories && |
| 59 | + featuredArticle.categories.length > 0 ? ( |
| 60 | + <Flex gap="3"> |
| 61 | + {featuredArticle.categories.map((category) => ( |
| 62 | + <Badge key={category} size="3"> |
| 63 | + {category} |
| 64 | + </Badge> |
| 65 | + ))} |
| 66 | + </Flex> |
| 67 | + ) : null} |
| 68 | + <Heading size={{ initial: '4', xs: '6', md: '8' }}> |
| 69 | + {featuredArticle.title} |
| 70 | + </Heading> |
| 71 | + <Text |
| 72 | + className="line-clamp-3" |
| 73 | + size={{ initial: '3', md: '4' }} |
| 74 | + > |
| 75 | + {featuredArticle.description} |
| 76 | + </Text> |
| 77 | + <Text color="gray" size={{ initial: '2', md: '3' }}> |
| 78 | + {dateFormatter.format(featuredArticle.createdAt)} |
| 79 | + </Text> |
| 80 | + </Flex> |
| 81 | + </article> |
| 82 | + </Grid> |
| 83 | + </Link> |
| 84 | + </Card> |
| 85 | + </Section> |
| 86 | + </Container> |
6 | 87 | );
|
7 | 88 | };
|
8 | 89 |
|
|
0 commit comments