Files
supabase/apps/www/components/Events/new/EventBanner.tsx
Alan Daniel 73286972fb feat(www): load _events mdx files on /events listing (#45176)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Feature

## What is the current behavior?

The /events page only loads events from the Notion "Developer Events"
database and the Luma Community API. MDX files under `apps/www/_events/`
(including webinars like agency-webinar, sentry, datadog, figma-make)
are not surfaced on the listing, and past events could still appear
until the moment they ended because the filter compared against `now()`
rather than the current day.

Addresses
[DEBR-85](https://linear.app/supabase/issue/DEBR-85/events-page-powered-by-notion-page).

## What is the new behavior?

- New `getMdxEvents()` reads `apps/www/_events/*.mdx`, parses
frontmatter with `gray-matter`, and returns today-and-future events as
`SupabaseEvent`s.
- `/events` now merges Notion + mdx + Luma events.
- Past events are hidden across all sources by comparing against the
start of today (UTC) instead of `now()`, so events running today stay
visible throughout the day.

## Additional context

Links on mdx events point at the main_cta URL when it's an external
\`http(s)\` URL, otherwise fall back to the built \`/events/{slug}\`
page so on-demand recordings remain reachable.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Events can be sourced from MDX files and merged into site event
listings.
* Luma supports multiple calendars (community and hackathon) for richer
feeds.

* **Improvements**
  * Events now exclude anything before the start of the current UTC day.
  * Added a “Community Event” category filter and included it in counts.
  * Event title typography adjusted for improved readability.
* “Hosted by” text now only shows when hosts exist; host fallbacks
standardized.

* **Chores**
  * Build env updated to include hackathon API key.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-08 11:22:35 -04:00

194 lines
6.8 KiB
TypeScript

'use client'
import { useEvents } from '~/app/events/context'
import { formatHosts } from '~/lib/eventsUtils'
import { ArrowRightIcon, CalendarIcon, MapPinIcon } from 'lucide-react'
import Link from 'next/link'
import { Badge, Button } from 'ui'
export function EventBanner() {
const { isLoading, featuredEvent } = useEvents()
if (isLoading) {
return <EventBannerSkeleton />
}
if (!featuredEvent) return null
return (
<section className="flex flex-col gap-6 rounded-lg py-6">
<article className="flex flex-col md:flex-row md:items-stretch gap-8 lg:py-2">
<div className="flex flex-col gap-6 flex-1">
<div className="flex flex-col">
<div className="flex items-center gap-4">
<h2 className="text-2xl font-medium lg:line-clamp-2">{featuredEvent.title}</h2>
{featuredEvent.isSpeaking && (
<Badge variant="success" className="flex items-center gap-1 shrink-0">
Speaking
</Badge>
)}
</div>
{featuredEvent.hosts.length > 0 && (
<p
className="text-lg font-medium text-foreground-light"
title={`Hosted by ${formatHosts(featuredEvent.hosts).fullList}`}
>
{formatHosts(featuredEvent.hosts).displayText}
</p>
)}
</div>
<p className="text-foreground-light line-clamp-3 lg:line-clamp-4">
{featuredEvent.description}
</p>
</div>
<div className="flex flex-col justify-between gap-8">
<div className="flex flex-row gap-6">
<DateWidget date={featuredEvent.date} endDate={featuredEvent.end_date} />
<LocationWidget location={featuredEvent.location} />
</div>
<div className="flex items-center md:justify-end gap-2">
{featuredEvent.meetingLink && (
<Button type="secondary" size="medium" asChild>
<Link href={featuredEvent.meetingLink} target="_blank" rel="noopener noreferrer">
Meet with us
</Link>
</Button>
)}
{featuredEvent.link && (
<Button size="medium" asChild iconRight={<ArrowRightIcon size={14} />}>
<Link
href={featuredEvent.link.href}
target={featuredEvent.link.target}
rel="noopener noreferrer"
>
Register
</Link>
</Button>
)}
</div>
</div>
</article>
</section>
)
}
const DateWidget = ({ date, endDate }: { date: string; endDate?: string }) => {
const eventDate = new Date(date)
// Date-only Notion events are normalized to noon UTC (T12:00:00Z); detect them
// so we can display in UTC and suppress the fabricated time component.
const isDateOnly = date.endsWith('T12:00:00Z')
const tzOption = isDateOnly ? ({ timeZone: 'UTC' } as const) : {}
const formattedDate = eventDate.toLocaleDateString('en-US', {
weekday: 'long',
month: 'short',
day: 'numeric',
...tzOption,
})
const currentYear = new Date().getFullYear()
const eventYear = isDateOnly ? parseInt(date.slice(0, 4), 10) : eventDate.getFullYear()
const formattedDateWithYear =
eventYear !== currentYear ? `${formattedDate}, ${eventYear}` : formattedDate
// Only show time for events that have a real time component
let timeDisplay: string | null = null
if (!isDateOnly) {
const startTime = eventDate.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true,
})
if (endDate && !endDate.endsWith('T12:00:00Z')) {
const endEventDate = new Date(endDate)
const endTime = endEventDate.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true,
})
timeDisplay = `${startTime} - ${endTime}`
} else {
timeDisplay = startTime
}
}
return (
<div className="flex items-center gap-4">
<div className="bg-surface-100 w-10 h-10 flex items-center justify-center border rounded-md">
<CalendarIcon className="size-5" strokeWidth={1.5} />
</div>
<div className="flex flex-col gap-0">
<p>{formattedDateWithYear}</p>
{timeDisplay && <p className="text-foreground-light text-sm">{timeDisplay}</p>}
</div>
</div>
)
}
const LocationWidget = ({ location }: { location?: string }) => {
const hasLocation = location && location.length > 0
const locationText = hasLocation ? location : 'Unknown'
return (
<div className="flex items-center gap-4">
<div className="bg-surface-100 w-10 h-10 flex items-center justify-center border rounded-md">
<MapPinIcon className="size-5" strokeWidth={1.5} />
</div>
<div className="flex flex-col gap-0">
<p>Hosted at</p>
<p className="text-foreground-light text-sm">{locationText}</p>
</div>
</div>
)
}
const EventBannerSkeleton = () => {
return (
<section className="flex flex-col gap-6 rounded-lg p-6">
<article className="flex flex-col md:flex-row md:items-stretch gap-6 lg:py-2">
{/* Left: title + host + description */}
<div className="flex flex-col gap-6 flex-1">
<div className="flex flex-col gap-1.5">
<div className="h-8 bg-surface-200 rounded-sm animate-pulse w-3/4" />
<div className="h-5 bg-surface-200 rounded-sm animate-pulse w-1/2 mt-1" />
</div>
<div className="h-16 bg-surface-200 rounded-sm animate-pulse w-full" />
</div>
{/* Right: widgets top, button bottom */}
<div className="flex flex-col justify-between gap-6">
<div className="flex flex-row gap-6">
{/* Date Widget Skeleton */}
<div className="flex items-center gap-4">
<div className="bg-surface-200 w-10 h-10 rounded-md animate-pulse" />
<div className="flex flex-col gap-2">
<div className="h-4 w-32 bg-surface-200 rounded-sm animate-pulse" />
<div className="h-3 w-20 bg-surface-200 rounded-sm animate-pulse" />
</div>
</div>
{/* Location Widget Skeleton */}
<div className="flex items-center gap-4">
<div className="bg-surface-200 w-10 h-10 rounded-md animate-pulse" />
<div className="flex flex-col gap-2">
<div className="h-4 w-20 bg-surface-200 rounded-sm animate-pulse" />
<div className="h-3 w-24 bg-surface-200 rounded-sm animate-pulse" />
</div>
</div>
</div>
{/* Button Skeleton */}
<div className="flex justify-end">
<div className="h-9 w-24 bg-surface-200 rounded-sm animate-pulse" />
</div>
</div>
</article>
</section>
)
}