|
| 1 | +import React from 'react' |
| 2 | +import { Heading } from '../ui/heading' |
| 3 | +import Link from 'next/link' |
| 4 | +import Image from 'next/image' |
| 5 | +import { ArrowUpRightIcon } from '@heroicons/react/24/outline' |
| 6 | +import { allGuides, Guide } from '@/content' |
| 7 | + |
| 8 | +type RequiredFeaturedGuide = Guide & { |
| 9 | + featured: NonNullable<Guide['featured']> |
| 10 | +} |
| 11 | + |
| 12 | +const GuidesFeatured: React.FC = ({ take = 3 }: { take?: number }) => { |
| 13 | + const featuredGuides = allGuides |
| 14 | + .filter((guide): guide is RequiredFeaturedGuide => !!guide.featured) |
| 15 | + .sort((a, b) => { |
| 16 | + if (a.published_at && b.published_at) { |
| 17 | + return a.published_at > b.published_at ? -1 : 1 |
| 18 | + } |
| 19 | + |
| 20 | + return 0 |
| 21 | + }) |
| 22 | + .slice(0, take) |
| 23 | + |
| 24 | + return featuredGuides.length === 0 ? null : ( |
| 25 | + <div> |
| 26 | + <Heading level={2} className="sr-only"> |
| 27 | + Featured |
| 28 | + </Heading> |
| 29 | + <div className="mx-auto grid max-w-2xl auto-rows-fr grid-cols-1 gap-4 lg:mx-0 lg:max-w-none lg:grid-cols-3"> |
| 30 | + {featuredGuides.map((guide) => ( |
| 31 | + <article |
| 32 | + key={guide.slug} |
| 33 | + className="group relative isolate flex flex-col justify-end overflow-hidden rounded-lg bg-zinc-900 px-8 pb-8 pt-48" |
| 34 | + > |
| 35 | + <Image |
| 36 | + alt={guide.featured.image_alt} |
| 37 | + src={guide.featured.image} |
| 38 | + fill |
| 39 | + sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw" |
| 40 | + priority |
| 41 | + className="absolute inset-0 -z-10 h-full w-full object-cover" |
| 42 | + /> |
| 43 | + <div className="absolute inset-0 -z-10 bg-gradient-to-t from-primary-300/50 via-secondary-400/30 to-primary-500/40 dark:from-primary-700/50 dark:via-secondary-800/40 dark:to-primary-900/50" /> |
| 44 | + <div className="absolute inset-0 -z-10 rounded-2xl ring-1 ring-inset ring-primary-500/10 dark:ring-primary-900/10" /> |
| 45 | + |
| 46 | + <h3 className="mt-3 text-lg/6 font-semibold tracking-wide text-white"> |
| 47 | + <Link href={`/${guide.slug}`}> |
| 48 | + <span className="absolute inset-0" /> |
| 49 | + {guide.title} |
| 50 | + </Link> |
| 51 | + </h3> |
| 52 | + <p className="mt-1 text-base leading-5 text-white dark:text-muted-foreground"> |
| 53 | + {guide.description} |
| 54 | + </p> |
| 55 | + <ArrowUpRightIcon |
| 56 | + aria-hidden="true" |
| 57 | + className="pointer-events-none absolute right-0 top-0 m-4 size-6 text-white transition-transform group-hover:-translate-y-1 group-hover:translate-x-1 dark:text-primary-light/70" |
| 58 | + /> |
| 59 | + </article> |
| 60 | + ))} |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + ) |
| 64 | +} |
| 65 | + |
| 66 | +export default GuidesFeatured |
0 commit comments