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

76 lines
1.9 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types'
2021-06-26 12:17:54 +02:00
import {jwennTeksEpiSlug, jwennTeks, jwennKomanteEpiTeksId} 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(', ')
}
2021-06-26 12:17:54 +02:00
export default function SlugTeks({teks, anTeks, slug, komante}) {
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-05-28 19:41:13 +02:00
const formatKouveti = () => {
if (!kouveti) {
return null
}
2021-06-03 19:19:22 +02:00
if (kouveti && kouveti.formats && kouveti.formats.large) {
return kouveti.formats.large
2021-05-28 19:41:13 +02:00
}
2021-05-28 20:04:36 +02:00
if (kouveti && kouveti.formats && kouveti.formats.medium) {
return kouveti.formats.medium
}
2021-06-03 19:19:22 +02:00
if (kouveti && kouveti.formats && kouveti.formats.small) {
return kouveti.formats.small
2021-05-28 20:04:36 +02:00
}
2021-05-28 19:41:13 +02:00
return kouveti
}
2021-03-07 15:18:58 +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}
2021-09-29 18:59:31 +02:00
title={`${awtis} - ${anTeks.tit}`} tab={1} slug={`teks/${slug}`}
2021-05-28 18:29:15 +02:00
>
2021-06-26 12:17:54 +02:00
<TeksDrawer teks={teks} anTeks={anTeks} komante={komante} />
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')
}
2021-06-26 12:17:54 +02:00
const {_id} = anTeks
const komante = await jwennKomanteEpiTeksId(_id)
return {
props: {
2020-12-18 22:08:34 +01:00
teks,
2020-12-24 13:39:07 +01:00
anTeks,
2021-06-26 12:17:54 +02:00
slug,
komante
}
}
}
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,
2021-06-26 12:17:54 +02:00
slug: PropTypes.string.isRequired,
komante: PropTypes.array.isRequired
}