meta builder; person page refactoring
This commit is contained in:
1 parent
3f8941b613
commit
dbf09f608a
2 files changed
+30
-15
No files matched your search
+19
-12
@@ -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<any>(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<Person>(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)
|
||||
|
||||
+11
-3
@@ -1,4 +1,4 @@
|
||||
import { IMeta, IImage } from 'src/types'
|
||||
import { IMeta, IImage, ImageDefinition } from 'src/types'
|
||||
|
||||
export function meta(props: Partial<IMeta>): IMeta {
|
||||
const path = props.url || '/'
|
||||
@@ -25,7 +25,7 @@ export function meta(props: Partial<IMeta>): IMeta {
|
||||
}
|
||||
|
||||
export class MetaBuilder {
|
||||
private image: IImage
|
||||
private image: ImageDefinition
|
||||
private title: string
|
||||
private description: string
|
||||
private data: Partial<IMeta>
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user