diff --git a/pages/album/[slug].tsx b/pages/album/[slug].tsx index 92ac727b..0fd48c06 100644 --- a/pages/album/[slug].tsx +++ b/pages/album/[slug].tsx @@ -50,7 +50,6 @@ export const unstable_getStaticProps = async (ctx: any) => { const id = ctx.params.slug const data = await requestGet(createApiUrl(`/api/albums/${id}`), null) - console.log('call album unstable_getStaticProps', data) if (!data) { throw new Error(`kek ${id}`) } diff --git a/pages/article/[article].jsx b/pages/article/[article].jsx deleted file mode 100644 index dfe5398d..00000000 --- a/pages/article/[article].jsx +++ /dev/null @@ -1,55 +0,0 @@ -import React from 'react' -import Head from 'next/head' -import { get } from 'lodash' -import { App } from '../../src/components/App' -import Article from '../../src/components/Article' -import Html from '../../src/components/Html' -import menuModel from '../../src/models/menu' -import { buildMenu } from '../../src/lib/menu' -import { Meta } from '../../src/components/Meta' -import { meta } from '../../src/lib/meta' -import { createApiUrl, requestGet, wrapInitialProps } from '../../src/next-lib' - -const Page = (props) => ( - - - {props.article.title} - - -
- -
-
-) - -Page.getInitialProps = wrapInitialProps(async (ctx) => { - const pageUrl = '/' - const id = ctx.query.article - const article = await requestGet(createApiUrl(`/api/articles/${id}`), {}) - const image = get(article, 'preview.artifacts.fb', {}) - - return { - article, - pageUrl, - meta: meta({ - title: article.title, - image: image.src, - imageWidth: image.width, - imageHeight: image.height, - }), - } -}) - -export default Page \ No newline at end of file diff --git a/pages/article/[slug].tsx b/pages/article/[slug].tsx new file mode 100644 index 00000000..a8e19c3e --- /dev/null +++ b/pages/article/[slug].tsx @@ -0,0 +1,95 @@ +import Head from 'next/head' +import { get } from 'lodash' +import { App } from 'src/components/App' +import Article from 'src/components/Article' +import Html from 'src/components/Html' +import menuModel from 'src/models/menu' +import { buildMenu } from 'src/lib/menu' +import { Meta } from 'src/components/Meta' +import { meta } from 'src/lib/meta' +import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' +import { NextPage } from 'next' + +type Props = { + pageUrl: string + meta: any + data: any //(article) +} + +const Page: NextPage = props => { + if (!props.data) { + console.log('kek error', props) + return null + } + + return ( + + + {props.data.title} + + +
+ +
+
+ ) +} + +export const unstable_getStaticProps = async (ctx: any) => { + const pageUrl = '/' + const id = ctx.params.slug + const data = await requestGet(createApiUrl(`/api/articles/${id}`), null) + if (!data) { + return null + } + + const image = get(data, 'preview.artifacts.fb', {}) + + return { + props: { + data, + pageUrl, + meta: meta({ + title: data.title, + image: image.src, + imageWidth: image.width, + imageHeight: image.height, + }), + } + } +} + +export const unstable_getStaticPaths = async () => { + console.log('call article unstable_getStaticPaths') + + const urls = await requestGet>(createApiUrl(`/api/articles/urls`), null) + if (!urls) { + return null + } + + return { + paths: urls.items + .map(x => x.replace('/article/', '')) + .map(slug => { + return { + params: { + slug, + }, + } + }), + } +} + +export default Page diff --git a/pages/articles/[page].jsx b/pages/articles/[page].jsx deleted file mode 100644 index 2b0cb43f..00000000 --- a/pages/articles/[page].jsx +++ /dev/null @@ -1,52 +0,0 @@ -import React from 'react' -import Head from 'next/head' -import { App } from '../../src/components/App' -import { ArticleCardList } from '../../src/components/ArticleCardList' -import menuModel from '../../src/models/menu' -import { buildMenu } from '../../src/lib/menu' -import { meta } from '../../src/lib/meta' -import { Meta } from '../../src/components/Meta' -import { createApiUrl, requestGet, wrapInitialProps } from '../../src/next-lib' - -const Page = (props) => ( - - - {props.title} - - - - -) - -Page.getInitialProps = wrapInitialProps(async (ctx) => { - const pageUrl = '/' - const page = parseInt(ctx.query.page) - const pageSize = parseInt(ctx.query.pageSize) || 15 - const res = await requestGet(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), {}) - const articles = res.items || [] - const nextPage = res.nextPage - const prevPage = res.prevPage - const title = 'События' - - return { - articles, - nextPage, - prevPage, - pageUrl, - title, - meta: meta({ - title, - }) - } -}) - -export default Page diff --git a/pages/articles/[slug].tsx b/pages/articles/[slug].tsx new file mode 100644 index 00000000..16993f65 --- /dev/null +++ b/pages/articles/[slug].tsx @@ -0,0 +1,104 @@ +import Head from 'next/head' +import { range } from 'lodash' +import { App } from 'src/components/App' +import { ArticleCardList } from 'src/components/ArticleCardList' +import menuModel from 'src/models/menu' +import { buildMenu } from 'src/lib/menu' +import { meta } from 'src/lib/meta' +import { Meta } from 'src/components/Meta' +import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' +import { NextPage } from 'next' + +const pageSize = Number(process.env.APP_ARTICLES_PAGE_SIZE) + +type Props = { + pageUrl: string + meta: any + title: string + data: any //(list of article) + nextPage: number + prevPage: number +} + +const Page: NextPage = props => { + if (!props.data) { + console.log('kek error', props) + return null + } + + return ( + + + {props.title} + + + + + ) +} + +export const unstable_getStaticProps = async (ctx: any) => { + const pageUrl = '/' + // const page = parseInt(ctx.query.page) + const page = parseInt(ctx.params.slug) + const res = await requestGet>( + createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), + null + ) + if (!res) { + return null + } + + const data = res.items || [] + const nextPage = (res as any).nextPage + const prevPage = (res as any).prevPage + const title = 'События' + + return { + props: { + data, + nextPage, + prevPage, + pageUrl, + title, + meta: meta({ + title, + }) + } + } +} + +export const unstable_getStaticPaths = async () => { + console.log('call articles unstable_getStaticPaths') + + const urls = await requestGet>(createApiUrl(`/api/articles/urls`), null) + if (!urls) { + return null + } + + const count = urls.items.length + const pages = Math.ceil(count / pageSize) + + return { + paths: range(1, pages + 1) + .map(i => { + return { + params: { + slug: `${i}`, + }, + } + }), + } +} + + +export default Page diff --git a/pages/collective.tsx b/pages/collective.tsx index dcfa4354..07172e87 100644 --- a/pages/collective.tsx +++ b/pages/collective.tsx @@ -21,50 +21,58 @@ type Props = { title: string image: string meta: IMeta - persons: IPerson[] + data: IPerson[] } -const Page: NextPage = props => ( - - - {props.title} - - +const Page: NextPage = props => { + if (!props.data) { + console.log('kek error') + return + } - {!props.image ? null : ( - - )} + return ( + + + {props.title} + + - ( - )} - /> - -) -export const unstable_getServerProps = async (ctx: NextPageContext) => { - const pageUrl = ctx.req.url + ( + + )} + /> + + ) +} + +export const unstable_getStaticProps = async (ctx: NextPageContext) => { + // const pageUrl = ctx.req.url + const pageUrl = '/collective' const res = await requestGet>(createApiUrl('/api/persons'), { items: [] }) - const persons = res.items || [] + const data = res.items || [] const title = 'Преподаватели Шлиссельбургской ДХШ' const imageFile = 'Images/HudozkaCollective2017.jpg' const resImage = await requestGet(createApiUrl(`/api/image?file=${imageFile}`), null) @@ -72,7 +80,7 @@ export const unstable_getServerProps = async (ctx: NextPageContext) => { return { props: { - persons, + data, image, pageUrl, title, diff --git a/pages/document/[document].jsx b/pages/document/[document].jsx deleted file mode 100644 index 31510772..00000000 --- a/pages/document/[document].jsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react' -import Head from 'next/head' -import { App } from '../../src/components/App' -import Document from '../../src/components/Document' -import { Share } from '../../src/components/Share' -import menuModel from '../../src/models/menu' -import { buildMenu } from '../../src/lib/menu' -import { meta } from '../../src/lib/meta' -import { Meta } from '../../src/components/Meta' -import { createApiUrl, requestGet, wrapInitialProps } from '../../src/next-lib' - -const Page = (props) => ( - - - {props.file.title} - - - - - -) - -Page.getInitialProps = wrapInitialProps(async (ctx) => { - const pageUrl = '/documents' - const id = ctx.query.document - const file = await requestGet(createApiUrl(`/api/files/${id}`), {}) - - return { - file, - pageUrl, - meta: meta({ - title: file.meta, - }) - } -}) - -export default Page \ No newline at end of file diff --git a/pages/document/[slug].tsx b/pages/document/[slug].tsx new file mode 100644 index 00000000..dc57b44d --- /dev/null +++ b/pages/document/[slug].tsx @@ -0,0 +1,81 @@ +import React from 'react' +import Head from 'next/head' +import { App } from 'src/components/App' +import Document from 'src/components/Document' +import { Share } from 'src/components/Share' +import menuModel from 'src/models/menu' +import { buildMenu } from 'src/lib/menu' +import { meta } from 'src/lib/meta' +import { Meta } from 'src/components/Meta' +import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' +import { NextPage } from 'next' +import { IMeta } from 'src/types' + +type Props = { + pageUrl: string + data: any //(file) + meta: IMeta +} + +const Page: NextPage = props => { + if (!props.data) { + console.log('kek error', props) + + return null + } + + return ( + + + {props.data.title} + + + + + + ) +} + +export const unstable_getStaticProps = async (ctx: any) => { + const pageUrl = '/documents' + const id = ctx.params.slug + const data = await requestGet(createApiUrl(`/api/files/${id}`), {}) + + return { + props: { + data, + pageUrl, + meta: meta({ + // title: file.meta, + }) + } + } +} + +export const unstable_getStaticPaths = async () => { + console.log('call file unstable_getStaticPaths') + + const urls = await requestGet>(createApiUrl(`/api/files/urls`), null) + if (!urls) { + return null + } + + return { + paths: urls.items + .map(x => x.replace('/document/', '')) + .map(slug => { + return { + params: { + slug, + }, + } + }), + } +} + +export default Page diff --git a/pages/documents.tsx b/pages/documents.tsx index 0074f462..1bfb7f03 100644 --- a/pages/documents.tsx +++ b/pages/documents.tsx @@ -1,15 +1,13 @@ -import React from 'react' import Head from 'next/head' -import { App } from '../src/components/App' -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 { IDocument } from '../src/types' - -import { DocumentList } from '../src/components/DocumentList' -import { unique } from '../src/utils/common' -import { createApiUrl, requestGet, wrapInitialProps, IResponseItems } from '../src/next-lib' +import { App } from 'src/components/App' +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 { IDocument } from 'src/types' +import { DocumentList } from 'src/components/DocumentList' +import { unique } from 'src/utils/common' +import { createApiUrl, requestGet, wrapInitialProps, IResponseItems } from 'src/next-lib' import { NextPage } from 'next' interface IDocumentCategory { @@ -125,7 +123,7 @@ const Page: NextPage = props => ( ) -Page.getInitialProps = wrapInitialProps(async (ctx) => { +export const unstable_getStaticProps = async (ctx) => { const pageUrl = '/documents' const res = await requestGet>(createApiUrl('/api/files'), { items: [] }) const files = res.items @@ -133,14 +131,16 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => { const collections = getSorted(files) return { - collections, - pageUrl, - title, - meta: meta({ + props: { + collections, + pageUrl, title, - description: 'Документы Шлиссельбургской ДХШ', - }) + meta: meta({ + title, + description: 'Документы Шлиссельбургской ДХШ', + }) + } } -}) +} -export default Page \ No newline at end of file +export default Page diff --git a/pages/gallery.tsx b/pages/gallery.tsx index 5ccfc13a..f8513aa8 100644 --- a/pages/gallery.tsx +++ b/pages/gallery.tsx @@ -96,22 +96,28 @@ const Page: NextPage = props => ( ) -Page.getInitialProps = wrapInitialProps(async (ctx) => { - const pageUrl = ctx.req.url - const res = await requestGet(createApiUrl(`/api/albums`), {}) +export const unstable_getStaticProps = async (ctx: any) => { + // const pageUrl = ctx.req.url + const pageUrl = '/gallery' + const res = await requestGet(createApiUrl(`/api/albums`), null) + if (!res) { + return null + } const items = res.items || [] const albumCollections = albumsByYear(items) const title = 'Галерея' return { - collections: [...albumCollections.entries()], - pageUrl, - title, - meta: meta({ + props: { + collections: [...albumCollections.entries()], + pageUrl, title, - description: 'Галерея работ учащихся Шлиссельбургской Детской Художественной Школы' - }) + meta: meta({ + title, + description: 'Галерея работ учащихся Шлиссельбургской Детской Художественной Школы' + }) + } } -}) +} export default Page diff --git a/pages/schedule.jsx b/pages/schedule.jsx deleted file mode 100644 index d2028fac..00000000 --- a/pages/schedule.jsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react' -import Head from 'next/head' -import { App } from '../src/components/App' -import { Schedule } from '../src/components/Schedule' -import { Share } from '../src/components/Share' -import menuModel from '../src/models/menu' -import { buildMenu } from '../src/lib/menu' -import { createApiUrl, requestGet, wrapInitialProps } from '../src/next-lib' - -const Page = (props) => ( - - - {props.title} - - - {/**/} - - - - - -) - -Page.getInitialProps = wrapInitialProps(async (ctx) => { - const pageUrl = ctx.req.url - const period = '2016-2017' - const semester = 'spring' - const schedule = await requestGet(createApiUrl(`/api/schedule?period=${period}&semester=${semester}`), {}) - - return { - schedule, - pageUrl, - title: 'Расписание', - } -}) - -export default Page \ No newline at end of file diff --git a/pages/schedule.tsx b/pages/schedule.tsx new file mode 100644 index 00000000..ed2700ce --- /dev/null +++ b/pages/schedule.tsx @@ -0,0 +1,54 @@ +import Head from 'next/head' +import { App } from 'src/components/App' +import { Schedule } from 'src/components/Schedule' +import { Share } from 'src/components/Share' +import menuModel from 'src/models/menu' +import { buildMenu } from 'src/lib/menu' +import { createApiUrl, requestGet } from 'src/next-lib' +import { NextPage } from 'next' + +type Props = { + pageUrl: string + title: string + data: any //(schedule) +} + +const Page: NextPage = props => ( + + + {props.title} + + + {/**/} + + + + + +) + +export const unstable_getStaticProps = async (ctx: any) => { + // const pageUrl = ctx.req.url + const pageUrl = '/schedule' + const period = '2016-2017' + const semester = 'spring' + const data = await requestGet(createApiUrl(`/api/schedule?period=${period}&semester=${semester}`), null) + if (!data) { + return null + } + + return { + props: { + data, + pageUrl, + title: 'Расписание', + } + } +} + +export default Page