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 { MetaBuilder } from 'src/lib/meta'
|
||||||
import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
||||||
import { NextPage } from 'next'
|
import { NextPage } from 'next'
|
||||||
import { IMeta } from 'src/types'
|
import { IMeta, ImageArtifact, ImageDefinition } from 'src/types'
|
||||||
import { Html } from 'src/components/Html'
|
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 {
|
interface IProps {
|
||||||
title: string
|
title: string
|
||||||
meta: IMeta
|
meta: IMeta
|
||||||
@@ -52,22 +68,13 @@ export const unstable_getStaticProps = async (ctx: any) => {
|
|||||||
throw new Error('sry')
|
throw new Error('sry')
|
||||||
}
|
}
|
||||||
|
|
||||||
const person = await requestGet<any>(createApiUrl(`/api/persons/${id}`), null)
|
const person = await requestGet<Person>(createApiUrl(`/api/persons/${id}`), null)
|
||||||
const name = person.name || []
|
|
||||||
const title = name.join(' ')
|
|
||||||
const image = person.preview ? person.preview.artifacts.fb : {}
|
|
||||||
|
|
||||||
if (!person?.post) {
|
if (!person?.post) {
|
||||||
throw new Error(`post kek ${id}`)
|
throw new Error(`post kek ${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const title = person.name.join(' ')
|
||||||
const meta = (new MetaBuilder())
|
const meta = (new MetaBuilder())
|
||||||
.setData({
|
|
||||||
title,
|
|
||||||
image: image.src,
|
|
||||||
imageWidth: image.width,
|
|
||||||
imageHeight: image.height,
|
|
||||||
})
|
|
||||||
.setImage(person.preview)
|
.setImage(person.preview)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setDescription(person.position)
|
.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 {
|
export function meta(props: Partial<IMeta>): IMeta {
|
||||||
const path = props.url || '/'
|
const path = props.url || '/'
|
||||||
@@ -25,7 +25,7 @@ export function meta(props: Partial<IMeta>): IMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MetaBuilder {
|
export class MetaBuilder {
|
||||||
private image: IImage
|
private image: ImageDefinition
|
||||||
private title: string
|
private title: string
|
||||||
private description: string
|
private description: string
|
||||||
private data: Partial<IMeta>
|
private data: Partial<IMeta>
|
||||||
@@ -45,14 +45,22 @@ export class MetaBuilder {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setImage(param: IImage) {
|
setImage(param: ImageDefinition) {
|
||||||
this.image = param
|
this.image = param
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
const artifact = this.image.artifacts.fb
|
||||||
|
const image = {
|
||||||
|
image: artifact.src,
|
||||||
|
imageWidth: artifact.width,
|
||||||
|
imageHeight: artifact.height,
|
||||||
|
}
|
||||||
|
|
||||||
return meta({
|
return meta({
|
||||||
...this.data,
|
...this.data,
|
||||||
|
...image,
|
||||||
title: this.title,
|
title: this.title,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user