diff --git a/pages/teacher/[person].tsx b/pages/teacher/[person].tsx index 7957556e..8cd36744 100644 --- a/pages/teacher/[person].tsx +++ b/pages/teacher/[person].tsx @@ -5,9 +5,25 @@ import { Meta } from 'src/components/Meta' import { MetaBuilder } from 'src/lib/meta' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage } from 'next' -import { IMeta } from 'src/types' +import { IMeta, ImageArtifact, ImageDefinition } from 'src/types' import { Html } from 'src/components/Html' +type Person = { + id: string + position: string + name: [string, string, string] + post: string + diploma: string + edu: string + file: string + hash: string + shortName: string + status: string + url: string + picture: ImageArtifact + preview: ImageDefinition +} + interface IProps { title: string meta: IMeta @@ -52,22 +68,13 @@ export const unstable_getStaticProps = async (ctx: any) => { 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 : {} - + const person = await requestGet(createApiUrl(`/api/persons/${id}`), null) if (!person?.post) { throw new Error(`post kek ${id}`) } + const title = person.name.join(' ') const meta = (new MetaBuilder()) - .setData({ - title, - image: image.src, - imageWidth: image.width, - imageHeight: image.height, - }) .setImage(person.preview) .setTitle(title) .setDescription(person.position) diff --git a/src/lib/meta.ts b/src/lib/meta.ts index a4327842..db518e94 100644 --- a/src/lib/meta.ts +++ b/src/lib/meta.ts @@ -1,4 +1,4 @@ -import { IMeta, IImage } from 'src/types' +import { IMeta, IImage, ImageDefinition } from 'src/types' export function meta(props: Partial): IMeta { const path = props.url || '/' @@ -25,7 +25,7 @@ export function meta(props: Partial): IMeta { } export class MetaBuilder { - private image: IImage + private image: ImageDefinition private title: string private description: string private data: Partial @@ -45,14 +45,22 @@ export class MetaBuilder { return this } - setImage(param: IImage) { + setImage(param: ImageDefinition) { this.image = param return this } build() { + const artifact = this.image.artifacts.fb + const image = { + image: artifact.src, + imageWidth: artifact.width, + imageHeight: artifact.height, + } + return meta({ ...this.data, + ...image, title: this.title, description: this.description, })