initial static export in teachers
This commit is contained in:
1 parent
92460592b4
commit
997e44483e
5 files changed
+134
-89
No files matched your search
+14
-12
@@ -9,8 +9,8 @@ import menuModel from 'src/models/menu'
|
||||
import { buildMenu } from 'src/lib/menu'
|
||||
import { meta } from 'src/lib/meta'
|
||||
import { IMeta } from 'src/types'
|
||||
import { createApiUrl, requestGet, wrapInitialProps, IResponseItems } from 'src/next-lib'
|
||||
import { NextPage } from 'next'
|
||||
import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
||||
import { NextPage, NextPageContext } from 'next'
|
||||
|
||||
interface IPerson {
|
||||
|
||||
@@ -60,7 +60,7 @@ const Page: NextPage<Props> = props => (
|
||||
</App>
|
||||
)
|
||||
|
||||
Page.getInitialProps = wrapInitialProps(async (ctx) => {
|
||||
export const unstable_getServerProps = async (ctx: NextPageContext) => {
|
||||
const pageUrl = ctx.req.url
|
||||
|
||||
const res = await requestGet<IResponseItems<IPerson>>(createApiUrl(ctx.req, '/api/persons'), { items: [] })
|
||||
@@ -71,16 +71,18 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => {
|
||||
const image = get(resImage, 'artifacts.large', null)
|
||||
|
||||
return {
|
||||
persons,
|
||||
image,
|
||||
pageUrl,
|
||||
title,
|
||||
meta: meta({
|
||||
props: {
|
||||
persons,
|
||||
image,
|
||||
pageUrl,
|
||||
title,
|
||||
url: pageUrl,
|
||||
description: 'Преподаватели Шлиссельбургской ДХШ',
|
||||
})
|
||||
meta: meta({
|
||||
title,
|
||||
url: pageUrl,
|
||||
description: 'Преподаватели Шлиссельбургской ДХШ',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default Page
|
||||
+81
-38
@@ -5,8 +5,8 @@ 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, wrapInitialProps } from 'src/next-lib'
|
||||
import { NextPage } from 'next'
|
||||
import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
||||
import { NextPage, NextPageContext } from 'next'
|
||||
import { IMeta } from 'src/types'
|
||||
import Html from 'src/components/Html'
|
||||
|
||||
@@ -17,50 +17,93 @@ interface IProps {
|
||||
person: any
|
||||
}
|
||||
|
||||
const Index: NextPage<IProps> = props => (
|
||||
<App
|
||||
menu={buildMenu(props.pageUrl, menuModel)}
|
||||
showAuthor={true}
|
||||
menuPadding={true}
|
||||
layout={'thin'}
|
||||
>
|
||||
<Head>
|
||||
<title>{props.title}</title>
|
||||
<Meta meta={props.meta} />
|
||||
</Head>
|
||||
const Index: NextPage<IProps> = props => {
|
||||
if (!props?.person?.post) {
|
||||
console.log('kek error', props)
|
||||
|
||||
<Article
|
||||
title={''}
|
||||
tags={[]}
|
||||
date={null}
|
||||
shareable={true}
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<App
|
||||
menu={buildMenu(props.pageUrl, menuModel)}
|
||||
showAuthor={true}
|
||||
menuPadding={true}
|
||||
layout={'thin'}
|
||||
>
|
||||
<Html
|
||||
html={props.person.post}
|
||||
/>
|
||||
</Article>
|
||||
</App>
|
||||
)
|
||||
<Head>
|
||||
<title>{props.title}</title>
|
||||
<Meta meta={props.meta} />
|
||||
</Head>
|
||||
|
||||
{!props.person.post ? null : (
|
||||
<Article
|
||||
title={''}
|
||||
tags={[]}
|
||||
date={null}
|
||||
shareable={true}
|
||||
>
|
||||
<Html
|
||||
html={props.person.post}
|
||||
/>
|
||||
</Article>
|
||||
)}
|
||||
</App>
|
||||
)
|
||||
}
|
||||
|
||||
export const unstable_getStaticProps = async (ctx: any) => {
|
||||
console.log('call unstable_getStaticProps', ctx)
|
||||
|
||||
Index.getInitialProps = wrapInitialProps(async (ctx) => {
|
||||
const pageUrl = '/collective'
|
||||
const id = ctx.query.person
|
||||
const person: any = await requestGet(createApiUrl(ctx.req, `/api/persons/${id}`), {})
|
||||
// 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 : {}
|
||||
|
||||
return {
|
||||
pageUrl,
|
||||
person,
|
||||
title,
|
||||
meta: meta({
|
||||
title,
|
||||
image: image.src,
|
||||
imageWidth: image.width,
|
||||
imageHeight: image.height,
|
||||
})
|
||||
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<IResponseItems<string>>(`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
|
||||
Reference in new issue
Block a user