|
| 1 | +import LinkButton from '@/components/core/LinkButton'; |
| 2 | +import Wrapper from '@/components/layout/Wrapper'; |
| 3 | +import directus from '@/util/directus'; |
| 4 | +import { readItems } from '@directus/sdk'; |
| 5 | +import { Card, CardSection, Group, Image, SimpleGrid, Text, Title, Tooltip } from '@mantine/core'; |
| 6 | +import { IconCalendar, IconChevronRight } from '@tabler/icons-react'; |
| 7 | +import { Metadata } from 'next'; |
| 8 | +import { Locale } from 'next-intl'; |
| 9 | +import { getFormatter, setRequestLocale } from 'next-intl/server'; |
| 10 | + |
| 11 | +export const dynamic = 'force-static'; |
| 12 | +export const revalidate = 86400; // 24h |
| 13 | + |
| 14 | +export const metadata: Metadata = { |
| 15 | + title: 'Blog', |
| 16 | + description: |
| 17 | + 'Discover the latest news, updates, and stories from BuildTheEarth. Explore our blog to learn about our projects, events, and the passionate community behind our mission to recreate Earth in Minecraft.', |
| 18 | +}; |
| 19 | + |
| 20 | +export default async function Page({ params }: { params: Promise<{ locale: Locale }> }) { |
| 21 | + const locale = (await params).locale; |
| 22 | + setRequestLocale(locale); |
| 23 | + const formatter = await getFormatter(); |
| 24 | + |
| 25 | + const posts: { |
| 26 | + slug: string; |
| 27 | + title: string; |
| 28 | + thumbnail: string; |
| 29 | + summary: string; |
| 30 | + published_at: string; |
| 31 | + user_created: { display_name?: string }; |
| 32 | + }[] = (await directus.request( |
| 33 | + readItems('blog', { |
| 34 | + limit: 99, |
| 35 | + sort: '-published_at', |
| 36 | + fields: ['slug', 'title', 'thumbnail', 'summary', 'published_at', { user_created: ['display_name'] }], |
| 37 | + }), |
| 38 | + )) as any[]; |
| 39 | + |
| 40 | + return ( |
| 41 | + <Wrapper offsetHeader={false} head={{ title: 'Blog', src: '/placeholders/home.png' }}> |
| 42 | + <Text> |
| 43 | + Ever wonder how we build our projects, what goes on behind the scenes, or want to stay updated with our latest |
| 44 | + news? Then this is the place! Dive into a world of creativity, innovation, and community spirit as we share |
| 45 | + stories, updates, and insights from our journey to recreate Earth in Minecraft. |
| 46 | + </Text> |
| 47 | + <Title order={2} mb="md" mt="lg"> |
| 48 | + Latest Posts |
| 49 | + </Title> |
| 50 | + <SimpleGrid cols={3}> |
| 51 | + {posts.map((post) => ( |
| 52 | + <Card |
| 53 | + key={post.slug + '-lg'} |
| 54 | + withBorder |
| 55 | + maw={{ base: '60vw', sm: '40vw', md: '32vw', xl: '20vw' }} |
| 56 | + radius={0} |
| 57 | + className="anim" |
| 58 | + > |
| 59 | + <CardSection> |
| 60 | + <Image src={`${directus.url}assets/${post.thumbnail}?height=320`} height={160} alt="Thumbnail Image" /> |
| 61 | + </CardSection> |
| 62 | + |
| 63 | + <Text |
| 64 | + fw={700} |
| 65 | + fz="xl" |
| 66 | + mt="md" |
| 67 | + style={{ |
| 68 | + display: '-webkit-box', |
| 69 | + WebkitLineClamp: 2, |
| 70 | + lineClamp: 2, |
| 71 | + WebkitBoxOrient: 'vertical', |
| 72 | + overflow: 'hidden', |
| 73 | + }} |
| 74 | + > |
| 75 | + {post.title} |
| 76 | + </Text> |
| 77 | + <Group wrap="nowrap" gap={10} mt="xs" mb="md"> |
| 78 | + <Tooltip |
| 79 | + label={'Published on ' + formatter.dateTime(new Date(post.published_at), { dateStyle: 'medium' })} |
| 80 | + > |
| 81 | + <IconCalendar size={16} /> |
| 82 | + </Tooltip> |
| 83 | + <Text size="xs" c="dimmed"> |
| 84 | + {formatter.dateTime(new Date(post.published_at), { dateStyle: 'medium' })} /{' '} |
| 85 | + {post.user_created.display_name || 'BuildTheEarth'} |
| 86 | + </Text> |
| 87 | + </Group> |
| 88 | + <Text |
| 89 | + size="sm" |
| 90 | + c="dimmed" |
| 91 | + style={{ |
| 92 | + minHeight: '5lh', |
| 93 | + maxHeight: '5lh', |
| 94 | + display: '-webkit-box', |
| 95 | + WebkitLineClamp: 5, |
| 96 | + lineClamp: 5, |
| 97 | + WebkitBoxOrient: 'vertical', |
| 98 | + overflow: 'hidden', |
| 99 | + }} |
| 100 | + > |
| 101 | + {post.summary} |
| 102 | + </Text> |
| 103 | + <LinkButton |
| 104 | + href={`/blog/${post.slug}`} |
| 105 | + variant="subtle" |
| 106 | + color="indigo" |
| 107 | + rightSection={<IconChevronRight size={12} />} |
| 108 | + mt="md" |
| 109 | + > |
| 110 | + Read more |
| 111 | + </LinkButton> |
| 112 | + </Card> |
| 113 | + ))} |
| 114 | + </SimpleGrid> |
| 115 | + </Wrapper> |
| 116 | + ); |
| 117 | +} |
0 commit comments