Skip to content

Commit

Permalink
feat: store upcoming conferences in sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 18, 2024
1 parent d639d3d commit 1779871
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 23 deletions.
39 changes: 39 additions & 0 deletions cms/schemaTypes/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineField, defineType } from 'sanity'

export default defineType({
name: 'event',
title: 'Conference or meetup',
type: 'document',
fields: [
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'date',
title: 'Date',
type: 'date',
}),
defineField({
name: 'endDate',
title: 'End date (for multi-day events)',
type: 'date',
}),
defineField({
name: 'link',
title: 'Link',
type: 'url',
}),
defineField({
name: 'location',
title: 'Location',
type: 'string',
}),
defineField({
name: 'image',
title: 'Image',
type: 'image',
}),
],
})
3 changes: 2 additions & 1 deletion cms/schemaTypes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ama from './ama'
import event from './event'

export const schemaTypes = [ama]
export const schemaTypes = [ama, event]
58 changes: 36 additions & 22 deletions server/api/upcoming-conferences.get.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
import { imageMeta } from 'image-meta'

const upcomingConferences: Array<{
const eventQuery = groq`
*[_type == 'event' && date > now()] {
name,
"dates": date,
endDate,
link,
location,
"image": image.asset->{
"height": metadata.dimensions.height,
"width": metadata.dimensions.width,
url
}
} | order(date)
`

interface Event {
name: string
dates: string
endDate?: string
link: string
location: string
image?: {
url: string
width: number
height: number
}
location: string
}> = [
{
name: 'DevFest Scotland',
dates: '30 November',
link: 'https://gdg.community.dev/events/details/google-gdg-glasgow-presents-devfest-scotland-2024-1/cohost-gdg-glasgow',
location: '🏴󠁧󠁢󠁳󠁣󠁴󠁿',
},
{
name: 'DundeeScript Meetup',
dates: '10 December',
link: 'https://www.eventbrite.co.uk/e/dundeescript-meetup-tickets-1038765113417',
location: '🏴󠁧󠁢󠁳󠁣󠁴󠁿',
image: {
url: 'https://www.dundeescript.co.uk/images/dundeescript-logo.png',
width: 684,
height: 466,
},
},
]
}

export default defineCachedEventHandler(async () => {
export default defineEventHandler(async event => {
if (!import.meta.dev && !import.meta.prerender) return []

const sanity = useSanity(event)

const upcomingConferences = await sanity.client.fetch<Event[]>(eventQuery)

console.log(upcomingConferences)
const formatter = new Intl.DateTimeFormat('en', {
month: 'long',
day: 'numeric',
})

return Promise.all(
upcomingConferences.map(async conference => {
let dates = formatter.format(new Date(conference.dates))
if (conference.endDate) {
dates += ` - ${formatter.format(new Date(conference.endDate))}`
delete conference.endDate
}
conference.dates = dates
if (conference.image) {
return conference as Omit<typeof conference, 'image'> & { image: NonNullable<typeof conference.image> }
}
Expand Down

0 comments on commit 1779871

Please sign in to comment.