import Head from 'next/head' import { App } from 'src/components/App' import Article from 'src/components/Article' import { Meta } from 'src/components/Meta' import menuModel from 'src/models/menu' import { buildMenu } from 'src/lib/menu' import { meta } from 'src/lib/meta' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage, NextPageContext } from 'next' import { IMeta } from 'src/types' import Html from 'src/components/Html' interface IProps { pageUrl: string 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 pageUrl = '/collective' // 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: any = await requestGet(createApiUrl(ctx.req, `/api/persons/${id}`), {}) const person: any = await requestGet(`http://localhost:3000/api/persons/${id}`, {}) 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: { pageUrl, 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>(`http://localhost:3000/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