Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

meetups ogs and events (#30598)

Francesco Sansalvadorecceeae7e59cf
diff --git a/apps/www/components/Events/EventListItem.tsx b/apps/www/components/Events/EventListItem.tsx
index 432f63ba301..b112d9b0ad5 100644
--- a/apps/www/components/Events/EventListItem.tsx
+++ b/apps/www/components/Events/EventListItem.tsx
@@ -36,12 +36,12 @@ const EventListItem = ({ event }: Props) => {
<Link
href={event.disable_page_build ? event.link?.href ?? '' : event.path}
target={event.disable_page_build ? event.link?.target ?? '' : '_self'}
- className="group flex flex-col lg:grid lg:grid-cols-10 2xl:grid-cols-12 w-full py-2 sm:py-4 h-full border-b"
+ className="group flex flex-col lg:grid lg:grid-cols-10 xl:grid-cols-12 w-full py-2 sm:py-4 h-full border-b"
>
- <div className="flex w-full lg:col-span-7 2xl:col-span-9">
+ <div className="flex w-full lg:col-span-7 xl:col-span-8">
<h3 className="text-foreground text-lg group-hover:underline">{event.title}</h3>
</div>
- <div className="lg:col-span-3 xl:col-span-3 flex justify-between items-center grid-cols-2 gap-2 text-sm">
+ <div className="lg:col-span-3 xl:col-span-4 flex justify-between items-center grid-cols-2 gap-2 text-sm">
{event.categories && (
<div className="hidden xl:flex gap-2 text-foreground-lighter group-hover:text-foreground-light">
{event.categories.map(
@@ -61,7 +61,7 @@ const EventListItem = ({ event }: Props) => {
}
const EventDate: React.FC<{ event: PostTypes }> = ({ event }) => (
- <p className="text-foreground-lighter lg:text-right flex-grow lg:w-full text-nowrap group-hover:text-foreground-light min-w-40 inline-flex items-center lg:justify-end gap-1.5 flex-1 w-full">
+ <p className="text-foreground-lighter lg:text-left lg:w-[240px] text-nowrap group-hover:text-foreground-light min-w-20 inline-flex items-center lg:justify-start gap-1.5 w-full">
{dayjs(event.date).tz(event.timezone).format('DD MMM YYYY')}
<span className="min-w-px h-[16px] bg-muted" />
<span className="">{dayjs(event.date).tz(event.timezone).format('hA')}</span>
diff --git a/apps/www/lib/database.types.ts b/apps/www/lib/database.types.ts
index 0dbac75abfe..689bbc7d4aa 100644
--- a/apps/www/lib/database.types.ts
+++ b/apps/www/lib/database.types.ts
@@ -7,6 +7,7 @@ export type Database = {
Row: {
contact_email: string
created_at: string | null
+ start_at: string | null
document: string | null
id: number
updated_at: string | null
@@ -14,6 +15,7 @@ export type Database = {
Insert: {
contact_email: string
created_at?: string | null
+ start_at?: string | null
document?: string | null
id?: number
updated_at?: string | null
@@ -21,6 +23,7 @@ export type Database = {
Update: {
contact_email?: string
created_at?: string | null
+ start_at?: string | null
document?: string | null
id?: number
updated_at?: string | null
@@ -96,6 +99,8 @@ export type Database = {
link: string | null
location: string | null
is_live: boolean
+ city?: string
+ timezone?: string
}
Insert: {
id?: number
@@ -105,6 +110,8 @@ export type Database = {
link?: string | null
location?: string | null
is_live?: boolean
+ city?: string
+ timezone?: string
}
Update: {
id?: number
@@ -114,6 +121,8 @@ export type Database = {
link?: string | null
location?: string | null
is_live?: boolean
+ city?: string
+ timezone?: string
}
Relationships: []
}
diff --git a/apps/www/pages/events/index.tsx b/apps/www/pages/events/index.tsx
index 15177e1ebc6..de32454215e 100644
--- a/apps/www/pages/events/index.tsx
+++ b/apps/www/pages/events/index.tsx
@@ -3,6 +3,7 @@ import { useRouter } from 'next/router'
import { NextSeo } from 'next-seo'
import { getSortedPosts } from '~/lib/posts'
+import supabase from '~/lib/supabase'
import { cn } from 'ui'
import DefaultLayout from '~/components/Layouts/Default'
@@ -121,10 +122,38 @@ function Events({ events: allEvents, onDemandEvents, categories }: Props) {
}
export async function getStaticProps() {
- const allEvents = getSortedPosts({
+ const { data: meetups, error } = await supabase
+ .from('meetups')
+ .select('id, city, country, link, start_at, timezone, launch_week')
+
+ if (error) console.log('meetups error: ', error)
+
+ const meetupEvents: BlogPost[] =
+ meetups?.map((meetup: any) => ({
+ slug: '',
+ type: 'event',
+ title: `Launch Week ${meetup.launch_week.slice(2)} Meetup: ${meetup.city}, ${meetup.country}`,
+ date: meetup.start_at,
+ description: '',
+ thumb: '',
+ path: '',
+ url: meetup.link ?? '',
+ tags: ['meetup', 'launch-week'],
+ categories: ['meetup'],
+ timezone: meetup.timezone ?? 'America/Los_Angeles',
+ disable_page_build: true,
+ link: {
+ href: meetup.link ?? '#',
+ target: '_blank',
+ },
+ })) ?? []
+
+ const staticEvents = getSortedPosts({
directory: '_events',
runner: '** EVENTS PAGE **',
}) as BlogPost[]
+
+ const allEvents = [...staticEvents, ...meetupEvents]
const upcomingEvents = allEvents.filter((event: BlogPost) => new Date(event.date!) >= new Date())
const onDemandEvents = allEvents.filter(
(event: BlogPost) => new Date(event.date!) < new Date() && event.onDemand === true
diff --git a/apps/www/types/post.ts b/apps/www/types/post.ts
index 743f26ae4ff..f4afc35de01 100644
--- a/apps/www/types/post.ts
+++ b/apps/www/types/post.ts
@@ -1,6 +1,6 @@
type PostTypes = {
slug?: string
- type: 'casestudy' | 'blog'
+ type: 'casestudy' | 'blog' | 'event'
title: string
date?: string
formattedDate?: string
@@ -17,8 +17,8 @@ type PostTypes = {
description: string
url: string
path: string
- tags?: []
- categories?: []
+ tags?: string[]
+ categories?: string[]
logo?: string
logo_inverse?: string
hideAuthor?: boolean
diff --git a/supabase/functions/common/helpers.ts b/supabase/functions/common/helpers.ts
new file mode 100644
index 00000000000..d066e02bf3e
--- /dev/null
+++ b/supabase/functions/common/helpers.ts
@@ -0,0 +1,39 @@
+export const normalizeString = (str: string) =>
+ str
+ .normalize('NFD') // Normalize to separate accents
+ .replace(/[\u0300-\u036f]/g, '') // Remove diacritics
+ .toLowerCase() // Convert to lowercase
+ .replace(/[^a-z0-9]+/g, '-') // Replace non-alphanumeric characters with hyphens
+ .replace(/^-+|-+$/g, '') // Trim hyphens from start and end
+
+export const formatDateTime = (isoString: string, timezone: string) => {
+ const date = new Date(isoString)
+
+ // Extract the day and the short month
+ const dayFormatter = new Intl.DateTimeFormat('en-US', { day: 'numeric' })
+ const monthFormatter = new Intl.DateTimeFormat('en-US', { month: 'short' })
+
+ const day = dayFormatter.format(date)
+ const month = monthFormatter.format(date)
+
+ // Format the time with AM/PM
+ const timeFormatter = new Intl.DateTimeFormat('en-US', {
+ hour: 'numeric',
+ hour12: true,
+ // we're saving absolute time
+ // timeZone: timezone,
+ })
+
+ const time = timeFormatter.format(date)
+
+ // Add timezone abbreviation (PT, ET, etc.)
+ const tzFormatter = new Intl.DateTimeFormat('en-US', {
+ timeZoneName: 'short',
+ timeZone: timezone,
+ })
+ const timeZoneAbbreviation = tzFormatter
+ .formatToParts(date)
+ .find((part) => part.type === 'timeZoneName')?.value
+
+ return `${day} ${month} / ${time.replace(':00', '')} ${timeZoneAbbreviation}`
+}
diff --git a/supabase/functions/lw13-meetup-og/README.md b/supabase/functions/lw13-meetup-og/README.md
new file mode 100644
index 00000000000..e412c3fb2cd
--- /dev/null
+++ b/supabase/functions/lw13-meetup-og/README.md
@@ -0,0 +1,22 @@
+# Open Graph (OG) Image Generation with Supabase Storage CDN Caching
+
+Generate Open Graph images with Deno and Supabase Edge Functions and cache the generated image with Supabase Storage CDN.
+
+- Docs: https://deno.land/x/[email protected]
+- Examples: https://vercel.com/docs/concepts/functions/edge-functions/og-image-examples
+- Demo: https://obuldanrptloktxcffvn.supabase.co/functions/v1/lw13-meetups-ogs?username=thorwebdev
+
+## Run locally
+
+```bash
+supabase start
+supabase functions serve lw13-meetups-ogs --no-verify-jwt --env-file ./supabase/.env.local
+```
+
+Navigate to http://localhost:54321/functions/v1/lw13-meetups-ogs
+
+## Deploy
+
+```bash
+supabase functions deploy lw13-meetups-ogs --no-verify-jwt
+```
diff --git a/supabase/functions/lw13-meetup-og/handler.tsx b/supabase/functions/lw13-meetup-og/handler.tsx
new file mode 100644
index 00000000000..919d7128d1e
--- /dev/null
+++ b/supabase/functions/lw13-meetup-og/handler.tsx
@@ -0,0 +1,218 @@
+import React from 'https://esm.sh/[email protected]?deno-std=0.140.0'
+import { ImageResponse } from 'https://deno.land/x/[email protected]/mod.ts'
+import { createClient } from 'jsr:@supabase/supabase-js@2'
+import { encodeUrl } from 'https://deno.land/x/encodeurl/mod.ts'
+import { formatDateTime, normalizeString } from '../common/helpers.ts'
+
+const corsHeaders = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
+}
+
+const SUPABASE_URL =
+ Deno.env.get('SUPABASE_URL') !== 'http://kong:8000'
+ ? Deno.env.get('SUPABASE_URL')
+ : 'http://host.docker.internal:54321'
+
+const STORAGE_BASE_PATH = `launch-week/lw13`
+const STORAGE_URL = `${SUPABASE_URL}/storage/v1/object/public/images/${STORAGE_BASE_PATH}`
+
+// Load custom font
+const FONT_URL = `${STORAGE_URL}/assets/font/CircularStd-Book.otf`
+const MONO_FONT_URL = `${STORAGE_URL}/assets/font/SourceCodePro-Regular.ttf`
+const font = fetch(new URL(FONT_URL, import.meta.url)).then((res) => res.arrayBuffer())
+const mono_font = fetch(new URL(MONO_FONT_URL, import.meta.url)).then((res) => res.arrayBuffer())
+
+const MEETUPS_TABLE = 'meetups'
+
+const STYLING_CONGIF = {
+ regular: {
+ BACKGROUND: '#060809',
+ FOREGROUND: '#F8F9FA',
+ FOREGROUND_LIGHT: '#8B9092',
+ },
+}
+
+export async function handler(req: Request) {
+ const url = new URL(req.url)
+ const meetupId = url.searchParams.get('id') ?? url.searchParams.get('amp;id')
+
+ try {
+ const supabaseAdminClient = createClient(
+ // Supabase API URL - env var exported by default when deployed.
+ Deno.env.get('LIVE_SUPABASE_URL') ?? 'http://host.docker.internal:54321',
+ // Supabase API SERVICE ROLE KEY - env var exported by default when deployed.
+ Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''
+ )
+
+ // Get ticket data
+ const { data: meetup, error } = await supabaseAdminClient
+ .from(MEETUPS_TABLE)
+ .select('id, city, country, start_at, timezone')
+ .eq('launch_week', 'lw13')
+ .eq('id', meetupId)
+ .maybeSingle()
+
+ if (error) console.log('fetch error', error.message)
+ if (!meetup) throw new Error(`No meetup found with id: ${meetupId}`)
+
+ const ticketType = 'regular'
+ const fontData = await font
+ const monoFontData = await mono_font
+ const OG_WIDTH = 1200
+ const OG_HEIGHT = 800
+ const OG_PADDING_X = 90
+ const OG_PADDING_Y = 90
+
+ const startAt = meetup.start_at ? formatDateTime(meetup.start_at, meetup.timezone) : ''
+
+ const BACKGROUND = {
+ regular: {
+ BACKGROUND_IMG: `${STORAGE_URL}/assets/lw13-meetup-og-template.png`,
+ },
+ }
+
+ const generatedOgImage = new ImageResponse(
+ (
+ <>
+ <div
+ style={{
+ width: `${OG_WIDTH}px`,
+ height: `${OG_HEIGHT}px`,
+ position: 'relative',
+ fontFamily: '"Circular"',
+ color: STYLING_CONGIF[ticketType].FOREGROUND,
+ backgroundColor: STYLING_CONGIF[ticketType].BACKGROUND,
+ overflow: 'hidden',
+ display: 'flex',
+ flexDirection: 'column',
+ padding: '60px',
+ justifyContent: 'space-between',
+ }}
+ >
+ {/* Background */}
+ <img
+ width={`${OG_WIDTH + 4}px`}
+ height={`${OG_HEIGHT + 4}px`}
+ style={{
+ position: 'absolute',
+ top: '-1px',
+ left: '-1px',
+ bottom: '-1px',
+ right: '-1px',
+ zIndex: '0',
+ background: STYLING_CONGIF[ticketType].BACKGROUND,
+ backgroundSize: 'cover',
+ }}
+ src={BACKGROUND[ticketType].BACKGROUND_IMG}
+ />
+
+ <div
+ style={{
+ position: 'absolute',
+ // top: OG_PADDING_Y,
+ left: OG_PADDING_X,
+ // bottom: OG_PADDING_Y,
+ bottom: OG_PADDING_Y + 170,
+ display: 'flex',
+ flexDirection: 'column',
+ width: OG_WIDTH - OG_PADDING_X * 2,
+ alignItems: 'flex-start',
+ justifyContent: 'center',
+ letterSpacing: '0',
+ lineHeight: '110%',
+ }}
+ >
+ <p
+ style={{
+ margin: '0',
+ fontFamily: '"SourceCodePro"',
+ fontSize: 32,
+ color: STYLING_CONGIF[ticketType].FOREGROUND_LIGHT,
+ }}
+ >
+ {startAt}{' '}
+ </p>
+ <p
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ marginBottom: 20,
+ fontSize: 104,
+ letterSpacing: '-0.1rem',
+ color: STYLING_CONGIF[ticketType].FOREGROUND_LIGHT,
+ }}
+ >
+ <span
+ style={{
+ display: 'flex',
+ margin: 0,
+ fontSize: 120,
+ color: STYLING_CONGIF[ticketType].FOREGROUND,
+ }}
+ >
+ {meetup.city}
+ </span>
+ <span
+ style={{
+ display: 'flex',
+ margin: 0,
+ color: STYLING_CONGIF[ticketType].FOREGROUND,
+ }}
+ >
+ Meetup
+ </span>
+ </p>
+ </div>
+ </div>
+ </>
+ ),
+ {
+ width: OG_WIDTH,
+ height: OG_HEIGHT,
+ fonts: [
+ {
+ name: 'Circular',
+ data: fontData,
+ style: 'normal',
+ },
+ {
+ name: 'SourceCodePro',
+ data: monoFontData,
+ style: 'normal',
+ },
+ ],
+ headers: {
+ 'content-type': 'image/png',
+ 'cache-control': 'public, max-age=31536000, s-maxage=31536000, no-transform, immutable',
+ 'cdn-cache-control': 'max-age=31536000',
+ },
+ }
+ )
+
+ const normalizedCountry = normalizeString(meetup.country)
+ const normalizedCity = normalizeString(meetup.city)
+
+ const relativeFilePath = encodeUrl(
+ `og/meetups/${normalizedCountry}-${normalizedCity}-${meetup.id}.png`
+ )
+
+ // Upload image to storage.
+ const { error: storageError } = await supabaseAdminClient.storage
+ .from('images')
+ .upload(`${STORAGE_BASE_PATH}/${relativeFilePath}`, generatedOgImage.body!, {
+ contentType: 'image/png',
+ cacheControl: `0`,
+ upsert: true,
+ })
+
+ if (storageError) throw new Error(`storageError: ${storageError.message}`)
+
+ return await fetch(`${STORAGE_URL}/${relativeFilePath}`)
+ } catch (error) {
+ return new Response(JSON.stringify({ error: error.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 400,
+ })
+ }
+}
diff --git a/supabase/functions/lw13-meetup-og/index.ts b/supabase/functions/lw13-meetup-og/index.ts
new file mode 100644
index 00000000000..bf59501dedf
--- /dev/null
+++ b/supabase/functions/lw13-meetup-og/index.ts
@@ -0,0 +1,11 @@
+// Follow this setup guide to integrate the Deno language server with your editor:
+// https://deno.land/manual/getting_started/setup_your_environment
+// This enables autocomplete, go to definition, etc.
+
+import { serve } from 'https://deno.land/[email protected]/http/server.ts'
+
+import { handler } from './handler.tsx'
+
+console.log(`Function "lw13-meetups-ogs" up and running`)
+
+serve(handler)
diff --git a/supabase/functions/lw13-meetups-ogs/README.md b/supabase/functions/lw13-meetups-ogs/README.md
new file mode 100644
index 00000000000..e412c3fb2cd
--- /dev/null
+++ b/supabase/functions/lw13-meetups-ogs/README.md
@@ -0,0 +1,22 @@
+# Open Graph (OG) Image Generation with Supabase Storage CDN Caching
+
+Generate Open Graph images with Deno and Supabase Edge Functions and cache the generated image with Supabase Storage CDN.
+
+- Docs: https://deno.land/x/[email protected]
+- Examples: https://vercel.com/docs/concepts/functions/edge-functions/og-image-examples
+- Demo: https://obuldanrptloktxcffvn.supabase.co/functions/v1/lw13-meetups-ogs?username=thorwebdev
+
+## Run locally
+
+```bash
+supabase start
+supabase functions serve lw13-meetups-ogs --no-verify-jwt --env-file ./supabase/.env.local
+```
+
+Navigate to http://localhost:54321/functions/v1/lw13-meetups-ogs
+
+## Deploy
+
+```bash
+supabase functions deploy lw13-meetups-ogs --no-verify-jwt
+```
diff --git a/supabase/functions/lw13-meetups-ogs/handler.tsx b/supabase/functions/lw13-meetups-ogs/handler.tsx
new file mode 100644
index 00000000000..e1d484c6292
--- /dev/null
+++ b/supabase/functions/lw13-meetups-ogs/handler.tsx
@@ -0,0 +1,71 @@
+import { createClient } from 'jsr:@supabase/supabase-js@2'
+import { normalizeString } from '../common/helpers.ts'
+
+const corsHeaders = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
+}
+
+const SUPABASE_URL =
+ Deno.env.get('SUPABASE_URL') !== 'http://kong:8000'
+ ? Deno.env.get('SUPABASE_URL')
+ : 'http://host.docker.internal:54321'
+
+const STORAGE_BASE_PATH = `launch-week/lw13`
+const STORAGE_URL = `${SUPABASE_URL}/storage/v1/object/public/images/${STORAGE_BASE_PATH}`
+const MEETUPS_TABLE = 'meetups'
+
+export async function handler(_req: Request) {
+ try {
+ const supabaseAdminClient = createClient(
+ // Supabase API URL - env var exported by default when deployed.
+ Deno.env.get('LIVE_SUPABASE_URL') ?? 'http://host.docker.internal:54321',
+ // Supabase API SERVICE ROLE KEY - env var exported by default when deployed.
+ Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''
+ )
+
+ // Get meetups data
+ const { data: meetups, error } = await supabaseAdminClient
+ .from(MEETUPS_TABLE)
+ .select('id, city, country, start_at, timezone')
+ .eq('launch_week', 'lw13')
+
+ if (error) console.log('fetch error', error.message)
+ if (!meetups) throw new Error(`No meetups found`)
+
+ interface MeetupRes {
+ country: string
+ city: string
+ og: string
+ }
+ const response: MeetupRes[] = []
+
+ meetups.map(async (meetup) => {
+ const normalizedCountry = normalizeString(meetup.country)
+ const normalizedCity = normalizeString(meetup.city)
+
+ response.push({
+ country: normalizedCountry,
+ city: normalizedCity,
+ og: `${STORAGE_URL}/og/meetups/${normalizedCountry}-${normalizedCity}-${meetup.id}.png`,
+ })
+ await fetch(`${SUPABASE_URL}/functions/v1/lw13-meetup-og?id=${meetup.id}`)
+ })
+
+ return new Response(
+ JSON.stringify({
+ bucket_path: `${STORAGE_URL}/og/meetups`,
+ meetups: response,
+ }),
+ {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 200,
+ }
+ )
+ } catch (error) {
+ return new Response(JSON.stringify({ error: error.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 400,
+ })
+ }
+}
diff --git a/supabase/functions/lw13-meetups-ogs/index.ts b/supabase/functions/lw13-meetups-ogs/index.ts
new file mode 100644
index 00000000000..bf59501dedf
--- /dev/null
+++ b/supabase/functions/lw13-meetups-ogs/index.ts
@@ -0,0 +1,11 @@
+// Follow this setup guide to integrate the Deno language server with your editor:
+// https://deno.land/manual/getting_started/setup_your_environment
+// This enables autocomplete, go to definition, etc.
+
+import { serve } from 'https://deno.land/[email protected]/http/server.ts'
+
+import { handler } from './handler.tsx'
+
+console.log(`Function "lw13-meetups-ogs" up and running`)
+
+serve(handler)
diff --git a/supabase/migrations/20241121205753_add_meetups_columns.sql b/supabase/migrations/20241121205753_add_meetups_columns.sql
new file mode 100644
index 00000000000..abb5858c6c5
--- /dev/null
+++ b/supabase/migrations/20241121205753_add_meetups_columns.sql
@@ -0,0 +1,5 @@
+alter table public.meetups
+add column timezone text;
+
+alter table public.meetups
+add column city text;
\ No newline at end of file