diff --git a/pages/community/index.page.tsx b/pages/community/index.page.tsx index d68d6deb8..c609395d4 100644 --- a/pages/community/index.page.tsx +++ b/pages/community/index.page.tsx @@ -40,9 +40,23 @@ export const getStaticProps: GetStaticProps = async () => { const remoteICalUrl = 'https://calendar.google.com/calendar/ical/json.schema.community%40gmail.com/public/basic.ics'; - const datesInfo = await fetchRemoteICalFile(remoteICalUrl) - .then((icalData: any) => printEventsForNextWeeks(ical.parseICS(icalData))) - .catch((error) => console.error('Error:', error)); + let datesInfo: Array<{ + title: string; + time: string; + day: string; + timezone: string; + parsedStartDate: string; + }> = []; + try { + const icalData = await fetchRemoteICalFile(remoteICalUrl); + if (icalData) { + const parsedData = ical.parseICS(icalData); + datesInfo = printEventsForNextWeeks(parsedData) || []; + } + } catch (error) { + console.error('Error processing calendar data:', error); + // datesInfo defaults to empty array to prevent crashes + } return { props: { blogPosts, @@ -53,8 +67,11 @@ export const getStaticProps: GetStaticProps = async () => { }; export default function communityPages(props: any) { - const blogPosts = props.blogPosts; - const timeToRead = Math.ceil(readingTime(blogPosts[0].content).minutes); + const blogPosts = props.blogPosts || []; + const firstBlogPost = blogPosts[0]; + const timeToRead = firstBlogPost + ? Math.ceil(readingTime(firstBlogPost.content).minutes) + : 0; return ( @@ -248,7 +265,7 @@ export default function communityPages(props: any) {

Upcoming events

- {props.datesInfo.map((event: any, index: any) => ( + {(props.datesInfo || []).map((event: any, index: any) => (
-
-
- - {blogPosts[0].frontmatter.title} -

- {blogPosts[0].frontmatter.title} -

-
- +
+ + {firstBlogPost.frontmatter.title} -
-
- {(blogPosts[0].frontmatter.authors || []).map( - (author: any, index: number) => { - return ( -
- ); - }, - )} -
-

- {blogPosts[0].frontmatter.authors.length > 2 ? ( - <> - {blogPosts[0].frontmatter.authors - .slice(0, 2) - .map((author: any, index: number) => ( - - {author.name} - {index === 0 && ' & '} - - ))} - {'...'} - - ) : ( - blogPosts[0].frontmatter.authors.map( - (author: any) => ( - {author.name} - ), - ) - )} -

-
- - {blogPosts[0].frontmatter.date} ·{timeToRead}{' '} - min min read - +

+ {firstBlogPost.frontmatter.title} +

+
+ +
+
+ {(firstBlogPost.frontmatter.authors || []).map( + (author: any, index: number) => { + return ( +
+ ); + }, + )} +
+

+ {firstBlogPost.frontmatter.authors && + firstBlogPost.frontmatter.authors.length > 2 ? ( + <> + {firstBlogPost.frontmatter.authors + .slice(0, 2) + .map((author: any, index: number) => ( + + {author.name} + {index === 0 && ' & '} + + ))} + {'...'} + + ) : ( + firstBlogPost.frontmatter.authors?.map( + (author: any) => ( + {author.name} + ), + ) || [] + )} +

+
+ + {firstBlogPost.frontmatter.date} · + {timeToRead} min min read + +
-
- -
- - Read more posts +
+ + Read more posts + +
-
+ )}
diff --git a/pages/index.page.tsx b/pages/index.page.tsx index bc627b9b5..290abd6c2 100644 --- a/pages/index.page.tsx +++ b/pages/index.page.tsx @@ -49,9 +49,23 @@ export const getStaticProps: GetStaticProps = async () => { .slice(0, 5); const remoteICalUrl = 'https://calendar.google.com/calendar/ical/info%40json-schema.org/public/basic.ics'; - const datesInfo = await fetchRemoteICalFile(remoteICalUrl) - .then((icalData: any) => printEventsForNextWeeks(ical.parseICS(icalData))) - .catch((error) => console.error('Error:', error)); + let datesInfo: Array<{ + title: string; + time: string; + day: string; + timezone: string; + parsedStartDate: string; + }> = []; + try { + const icalData = await fetchRemoteICalFile(remoteICalUrl); + if (icalData) { + const parsedData = ical.parseICS(icalData); + datesInfo = printEventsForNextWeeks(parsedData) || []; + } + } catch (error) { + console.error('Error processing calendar data:', error); + // datesInfo defaults to empty array to prevent crashes + } return { props: { blogPosts, @@ -89,8 +103,11 @@ export function AlgoliaSearch() { ); } const Home = (props: any) => { - const blogPosts = props.blogPosts; - const timeToRead = Math.ceil(readingTime(blogPosts[0].content).minutes); + const blogPosts = props.blogPosts || []; + const firstBlogPost = blogPosts[0]; + const timeToRead = firstBlogPost + ? Math.ceil(readingTime(firstBlogPost.content).minutes) + : 0; const { resolvedTheme } = useTheme(); const [asyncapi_logo, setAsyncapi_logo] = useState(''); @@ -429,89 +446,94 @@ const Home = (props: any) => {
{/* BlogPost Data */} -
- -

- The JSON Schema Blog -

- {isClient && ( - <> - blog + +

+ The JSON Schema Blog +

+ {isClient && ( + <> + blog + + )} +

+ {' '} + {firstBlogPost.frontmatter.title} +

+
+ - - )} -

- {' '} - {blogPosts[0].frontmatter.title} -

-
- -
+
-
- {(blogPosts[0].frontmatter.authors || []).map( - (author: any, index: number) => { - return ( -
- ); - }, - )} -
-

- {blogPosts[0].frontmatter.authors.length > 2 ? ( - <> - {blogPosts[0].frontmatter.authors - .slice(0, 2) - .map((author: any, index: number) => ( - - {author.name} - {index === 0 && ' & '} - - ))} - {'...'} - - ) : ( - blogPosts[0].frontmatter.authors.map((author: any) => ( - {author.name} - )) - )} -

+
+ {(firstBlogPost.frontmatter.authors || []).map( + (author: any, index: number) => { + return ( +
+ ); + }, + )} +
+

+ {firstBlogPost.frontmatter.authors && + firstBlogPost.frontmatter.authors.length > 2 ? ( + <> + {firstBlogPost.frontmatter.authors + .slice(0, 2) + .map((author: any, index: number) => ( + + {author.name} + {index === 0 && ' & '} + + ))} + {'...'} + + ) : ( + firstBlogPost.frontmatter.authors?.map( + (author: any) => ( + {author.name} + ), + ) || [] + )} +

-
- - {blogPosts[0].frontmatter.date} · {timeToRead}{' '} - min read - +
+ + {firstBlogPost.frontmatter.date} · {timeToRead}{' '} + min read + +
-
- - -
- - Read more{' '} + +
+ + Read more{' '} + +
-
+ )}

@@ -546,7 +568,7 @@ const Home = (props: any) => { Upcoming events
    - {props.datesInfo.map((event: any, index: any) => ( + {(props.datesInfo || []).map((event: any, index: any) => (