diff --git a/pages/gallery.tsx b/pages/gallery.tsx index 8725b4c9..83efd772 100644 --- a/pages/gallery.tsx +++ b/pages/gallery.tsx @@ -1,14 +1,14 @@ import React from 'react' import Head from 'next/head' import { App } from '../src/components/App' -// import Album from '../src/components/Album' -import Article from '../src/components/Article' import { Meta } from '../src/components/Meta' import menuModel from '../src/models/menu' import { buildMenu } from '../src/lib/menu' import { splitBy } from '../src/lib/array' import { meta } from '../src/lib/meta' import { createApiUrl, requestGet, wrapInitialProps } from '../src/next-lib' +import { NextPage } from 'next' +import { PageHeader } from '../src/components/PageHeader' const albumsByYear = splitBy(album => new Date(album.date).getFullYear()) @@ -63,8 +63,14 @@ const ACollection = ({ title, albums }) => ( ) +interface IProps { + meta: any + pageUrl: string + title: string + collections: any[] +} -const Page = (props) => ( +const Page: NextPage = props => ( ( -
- {props.collections.map(([year, albums], index) => ( - - )) - } -
+ + + {props.collections.map(([year, albums], index) => ( + + ))}
) Page.getInitialProps = wrapInitialProps(async (ctx) => { const pageUrl = ctx.req.url - const res = await requestGet(createApiUrl(ctx.req, `/api/albums`), {}) + const res = await requestGet(createApiUrl(ctx.req, `/api/albums`), {}) const items = res.items || [] const albumCollections = albumsByYear(items) const title = 'Галерея' @@ -110,4 +114,4 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => { } }) -export default Page \ No newline at end of file +export default Page diff --git a/src/components/PageHeader/index.tsx b/src/components/PageHeader/index.tsx new file mode 100644 index 00000000..6dbcd894 --- /dev/null +++ b/src/components/PageHeader/index.tsx @@ -0,0 +1,22 @@ +import * as React from 'react' +import { dateFormat } from '../../lib/date' + +export interface IPageHeaderProps { + tags?: string[] + date?: Date + title: string +} + +export const PageHeader: React.FC = props => ( +
+

{props.title}

+ + {!props.date ? null : ( +

{dateFormat(props.date)}

+ )} + + {/* {!(tags.length) ? null : ( + + )} */} +
+) diff --git a/src/lib/date.ts b/src/lib/date.ts index 1a2cbede..2d5b7473 100644 --- a/src/lib/date.ts +++ b/src/lib/date.ts @@ -7,7 +7,7 @@ moment.locale('ru') * * @param date */ -export const dateFormat = (date: string) => moment(date).format('L') +export const dateFormat = (date: string | Date) => moment(date).format('L') /** *