initial static export in teachers

This commit is contained in:
tmshv committed 2020-02-13 17:31:23 +03:00
1 parent 92460592b4
commit 997e44483e
5 files changed
+134 -89

No files matched your search

+21 -21
View File
@@ -160,27 +160,27 @@ module.exports = withCss(withSass({
'/info/navigator',
]
),
...createPath(
'/teacher/[person]',
x => x.replace('/teacher/', ''),
person => ({ person }),
[
'/teacher/as-timasheva',
'/teacher/va-sarzhin',
'/teacher/vv-voronova',
'/teacher/ea-burovtseva',
'/teacher/ey-tarasova',
'/teacher/iv-khramov',
'/teacher/in-vturina',
'/teacher/ma-khramova',
'/teacher/mg-timasheva',
'/teacher/my-valkova',
'/teacher/nv-andreeva',
'/teacher/od-gogoleva',
'/teacher/rk-timashev',
'/teacher/sa-latipova',
],
),
// ...createPath(
// '/teacher/[person]',
// x => x.replace('/teacher/', ''),
// person => ({ person }),
// [
// '/teacher/as-timasheva',
// '/teacher/va-sarzhin',
// '/teacher/vv-voronova',
// '/teacher/ea-burovtseva',
// '/teacher/ey-tarasova',
// '/teacher/iv-khramov',
// '/teacher/in-vturina',
// '/teacher/ma-khramova',
// '/teacher/mg-timasheva',
// '/teacher/my-valkova',
// '/teacher/nv-andreeva',
// '/teacher/od-gogoleva',
// '/teacher/rk-timashev',
// '/teacher/sa-latipova',
// ],
// ),
...createPath(
'/article/[article]',
x => x.replace('/article/', ''),
+17 -17
View File
@@ -1059,9 +1059,9 @@
"integrity": "sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw=="
},
"@next/polyfill-nomodule": {
"version": "9.2.2-canary.16",
"resolved": "https://registry.npmjs.org/@next/polyfill-nomodule/-/polyfill-nomodule-9.2.2-canary.16.tgz",
"integrity": "sha512-VPAaxYJ9cDaaC+imgOTCNJmB4zijXaArF+Nv7KZS7zO5KpltFFNZSmsDO1Mw8jkJbZ4qWDmqpK/d+ZJoqwzOVQ=="
"version": "9.2.2-canary.18",
"resolved": "https://registry.npmjs.org/@next/polyfill-nomodule/-/polyfill-nomodule-9.2.2-canary.18.tgz",
"integrity": "sha512-YryD2l6Vzfjd8dHBu4GA0VJI/mBB0U6tmoOI8bum/C22S1Oh3OzWpBTkMVGXyxTVsOZM6jArVNSaL69Ps67vlA=="
},
"@types/accepts": {
"version": "1.3.5",
@@ -1987,7 +1987,7 @@
},
"babel-plugin-syntax-jsx": {
"version": "6.18.0",
"resolved": "http://storage.mds.yandex.net/get-npm/66641/babel-plugin-syntax-jsx-6.18.0.tgz",
"resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz",
"integrity": "sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY="
},
"babel-plugin-transform-define": {
@@ -2439,9 +2439,9 @@
}
},
"make-dir": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.1.tgz",
"integrity": "sha512-NFCymdWS4z/T+3AQ6tjsknt/+4hikbOe6zdq9ZBoPFfoX1S3fthRUbQWzZhI4WZBOM0kQ0GkhdCdfdan3HK+wg==",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.2.tgz",
"integrity": "sha512-rYKABKutXa6vXTXhoV18cBE7PaewPXHe/Bdq4v+ZLMhxbWApkFFplT0LcbMW+6BbjnQXzZ/sAvSE/JdguApG5w==",
"requires": {
"semver": "^6.0.0"
}
@@ -2836,9 +2836,9 @@
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"make-dir": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.1.tgz",
"integrity": "sha512-NFCymdWS4z/T+3AQ6tjsknt/+4hikbOe6zdq9ZBoPFfoX1S3fthRUbQWzZhI4WZBOM0kQ0GkhdCdfdan3HK+wg==",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.2.tgz",
"integrity": "sha512-rYKABKutXa6vXTXhoV18cBE7PaewPXHe/Bdq4v+ZLMhxbWApkFFplT0LcbMW+6BbjnQXzZ/sAvSE/JdguApG5w==",
"requires": {
"semver": "^6.0.0"
}
@@ -5280,7 +5280,7 @@
},
"is-plain-obj": {
"version": "1.1.0",
"resolved": "http://storage.mds.yandex.net/get-npm/69187/is-plain-obj-1.1.0.tgz",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4="
},
"is-plain-object": {
@@ -6691,9 +6691,9 @@
"integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw=="
},
"next": {
"version": "9.2.2-canary.16",
"resolved": "https://registry.npmjs.org/next/-/next-9.2.2-canary.16.tgz",
"integrity": "sha512-k4SuXSc6LxnfD7oehFxVxhJuXonzPg9ERlRarqUaUbuWOy6y8mXwJVYd36DNiXJlgXGjsRReSsVNC8d7fIlenQ==",
"version": "9.2.2-canary.18",
"resolved": "https://registry.npmjs.org/next/-/next-9.2.2-canary.18.tgz",
"integrity": "sha512-OiIaIJtmwBQG3C6Te6VIHbvKrlrVQiIaPaxevjsRv9pmdghcWmzuaCQoXx/SC6rwdvDAXKS8BtDczXJsx6mREQ==",
"requires": {
"@ampproject/toolbox-optimizer": "1.1.1",
"@babel/core": "7.7.2",
@@ -6711,7 +6711,7 @@
"@babel/preset-typescript": "7.7.2",
"@babel/runtime": "7.7.2",
"@babel/runtime-corejs2": "7.7.2",
"@next/polyfill-nomodule": "9.2.2-canary.16",
"@next/polyfill-nomodule": "9.2.2-canary.18",
"amphtml-validator": "1.0.23",
"async-retry": "1.2.3",
"async-sema": "3.0.0",
@@ -7325,7 +7325,7 @@
},
"normalize-range": {
"version": "0.1.2",
"resolved": "http://storage.mds.yandex.net/get-npm/38095/normalize-range-0.1.2.tgz",
"resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz",
"integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI="
},
"normalize-url": {
@@ -7353,7 +7353,7 @@
},
"num2fraction": {
"version": "1.2.2",
"resolved": "http://storage.mds.yandex.net/get-npm/38095/num2fraction-1.2.2.tgz",
"resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz",
"integrity": "sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4="
},
"number-is-nan": {
+1 -1
View File
@@ -25,7 +25,7 @@
"lodash": "^4.17.15",
"moment": "^2.24.0",
"mongodb": "^2.1.14",
"next": "^9.2.2-canary.16",
"next": "^9.2.2-canary.18",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"sitemap": "^1.5.0",
+14 -12
View File
@@ -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
View File
@@ -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