import Head from 'next/head' import { App } from 'src/components/App' import { Article } from 'src/components/Article' import { Meta } from 'src/components/Meta' import { meta } from 'src/lib/meta' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage } from 'next' import { IMeta } from 'src/types' import { Html } from 'src/components/Html' interface IProps { title: string meta: IMeta person: any } const Index: NextPage = props => { if (!props?.person?.post) { console.log('kek error', props) return null } return ( {props.title} {!props.person.post ? null : (
)}
) } export const unstable_getStaticProps = async (ctx: any) => { console.log('call unstable_getStaticProps', ctx) // const id = ctx.query.person // const id = ctx.params.person ?? 'va-sarzhin' const id = ctx.params.person //?? 'mg-timasheva' if (!id) { throw new Error('sry') } const person = await requestGet(createApiUrl(`/api/persons/${id}`), null) const name = person.name || [] const title = name.join(' ') const image = person.preview ? person.preview.artifacts.fb : {} if (!person?.post) { throw new Error(`post kek ${id}`) } return { props: { person, title, meta: meta({ title, image: image.src, imageWidth: image.width, imageHeight: image.height, }) } } } export const unstable_getStaticPaths = async () => { console.log('call unstable_getStaticPaths') const urls = await requestGet>(createApiUrl(`/api/persons/urls`), null) // const urls = {items: ['/teacher/va-sarzhin']} return { paths: urls.items .map(x => x.replace('/teacher/', '')) .map(person => ({ params: { person, }, })), } } export default Index