2020-12-13 23:20:07 +01:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
import {jwennTeksEpiSlug, jwennTeks} from '../../lib/oki-api'
|
2020-12-13 23:20:07 +01:00
|
|
|
|
|
|
|
|
import TeksDrawer from '../../components/teks/teks-drawer'
|
2020-12-15 23:46:05 +01:00
|
|
|
import HeadLayout from '../../components/head-layout'
|
2020-12-13 23:20:07 +01:00
|
|
|
|
2021-03-07 15:18:58 +01:00
|
|
|
const jwennAwtis = awtis => {
|
|
|
|
|
return awtis.map(a => a.alias).join(', ')
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 13:39:07 +01:00
|
|
|
export default function SlugTeks({teks, anTeks, slug}) {
|
2021-03-07 15:18:58 +01:00
|
|
|
const awtis = anTeks.awtis.length === 1 ? anTeks.awtis.alias : jwennAwtis(anTeks.awtis)
|
|
|
|
|
|
2020-12-13 23:20:07 +01:00
|
|
|
return (
|
2021-03-07 15:18:58 +01:00
|
|
|
<HeadLayout title={`${awtis} - ${anTeks.tit}`} tab={2} slug={`teks/${slug}`}>
|
2020-12-18 22:08:34 +01:00
|
|
|
<TeksDrawer teks={teks} anTeks={anTeks} />
|
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
|
2020-12-18 22:08:34 +01:00
|
|
|
const teks = await jwennTeks()
|
|
|
|
|
const anTeks = await jwennTeksEpiSlug(slug)
|
2020-12-13 23:20:07 +01:00
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
if (!anTeks) {
|
2020-12-13 23:20:07 +01:00
|
|
|
throw new Error('San répons')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
props: {
|
2020-12-18 22:08:34 +01:00
|
|
|
teks,
|
2020-12-24 13:39:07 +01:00
|
|
|
anTeks,
|
|
|
|
|
slug
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
SlugTeks.propTypes = {
|
|
|
|
|
teks: PropTypes.array.isRequired,
|
2020-12-24 13:39:07 +01:00
|
|
|
anTeks: PropTypes.object.isRequired,
|
|
|
|
|
slug: PropTypes.string.isRequired
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|