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

51 lines
1.2 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:22:56 +01:00
const awtis = anTeks.awtis.length === 1 ? anTeks.awtis[0].alias : jwennAwtis(anTeks.awtis)
2021-05-28 18:29:15 +02:00
const {kouveti} = anTeks
2021-03-07 15:18:58 +01:00
return (
2021-05-28 18:29:15 +02:00
<HeadLayout
imageWidth={kouveti ? kouveti.formats.thumbnail.width : null}
imageHeight={kouveti ? kouveti.formats.thumbnail.height : null}
imageUrl={kouveti ? kouveti.formats.thumbnail.url : null}
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
}