Files
pawol.nu/pages/teks/[slug].js
T

45 lines
1.0 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types'
2020-12-18 22:08:34 +01:00
import {jwennTeksEpiSlug, jwennTeks} from '../../lib/oki-api'
import TeksDrawer from '../../components/teks/teks-drawer'
2020-12-15 23:46:05 +01:00
import HeadLayout from '../../components/head-layout'
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)
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>
)
}
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-18 22:08:34 +01:00
if (!anTeks) {
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-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
}