diff --git a/pages/index.tsx b/pages/index.tsx index 64e2f261..ccc3f334 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,19 +1,19 @@ import Head from 'next/head' import { App } from 'src/components/App' import { Meta } from 'src/components/Meta' -import { ArticleGrid } from 'src/components/ArticleGrid' +import { PageGrid } from 'src/components/PageGrid' import { HudozkaTitle } from 'src/components/HudozkaTitle' -import { meta, MetaBuilder } from 'src/lib/meta' +import { MetaBuilder } from 'src/lib/meta' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage } from 'next' -import { IArticle } from 'src/types' +import { IPage } from 'src/types' interface IProps { title: string meta: any prevPage: number nextPage: number - articles: any[] + items: any[] } const Page: NextPage = props => ( @@ -32,8 +32,8 @@ const Page: NextPage = props => ( }} /> - @@ -42,10 +42,26 @@ const Page: NextPage = props => ( export const unstable_getStaticProps = async () => { const page = 1 - const pageSize = process.env.APP_ARTICLES_PAGE_SIZE - const res = await requestGet>(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), null) + // const pageSize = parseInt(process.env.APP_ARTICLES_PAGE_SIZE) + const pageSize = 300 + + const limit = pageSize + const skip = (page - 1) * pageSize + + const tags = [ + 'event', + 'album', + 'post', + ] + const tagQuery = tags + .map(x => `tag=${x}`) + .join('&') + + const url = `/api/pages/tags?${tagQuery}&skip=${skip}&limit=${limit}&sortBy=-date` + const res = await requestGet>(createApiUrl(url), null) const articles = (res.items || []) - const nextPage = res.nextPage + // const nextPage = res.nextPage + const nextPage = 2 const prevPage = res.prevPage const title = 'Шлиссельбургская ДХШ' const meta = (new MetaBuilder()) diff --git a/src/components/ArticleGrid/Date.tsx b/src/components/PageGrid/Date.tsx similarity index 100% rename from src/components/ArticleGrid/Date.tsx rename to src/components/PageGrid/Date.tsx diff --git a/src/components/ArticleGrid/index.tsx b/src/components/PageGrid/index.tsx similarity index 77% rename from src/components/ArticleGrid/index.tsx rename to src/components/PageGrid/index.tsx index c9523ebe..9466e99a 100644 --- a/src/components/ArticleGrid/index.tsx +++ b/src/components/PageGrid/index.tsx @@ -1,4 +1,4 @@ -import { IArticle, ImageDefinition } from 'src/types' +import { ImageDefinition, IPage } from 'src/types' import { Pager } from '../Pager' import { CardGrid } from '../CardGrid' import { Card, CardLayout } from '../Card' @@ -47,13 +47,13 @@ function getImage(image?: ImageDefinition) { } } -export type ArticleGridProps = { - articles: IArticle[] +export type PageGridProps = { + items: IPage[] nextPage: number | null prevPage: number | null } -export const ArticleGrid: React.FC = ({ articles, nextPage, prevPage, ...props }) => { +export const PageGrid: React.FC = ({ items, nextPage, prevPage, ...props }) => { const nextHref = nextPage ? `/articles/${nextPage}` : null let prevHref = prevPage ? `/articles/${prevPage}` : null if (prevPage === 1) { @@ -67,32 +67,32 @@ export const ArticleGrid: React.FC = ({ articles, nextPage, pr marginBottom: 'var(--size-m)', }} > - {articles.map((article, i) => { - const gridColumn = article.featured ? 'span 2' : 'auto' - const layout: CardLayout = article.featured ? 'featured' : 'simple' - const { src, srcSet } = getImage(article.preview) + {items.map((item, i) => { + const gridColumn = item.featured ? 'span 2' : 'auto' + const layout: CardLayout = item.featured ? 'featured' : 'simple' + const { src, srcSet } = getImage(item.preview) - const content = !article.featured + const content = !item.featured ? ( - {article.title} + {item.title} {article.date} + }}>{item.date} ) : ( - article.title + item.title ) return (