2020-12-13 23:20:07 +01:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
2022-05-22 00:17:28 +04:00
|
|
|
import {getAlias} from '../../lib/utils/format'
|
2022-10-30 21:05:21 +04:00
|
|
|
import {jwennTeksEpiSlug} from '../../lib/oki-api'
|
2020-12-13 23:20:07 +01:00
|
|
|
|
2020-12-15 23:46:05 +01:00
|
|
|
import HeadLayout from '../../components/head-layout'
|
2022-05-22 22:21:10 +04:00
|
|
|
import TeksDrawer from '../../components/teks/teks-drawer'
|
2020-12-13 23:20:07 +01:00
|
|
|
|
2022-05-14 03:37:04 +04:00
|
|
|
import Custom500 from '../500'
|
|
|
|
|
import Custom404 from '../404'
|
|
|
|
|
|
2022-05-22 22:21:10 +04:00
|
|
|
export default function SlugTeks({hasError, errorMessage, parole, slug}) {
|
2022-05-14 03:37:04 +04:00
|
|
|
if (hasError) {
|
|
|
|
|
console.log('⚠️ error :', errorMessage)
|
|
|
|
|
return <Custom500 />
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 02:15:56 +04:00
|
|
|
if (!parole) {
|
2022-05-14 03:37:04 +04:00
|
|
|
return <Custom404 />
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 00:17:28 +04:00
|
|
|
const artistes = parole.attributes.artistes.length === 1 ? parole.attributes.artistes[0].data.attributes.alias : getAlias(parole.attributes.artistes, parole.attributes.prioriteArtistes)
|
2022-05-20 02:15:56 +04:00
|
|
|
const {couverture} = parole.attributes
|
2021-05-28 19:41:13 +02:00
|
|
|
const formatKouveti = () => {
|
2022-05-20 04:40:17 +04:00
|
|
|
if (!couverture?.data?.attributes) {
|
2021-05-28 19:41:13 +02:00
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 04:40:17 +04:00
|
|
|
if (couverture.data.attributes && couverture.data.attributes.formats && couverture.data.attributes.formats.large) {
|
2022-05-21 16:57:34 +04:00
|
|
|
return couverture.data.attributes.formats.large
|
2021-05-28 19:41:13 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 04:40:17 +04:00
|
|
|
if (couverture.data.attributes && couverture.data.attributes.formats && couverture.data.attributes.formats.medium) {
|
2022-05-21 16:57:34 +04:00
|
|
|
return couverture.data.attributes.formats.medium
|
2021-05-28 20:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 04:40:17 +04:00
|
|
|
if (couverture.data.attributes && couverture.data.attributes.formats && couverture.data.attributes.formats.small) {
|
2022-05-20 04:52:30 +04:00
|
|
|
return couverture.data.attributes.formats.small
|
2021-05-28 20:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 04:40:17 +04:00
|
|
|
return couverture.data.attributes
|
2021-05-28 19:41:13 +02:00
|
|
|
}
|
2021-03-07 15:18:58 +01:00
|
|
|
|
2020-12-13 23:20:07 +01:00
|
|
|
return (
|
2021-05-28 18:29:15 +02:00
|
|
|
<HeadLayout
|
2021-05-28 19:41:13 +02:00
|
|
|
imageUrl={formatKouveti() ? formatKouveti().url : null}
|
|
|
|
|
imageWidth={formatKouveti() ? formatKouveti().width : null}
|
|
|
|
|
imageHeight={formatKouveti() ? formatKouveti().height : null}
|
2021-05-28 20:15:26 +02:00
|
|
|
imageMime={formatKouveti() ? formatKouveti().mime : null}
|
2022-05-20 02:15:56 +04:00
|
|
|
title={`${artistes} - ${parole.attributes.titre} | Paroles et Traductions`} tab={1} slug={`paroles/${slug}`}
|
2021-05-28 18:29:15 +02:00
|
|
|
>
|
2022-05-22 22:21:10 +04:00
|
|
|
<TeksDrawer parole={parole.attributes} paroleId={parole.id} slug={slug} />
|
2020-12-15 23:46:05 +01:00
|
|
|
</HeadLayout>
|
2020-12-13 23:20:07 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getServerSideProps({query}) {
|
|
|
|
|
const {slug} = query
|
2022-05-20 02:15:56 +04:00
|
|
|
let paroles
|
|
|
|
|
let parole
|
2022-05-14 03:37:04 +04:00
|
|
|
let hasError
|
|
|
|
|
let errorMessage
|
2020-12-13 23:20:07 +01:00
|
|
|
|
2022-05-14 03:37:04 +04:00
|
|
|
try {
|
2022-10-30 21:05:21 +04:00
|
|
|
parole = await jwennTeksEpiSlug(slug)
|
2022-05-14 03:37:04 +04:00
|
|
|
} catch (error) {
|
|
|
|
|
errorMessage = error
|
|
|
|
|
hasError = true
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
props: {
|
2022-05-14 03:37:04 +04:00
|
|
|
hasError: hasError || null,
|
|
|
|
|
errorMessage: errorMessage ? errorMessage.message : null,
|
2022-05-20 02:15:56 +04:00
|
|
|
paroles: paroles || null,
|
|
|
|
|
parole: parole || null,
|
2022-05-22 22:21:10 +04:00
|
|
|
slug
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 03:37:04 +04:00
|
|
|
SlugTeks.defaultProps = {
|
|
|
|
|
hasError: null,
|
|
|
|
|
errorMessage: null,
|
2022-05-22 22:21:10 +04:00
|
|
|
parole: null
|
2022-05-14 03:37:04 +04:00
|
|
|
}
|
|
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
SlugTeks.propTypes = {
|
2022-05-14 03:37:04 +04:00
|
|
|
hasError: PropTypes.bool,
|
|
|
|
|
errorMessage: PropTypes.string,
|
2022-05-20 02:15:56 +04:00
|
|
|
parole: PropTypes.object,
|
2021-06-26 12:17:54 +02:00
|
|
|
slug: PropTypes.string.isRequired,
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|