-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from webmardi/feature/event-seo-page
- Loading branch information
Showing
10 changed files
with
807 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import React, { ReactElement } from 'react'; | ||
import parse from 'react-html-parser'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { GetStaticPaths, GetStaticProps } from 'next'; | ||
import { isNil } from 'ramda'; | ||
|
||
import Layout from 'components/Layout'; | ||
import SEO from 'components/SEO'; | ||
import Sponsors from 'components/Sponsors'; | ||
import { Event } from 'types'; | ||
import { getEvent, getEvents, getLangName } from 'utils'; | ||
|
||
type Props = { | ||
event: Event; | ||
}; | ||
|
||
const Home = ({ event }: Props): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Layout> | ||
<SEO /> | ||
<h1 className="sr-only">{t('homepage.events.title')}</h1> | ||
|
||
<main | ||
className="max-w-3xl px-4 mx-auto my-20" | ||
itemScope | ||
itemType="https://schema.org/Event" | ||
> | ||
<h1 | ||
className="text-xl font-bold col-span-2 md:text-xl lg:text-2xl" | ||
itemProp="name" | ||
> | ||
{event.title} | ||
</h1> | ||
<p className="mt-12"> | ||
{ | ||
parse( | ||
event.seoBody.replace(/\n/gm, '<br /><br />') | ||
) as React.ReactNode | ||
} | ||
</p> | ||
<div className="mt-8 space-y-2"> | ||
{!isNil(event.speakerName) && ( | ||
<div | ||
itemScope | ||
itemProp="performer" | ||
itemType="https://schema.org/Person" | ||
className="flex items-baseline link space-x-4" | ||
> | ||
<h3 className="font-bold">{t('event.speaker')}</h3> | ||
{!isNil(event.speakerName) && isNil(event.speakerLink) && ( | ||
<span itemProp="name"> | ||
{parse(event.speakerName) as ReactElement[]} | ||
</span> | ||
)} | ||
{!isNil(event.speakerName) && !isNil(event.speakerLink) && ( | ||
<a | ||
href={event.speakerLink} | ||
target="_blank" | ||
itemProp="name" | ||
rel="noopener noreferrer" | ||
> | ||
{parse(event.speakerName) as ReactElement[]} | ||
</a> | ||
)} | ||
{!isNil(event.speakerJob) && ( | ||
<span itemProp="jobTitle" className="mt-1"> | ||
{parse(event.speakerJob) as ReactElement[]} | ||
</span> | ||
)} | ||
</div> | ||
)} | ||
{!isNil(event.language) && ( | ||
<div | ||
itemProp="inLanguage" | ||
className="flex items-baseline space-x-4" | ||
> | ||
<h3 className="font-bold">{t('event.lang')}</h3> | ||
<p> | ||
{t('event.be_held')} | ||
{getLangName(event.language)} | ||
</p> | ||
</div> | ||
)} | ||
{!isNil(event.types) && ( | ||
<div | ||
itemProp="inLanguage" | ||
className="flex items-baseline space-x-4" | ||
> | ||
<h3 className="font-bold">{t('event.who')}</h3> | ||
<p> | ||
{event.types?.map(type => ( | ||
<span key={`event-type-${event.title}-${type}`}> | ||
{t(`homepage.events.types.${type}`)} | ||
</span> | ||
))} | ||
</p> | ||
</div> | ||
)} | ||
{!isNil(event.location) && ( | ||
<div | ||
itemProp="inLanguage" | ||
className="flex items-baseline space-x-4" | ||
> | ||
<h3 className="font-bold">{t('event.where')}</h3> | ||
<p itemProp="location"> | ||
{parse(event.location) as ReactElement[]} | ||
</p> | ||
</div> | ||
)} | ||
</div> | ||
|
||
<p className="mt-8">{t('event.youtube')}</p> | ||
|
||
<p className="mt-8"> | ||
{ | ||
parse( | ||
event.seoHashtags.replace(/\n/gm, '<br /><br />') | ||
) as React.ReactNode | ||
} | ||
</p> | ||
</main> | ||
|
||
<Sponsors /> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps = async ({ params }) => { | ||
const event = await getEvent(params?.slug as string); | ||
return isNil(event) | ||
? { notFound: true } | ||
: { | ||
props: { | ||
event, | ||
}, | ||
}; | ||
}; | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
const events: Event[] = await getEvents(); | ||
return { | ||
paths: events | ||
.filter(({ slug }) => !isNil(slug)) | ||
.map(({ slug }) => ({ params: { slug: slug as string } })), | ||
fallback: false, | ||
}; | ||
}; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import axios from 'axios'; | ||
|
||
import { ApiEvents, Event } from 'types'; | ||
import sanitizeEvents from 'utils/sanitizeEvents'; | ||
|
||
const getEvent = async (slug: string): Promise<Event | null> => { | ||
let event: Event | null = null; | ||
|
||
try { | ||
const { results } = await axios | ||
.request({ | ||
method: 'POST', | ||
url: `https://api.notion.com/v1/databases/${process.env.NEXT_PUBLIC_DATABASE_ID}/query`, | ||
headers: { | ||
'Notion-Version': '2021-08-16', | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${process.env.NEXT_PUBLIC_TOKEN}`, | ||
}, | ||
data: { | ||
page_size: 1, | ||
filter: { | ||
property: 'slug', | ||
rich_text: { | ||
equals: slug, | ||
}, | ||
}, | ||
}, | ||
}) | ||
.then(res => { | ||
const data = res.data as unknown as ApiEvents; | ||
return { | ||
results: sanitizeEvents(data.results), | ||
next_cursor: data.next_cursor, | ||
has_more: data.has_more, | ||
}; | ||
}); | ||
|
||
if (results.length > 0) [event] = results; | ||
} catch (error) { | ||
console.log('error', error); | ||
} | ||
|
||
return event; | ||
}; | ||
|
||
export default getEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as getEvents } from './getEvents'; | ||
export { default as getEvent } from './getEvent'; | ||
export { default as sanitizeEvents } from './sanitizeEvents'; | ||
export { default as formatDate } from './formatDate'; | ||
export { default as getLangName } from './getLangName'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.