article related pages meta update and other improvements
This commit is contained in:
1 parent
9e5ec860e8
commit
488ea6ec06
6 files changed
+41
-36
No files matched your search
@@ -6,7 +6,7 @@ import { Meta } from 'src/components/Meta'
|
|||||||
import { 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 { IArticle, IMeta } from 'src/types'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string
|
title: string
|
||||||
|
|||||||
+11
-15
@@ -2,17 +2,18 @@ import Head from 'next/head'
|
|||||||
import { range } from 'lodash'
|
import { range } from 'lodash'
|
||||||
import { App } from 'src/components/App'
|
import { App } from 'src/components/App'
|
||||||
import { ArticleGrid } from 'src/components/ArticleGrid'
|
import { ArticleGrid } from 'src/components/ArticleGrid'
|
||||||
import { meta } from 'src/lib/meta'
|
import { MetaBuilder } from 'src/lib/meta'
|
||||||
import { Meta } from 'src/components/Meta'
|
import { Meta } from 'src/components/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'
|
||||||
|
|
||||||
const pageSize = Number(process.env.APP_ARTICLES_PAGE_SIZE)
|
const pageSize = Number(process.env.APP_ARTICLES_PAGE_SIZE)
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
meta: any
|
meta: any
|
||||||
title: string
|
title: string
|
||||||
data: any //(list of article)
|
data: IArticle[]
|
||||||
nextPage: number
|
nextPage: number
|
||||||
prevPage: number
|
prevPage: number
|
||||||
}
|
}
|
||||||
@@ -42,20 +43,19 @@ const Page: NextPage<Props> = props => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const unstable_getStaticProps = async (ctx: any) => {
|
export const unstable_getStaticProps = async (ctx: any) => {
|
||||||
// const page = parseInt(ctx.query.page)
|
|
||||||
const page = parseInt(ctx.params.slug)
|
const page = parseInt(ctx.params.slug)
|
||||||
const res = await requestGet<IResponseItems<any[]>>(
|
const res = await requestGet<IResponseItems<IArticle>>(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), null)
|
||||||
createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`),
|
|
||||||
null
|
|
||||||
)
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = res.items || []
|
const data = (res.items || [])
|
||||||
const nextPage = (res as any).nextPage
|
const nextPage = res.nextPage
|
||||||
const prevPage = (res as any).prevPage
|
const prevPage = res.prevPage
|
||||||
const title = 'События'
|
const title = 'События'
|
||||||
|
const meta = (new MetaBuilder())
|
||||||
|
.setTitle(title)
|
||||||
|
.build()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
@@ -63,16 +63,12 @@ export const unstable_getStaticProps = async (ctx: any) => {
|
|||||||
nextPage,
|
nextPage,
|
||||||
prevPage,
|
prevPage,
|
||||||
title,
|
title,
|
||||||
meta: meta({
|
meta,
|
||||||
title,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unstable_getStaticPaths = async () => {
|
export const unstable_getStaticPaths = async () => {
|
||||||
console.log('call articles unstable_getStaticPaths')
|
|
||||||
|
|
||||||
const urls = await requestGet<IResponseItems<string>>(createApiUrl(`/api/articles/urls`), null)
|
const urls = await requestGet<IResponseItems<string>>(createApiUrl(`/api/articles/urls`), null)
|
||||||
if (!urls) {
|
if (!urls) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
+8
-9
@@ -3,7 +3,7 @@ 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 { ArticleGrid } from 'src/components/ArticleGrid'
|
||||||
import { HudozkaTitle } from 'src/components/HudozkaTitle'
|
import { HudozkaTitle } from 'src/components/HudozkaTitle'
|
||||||
import { meta } from 'src/lib/meta'
|
import { meta, 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 { IArticle } from 'src/types'
|
||||||
@@ -45,13 +45,15 @@ export const unstable_getStaticProps = async () => {
|
|||||||
const pageSize = process.env.APP_ARTICLES_PAGE_SIZE
|
const pageSize = process.env.APP_ARTICLES_PAGE_SIZE
|
||||||
const res = await requestGet<IResponseItems<IArticle>>(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), null)
|
const res = await requestGet<IResponseItems<IArticle>>(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), null)
|
||||||
const articles = (res.items || [])
|
const articles = (res.items || [])
|
||||||
.map(x => ({
|
|
||||||
...x,
|
|
||||||
featured: ['2019-kotiki', 'veloparking'].includes(x.id)
|
|
||||||
}))
|
|
||||||
const nextPage = res.nextPage
|
const nextPage = res.nextPage
|
||||||
const prevPage = res.prevPage
|
const prevPage = res.prevPage
|
||||||
const title = 'Шлиссельбургская ДХШ'
|
const title = 'Шлиссельбургская ДХШ'
|
||||||
|
const meta = (new MetaBuilder())
|
||||||
|
.setTitle(title)
|
||||||
|
.setData({
|
||||||
|
url: '/',
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
@@ -59,10 +61,7 @@ export const unstable_getStaticProps = async () => {
|
|||||||
nextPage,
|
nextPage,
|
||||||
prevPage,
|
prevPage,
|
||||||
title,
|
title,
|
||||||
meta: meta({
|
meta,
|
||||||
title,
|
|
||||||
url: '/',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ export const ArticleGrid: React.FC<ArticleGridProps> = ({ articles, nextPage, pr
|
|||||||
{articles.map((article, i) => {
|
{articles.map((article, i) => {
|
||||||
const gridColumn = article.featured ? 'span 2' : 'auto'
|
const gridColumn = article.featured ? 'span 2' : 'auto'
|
||||||
const layout: CardLayout = article.featured ? 'featured' : 'simple'
|
const layout: CardLayout = article.featured ? 'featured' : 'simple'
|
||||||
const srcSet = article.preview.set.map(({ url, density }) => `${url} ${density}x`).join(' ')
|
const preview = article.preview.artifacts.medium
|
||||||
|
const src = preview.src
|
||||||
|
const srcSet = preview.set.map(({ url, density }) => `${url} ${density}x`).join(' ')
|
||||||
|
|
||||||
const content = !article.featured
|
const content = !article.featured
|
||||||
? (
|
? (
|
||||||
@@ -52,7 +54,7 @@ export const ArticleGrid: React.FC<ArticleGridProps> = ({ articles, nextPage, pr
|
|||||||
href={article.url}
|
href={article.url}
|
||||||
img={{
|
img={{
|
||||||
alt: article.title,
|
alt: article.title,
|
||||||
src: article.preview.src,
|
src,
|
||||||
srcSet,
|
srcSet,
|
||||||
}}
|
}}
|
||||||
layout={layout}
|
layout={layout}
|
||||||
|
|||||||
+16
-8
@@ -51,18 +51,26 @@ export class MetaBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
const artifact = this.image.artifacts.fb
|
const image = this.buildImage()
|
||||||
const image = {
|
|
||||||
image: artifact.src,
|
|
||||||
imageWidth: artifact.width,
|
|
||||||
imageHeight: artifact.height,
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta({
|
return meta({
|
||||||
...this.data,
|
...this.data,
|
||||||
...image,
|
...image,
|
||||||
title: this.title,
|
title: this.title ?? undefined,
|
||||||
description: this.description,
|
description: this.description ?? undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private buildImage() {
|
||||||
|
if (!this.image) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const artifact = this.image.artifacts.fb
|
||||||
|
return {
|
||||||
|
image: artifact.src,
|
||||||
|
imageWidth: artifact.width,
|
||||||
|
imageHeight: artifact.height,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -66,7 +66,7 @@ export interface IArticle {
|
|||||||
featured: boolean
|
featured: boolean
|
||||||
url: string
|
url: string
|
||||||
title: string
|
title: string
|
||||||
preview: IImage
|
preview: ImageDefinition
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Person = {
|
export type Person = {
|
||||||
|
|||||||
Reference in new issue
Block a user