index page updated; ArticleGrid -> PageGrid
This commit is contained in:
1 parent
85d2f7cc45
commit
970bdce53d
4 files changed
+40
-50
No files matched your search
+25
-9
@@ -1,19 +1,19 @@
|
|||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import { App } from 'src/components/App'
|
import { App } from 'src/components/App'
|
||||||
import { Meta } from 'src/components/Meta'
|
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 { 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 { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
||||||
import { NextPage } from 'next'
|
import { NextPage } from 'next'
|
||||||
import { IArticle } from 'src/types'
|
import { IPage } from 'src/types'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
title: string
|
title: string
|
||||||
meta: any
|
meta: any
|
||||||
prevPage: number
|
prevPage: number
|
||||||
nextPage: number
|
nextPage: number
|
||||||
articles: any[]
|
items: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const Page: NextPage<IProps> = props => (
|
const Page: NextPage<IProps> = props => (
|
||||||
@@ -32,8 +32,8 @@ const Page: NextPage<IProps> = props => (
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ArticleGrid
|
<PageGrid
|
||||||
articles={props.articles}
|
items={props.items}
|
||||||
prevPage={props.prevPage}
|
prevPage={props.prevPage}
|
||||||
nextPage={props.nextPage}
|
nextPage={props.nextPage}
|
||||||
/>
|
/>
|
||||||
@@ -42,10 +42,26 @@ const Page: NextPage<IProps> = props => (
|
|||||||
|
|
||||||
export const unstable_getStaticProps = async () => {
|
export const unstable_getStaticProps = async () => {
|
||||||
const page = 1
|
const page = 1
|
||||||
const pageSize = process.env.APP_ARTICLES_PAGE_SIZE
|
// const pageSize = parseInt(process.env.APP_ARTICLES_PAGE_SIZE)
|
||||||
const res = await requestGet<IResponseItems<IArticle>>(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), null)
|
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<IResponseItems<IPage>>(createApiUrl(url), null)
|
||||||
const articles = (res.items || [])
|
const articles = (res.items || [])
|
||||||
const nextPage = res.nextPage
|
// const nextPage = res.nextPage
|
||||||
|
const nextPage = 2
|
||||||
const prevPage = res.prevPage
|
const prevPage = res.prevPage
|
||||||
const title = 'Шлиссельбургская ДХШ'
|
const title = 'Шлиссельбургская ДХШ'
|
||||||
const meta = (new MetaBuilder())
|
const meta = (new MetaBuilder())
|
||||||
|
|||||||
File renamed without changes.
@@ -1,4 +1,4 @@
|
|||||||
import { IArticle, ImageDefinition } from 'src/types'
|
import { ImageDefinition, IPage } from 'src/types'
|
||||||
import { Pager } from '../Pager'
|
import { Pager } from '../Pager'
|
||||||
import { CardGrid } from '../CardGrid'
|
import { CardGrid } from '../CardGrid'
|
||||||
import { Card, CardLayout } from '../Card'
|
import { Card, CardLayout } from '../Card'
|
||||||
@@ -47,13 +47,13 @@ function getImage(image?: ImageDefinition) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ArticleGridProps = {
|
export type PageGridProps = {
|
||||||
articles: IArticle[]
|
items: IPage[]
|
||||||
nextPage: number | null
|
nextPage: number | null
|
||||||
prevPage: number | null
|
prevPage: number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ArticleGrid: React.FC<ArticleGridProps> = ({ articles, nextPage, prevPage, ...props }) => {
|
export const PageGrid: React.FC<PageGridProps> = ({ items, nextPage, prevPage, ...props }) => {
|
||||||
const nextHref = nextPage ? `/articles/${nextPage}` : null
|
const nextHref = nextPage ? `/articles/${nextPage}` : null
|
||||||
let prevHref = prevPage ? `/articles/${prevPage}` : null
|
let prevHref = prevPage ? `/articles/${prevPage}` : null
|
||||||
if (prevPage === 1) {
|
if (prevPage === 1) {
|
||||||
@@ -67,32 +67,32 @@ export const ArticleGrid: React.FC<ArticleGridProps> = ({ articles, nextPage, pr
|
|||||||
marginBottom: 'var(--size-m)',
|
marginBottom: 'var(--size-m)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{articles.map((article, i) => {
|
{items.map((item, i) => {
|
||||||
const gridColumn = article.featured ? 'span 2' : 'auto'
|
const gridColumn = item.featured ? 'span 2' : 'auto'
|
||||||
const layout: CardLayout = article.featured ? 'featured' : 'simple'
|
const layout: CardLayout = item.featured ? 'featured' : 'simple'
|
||||||
const { src, srcSet } = getImage(article.preview)
|
const { src, srcSet } = getImage(item.preview)
|
||||||
|
|
||||||
const content = !article.featured
|
const content = !item.featured
|
||||||
? (
|
? (
|
||||||
<Block
|
<Block
|
||||||
direction={'vertical'}
|
direction={'vertical'}
|
||||||
>
|
>
|
||||||
{article.title}
|
{item.title}
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Date style={{
|
<Date style={{
|
||||||
marginTop: 'var(--size-m)',
|
marginTop: 'var(--size-m)',
|
||||||
}}>{article.date}</Date>
|
}}>{item.date}</Date>
|
||||||
</Block>
|
</Block>
|
||||||
) : (
|
) : (
|
||||||
article.title
|
item.title
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={i}
|
key={i}
|
||||||
href={article.url}
|
href={item.url}
|
||||||
img={{
|
img={{
|
||||||
alt: article.title,
|
alt: item.title,
|
||||||
src,
|
src,
|
||||||
srcSet,
|
srcSet,
|
||||||
}}
|
}}
|
||||||
+1
-27
@@ -19,6 +19,7 @@ export interface IPage {
|
|||||||
tokens: any[]
|
tokens: any[]
|
||||||
tags: ITag[]
|
tags: ITag[]
|
||||||
breadcrumb?: IBreadcumbsPart[]
|
breadcrumb?: IBreadcumbsPart[]
|
||||||
|
featured: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDocument {
|
export interface IDocument {
|
||||||
@@ -60,33 +61,6 @@ export interface ITag {
|
|||||||
href: string
|
href: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IArticle {
|
|
||||||
id: string
|
|
||||||
date: string
|
|
||||||
tags: ITag[]
|
|
||||||
post:string
|
|
||||||
featured: boolean
|
|
||||||
url: string
|
|
||||||
title: string
|
|
||||||
preview: ImageDefinition
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Person = {
|
|
||||||
id: string
|
|
||||||
position: string
|
|
||||||
name: [string, string, string]
|
|
||||||
post: string
|
|
||||||
diploma: string
|
|
||||||
edu: string
|
|
||||||
file: string
|
|
||||||
hash: string
|
|
||||||
shortName: string
|
|
||||||
status: string
|
|
||||||
url: string
|
|
||||||
picture: ImageArtifact
|
|
||||||
preview: ImageDefinition
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ImageArtifact = {
|
export type ImageArtifact = {
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
|
|||||||
Reference in new issue
Block a user