mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 05:39:11 +03:00
cms events
This commit is contained in:
1 parent
272e7fee1f
commit
af8ec8a4eb
2 files changed
+75
-82
No files matched your search
@@ -97,9 +97,8 @@ const EventPage = ({ event }: InferGetStaticPropsType<typeof getStaticProps>) =>
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const staticPaths = getAllPostSlugs('_events')
|
||||
// const cmsPaths = await getAllCMSEventSlugs()
|
||||
// const paths = [...staticPaths, ...cmsPaths]
|
||||
const paths = [...staticPaths]
|
||||
const cmsPaths = await getAllCMSEventSlugs()
|
||||
const paths = [...staticPaths, ...cmsPaths]
|
||||
|
||||
return {
|
||||
paths,
|
||||
@@ -131,9 +130,8 @@ export const getStaticProps: GetStaticProps<EventPageProps, Params> = async ({
|
||||
|
||||
// Get all posts for navigation and related posts
|
||||
const allStaticEvents = getSortedPosts({ directory: '_events' })
|
||||
// const allCmsEvents = await getAllCMSEvents()
|
||||
// const allPosts = [...allStaticEvents, ...allCmsEvents].sort(
|
||||
const allPosts = [...allStaticEvents].sort(
|
||||
const allCmsEvents = await getAllCMSEvents()
|
||||
const allPosts = [...allStaticEvents, ...allCmsEvents].sort(
|
||||
(a: any, b: any) => new Date(b.date).getTime() - new Date(a.date).getTime()
|
||||
)
|
||||
const currentIndex = allPosts.findIndex((post) => post.slug === slug)
|
||||
@@ -168,61 +166,59 @@ export const getStaticProps: GetStaticProps<EventPageProps, Params> = async ({
|
||||
console.log('[getStaticProps] Static post not found, trying CMS post...')
|
||||
}
|
||||
|
||||
return { notFound: true }
|
||||
|
||||
// Try CMS post (handle preview/draft logic)
|
||||
// const cmsPost = await getCMSEventBySlug(slug, preview)
|
||||
const cmsPost = await getCMSEventBySlug(slug, preview)
|
||||
|
||||
// if (!cmsPost) {
|
||||
// // Try to fetch published version if preview mode failed
|
||||
// if (preview) {
|
||||
// const publishedPost = await getCMSEventBySlug(slug, false)
|
||||
// if (!publishedPost) {
|
||||
// return { notFound: true }
|
||||
// }
|
||||
// const mdxSource = await mdxSerialize(publishedPost.content || '')
|
||||
if (!cmsPost) {
|
||||
// Try to fetch published version if preview mode failed
|
||||
if (preview) {
|
||||
const publishedPost = await getCMSEventBySlug(slug, false)
|
||||
if (!publishedPost) {
|
||||
return { notFound: true }
|
||||
}
|
||||
const mdxSource = await mdxSerialize(publishedPost.content || '')
|
||||
|
||||
// const eventData: Event & EventData = {
|
||||
// ...(publishedPost as any),
|
||||
// tags: publishedPost.tags || [],
|
||||
// authors: publishedPost.authors || [],
|
||||
// isCMS: true,
|
||||
// content: mdxSource,
|
||||
// image: publishedPost.image ?? undefined,
|
||||
// }
|
||||
const eventData: Event & EventData = {
|
||||
...(publishedPost as any),
|
||||
tags: publishedPost.tags || [],
|
||||
authors: publishedPost.authors || [],
|
||||
isCMS: true,
|
||||
content: mdxSource,
|
||||
image: publishedPost.image ?? undefined,
|
||||
}
|
||||
|
||||
// return {
|
||||
// props: {
|
||||
// prevPost: null,
|
||||
// nextPost: null,
|
||||
// relatedPosts: [],
|
||||
// event: eventData,
|
||||
// },
|
||||
// revalidate: 60 * 10,
|
||||
// }
|
||||
// }
|
||||
// return { notFound: true }
|
||||
// }
|
||||
return {
|
||||
props: {
|
||||
prevPost: null,
|
||||
nextPost: null,
|
||||
relatedPosts: [],
|
||||
event: eventData,
|
||||
},
|
||||
revalidate: 60 * 10,
|
||||
}
|
||||
}
|
||||
return { notFound: true }
|
||||
}
|
||||
|
||||
// const mdxSource = await mdxSerialize(cmsPost.content || '')
|
||||
const mdxSource = await mdxSerialize(cmsPost.content || '')
|
||||
|
||||
// const eventData: Event & EventData = {
|
||||
// ...(cmsPost as any),
|
||||
// tags: cmsPost.tags || [],
|
||||
// authors: cmsPost.authors || [],
|
||||
// isCMS: true,
|
||||
// content: mdxSource,
|
||||
// }
|
||||
const eventData: Event & EventData = {
|
||||
...(cmsPost as any),
|
||||
tags: cmsPost.tags || [],
|
||||
authors: cmsPost.authors || [],
|
||||
isCMS: true,
|
||||
content: mdxSource,
|
||||
}
|
||||
|
||||
// return {
|
||||
// props: {
|
||||
// prevPost: null,
|
||||
// nextPost: null,
|
||||
// relatedPosts: [],
|
||||
// event: eventData,
|
||||
// },
|
||||
// revalidate: 60 * 10,
|
||||
// }
|
||||
return {
|
||||
props: {
|
||||
prevPost: null,
|
||||
nextPost: null,
|
||||
relatedPosts: [],
|
||||
event: eventData,
|
||||
},
|
||||
revalidate: 60 * 10,
|
||||
}
|
||||
}
|
||||
|
||||
export default EventPage
|
||||
@@ -22,7 +22,7 @@ interface Props {
|
||||
|
||||
function Events({ events: staticEvents, onDemandEvents, categories: staticCategories }: Props) {
|
||||
const [lumaEvents, setLumaEvents] = useState<BlogPost[]>([])
|
||||
// const [cmsEvents, setCmsEvents] = useState<BlogPost[]>([])
|
||||
const [cmsEvents, setCmsEvents] = useState<BlogPost[]>([])
|
||||
const [events, setEvents] = useState(staticEvents)
|
||||
const router = useRouter()
|
||||
|
||||
@@ -72,31 +72,29 @@ function Events({ events: staticEvents, onDemandEvents, categories: staticCatego
|
||||
}, [])
|
||||
|
||||
// Fetch CMS events on client-side
|
||||
// useEffect(() => {
|
||||
// const fetchCmsEvents = async () => {
|
||||
// try {
|
||||
// const url = new URL('/api-v2/cms-events', window.location.origin)
|
||||
// const res = await fetch(url.toString())
|
||||
// const data = await res.json()
|
||||
// if (data.success && Array.isArray(data.events)) {
|
||||
// setCmsEvents(data.events)
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error('Error fetching CMS events:', error)
|
||||
// }
|
||||
// }
|
||||
// fetchCmsEvents()
|
||||
// }, [])
|
||||
useEffect(() => {
|
||||
const fetchCmsEvents = async () => {
|
||||
try {
|
||||
const url = new URL('/api-v2/cms-events', window.location.origin)
|
||||
const res = await fetch(url.toString())
|
||||
const data = await res.json()
|
||||
if (data.success && Array.isArray(data.events)) {
|
||||
setCmsEvents(data.events)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching CMS events:', error)
|
||||
}
|
||||
}
|
||||
fetchCmsEvents()
|
||||
}, [])
|
||||
|
||||
// Combine static and Luma events
|
||||
const allEvents = useMemo(() => {
|
||||
// const combined = [...staticEvents, ...cmsEvents, ...lumaEvents]
|
||||
const combined = [...staticEvents, ...lumaEvents]
|
||||
const combined = [...staticEvents, ...cmsEvents, ...lumaEvents]
|
||||
return combined.filter((event: BlogPost) =>
|
||||
event.end_date ? new Date(event.end_date!) >= new Date() : new Date(event.date!) >= new Date()
|
||||
)
|
||||
// }, [staticEvents, cmsEvents, lumaEvents])
|
||||
}, [staticEvents, lumaEvents])
|
||||
}, [staticEvents, cmsEvents, lumaEvents])
|
||||
|
||||
// Keep displayed events in sync with combined list
|
||||
useEffect(() => {
|
||||
@@ -115,17 +113,16 @@ function Events({ events: staticEvents, onDemandEvents, categories: staticCatego
|
||||
})
|
||||
})
|
||||
|
||||
// cmsEvents.forEach((event) => {
|
||||
// updatedCategories.all = (updatedCategories.all || 0) + 1
|
||||
cmsEvents.forEach((event) => {
|
||||
updatedCategories.all = (updatedCategories.all || 0) + 1
|
||||
|
||||
// event.categories?.forEach((category) => {
|
||||
// updatedCategories[category] = (updatedCategories[category] || 0) + 1
|
||||
// })
|
||||
// })
|
||||
event.categories?.forEach((category) => {
|
||||
updatedCategories[category] = (updatedCategories[category] || 0) + 1
|
||||
})
|
||||
})
|
||||
|
||||
return updatedCategories
|
||||
// }, [staticCategories, lumaEvents, cmsEvents])
|
||||
}, [staticCategories, lumaEvents])
|
||||
}, [staticCategories, lumaEvents, cmsEvents])
|
||||
|
||||
const meta_title = 'Supabase Events: webinars, talks, hackathons, and meetups'
|
||||
const meta_description = 'Join Supabase and the open-source community at the upcoming events.'
|
||||
|
||||
Reference in new issue
Block a user