Files
pawol.nu/pages/teks/[slug].js
T
Cédric FAMIBELLE-PRONZOLA 72651a660b Add komante to TeksDrawer
2021-06-26 12:37:59 +02:00

76 lines
1.9 KiB
JavaScript

import PropTypes from 'prop-types'
import {jwennTeksEpiSlug, jwennTeks, jwennKomanteEpiTeksId} from '../../lib/oki-api'
import TeksDrawer from '../../components/teks/teks-drawer'
import HeadLayout from '../../components/head-layout'
const jwennAwtis = awtis => {
return awtis.map(a => a.alias).join(', ')
}
export default function SlugTeks({teks, anTeks, slug, komante}) {
const awtis = anTeks.awtis.length === 1 ? anTeks.awtis[0].alias : jwennAwtis(anTeks.awtis)
const {kouveti} = anTeks
const formatKouveti = () => {
if (!kouveti) {
return null
}
if (kouveti && kouveti.formats && kouveti.formats.large) {
return kouveti.formats.large
}
if (kouveti && kouveti.formats && kouveti.formats.medium) {
return kouveti.formats.medium
}
if (kouveti && kouveti.formats && kouveti.formats.small) {
return kouveti.formats.small
}
return kouveti
}
return (
<HeadLayout
imageUrl={formatKouveti() ? formatKouveti().url : null}
imageWidth={formatKouveti() ? formatKouveti().width : null}
imageHeight={formatKouveti() ? formatKouveti().height : null}
imageMime={formatKouveti() ? formatKouveti().mime : null}
title={`${awtis} - ${anTeks.tit}`} tab={2} slug={`teks/${slug}`}
>
<TeksDrawer teks={teks} anTeks={anTeks} komante={komante} />
</HeadLayout>
)
}
export async function getServerSideProps({query}) {
const {slug} = query
const teks = await jwennTeks()
const anTeks = await jwennTeksEpiSlug(slug)
if (!anTeks) {
throw new Error('San répons')
}
const {_id} = anTeks
const komante = await jwennKomanteEpiTeksId(_id)
return {
props: {
teks,
anTeks,
slug,
komante
}
}
}
SlugTeks.propTypes = {
teks: PropTypes.array.isRequired,
anTeks: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
komante: PropTypes.array.isRequired
}