use cover instead of preview of coverSrc

This commit is contained in:
tmshv committed 2020-03-11 13:38:50 +03:00
1 parent a4d245007e
commit b7f3bbbcef
9 files changed
+72 -58

No files matched your search

+1 -1
View File
@@ -62,7 +62,7 @@ export const getStaticProps = async (ctx: any) => {
const breadcrumbSize = page?.breadcrumb?.length ?? 0 const breadcrumbSize = page?.breadcrumb?.length ?? 0
const breadcrumb = breadcrumbSize < 2 ? null : page.breadcrumb const breadcrumb = breadcrumbSize < 2 ? null : page.breadcrumb
const meta = (new MetaBuilder()) const meta = (new MetaBuilder())
.setImage(page.preview) .setImage(page.cover)
.setTitle(page.title) .setTitle(page.title)
.setDescription(description) .setDescription(description)
.build() .build()
+2 -4
View File
@@ -109,15 +109,13 @@ export const getStaticProps = async (ctx: NextPageContext) => {
const data: CardData[] = pages const data: CardData[] = pages
.filter(Boolean) .filter(Boolean)
.map(x => { .map(x => {
const image = x.preview.artifacts.large
return { return {
title: x.title, title: x.title,
caption: x.description, caption: x.description,
href: x.url, href: x.url,
imageAlt: title, imageAlt: title,
imageSrc: image.src, imageSrc: x.cover.src,
imageSrcSet: imageSrcSet(image.src, [ImageSize.medium, ImageSize.small]) imageSrcSet: imageSrcSet(x.cover.src, [ImageSize.medium, ImageSize.small])
} }
}) })
+14 -12
View File
@@ -1,16 +1,15 @@
import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import { App } from 'src/components/App' import { App } from 'src/components/App'
import Document from 'src/components/Document' import { File } from 'src/components/File'
import { Share } from 'src/components/Share' import { Share } from 'src/components/Share'
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 { IMeta } from 'src/types' import { IMeta, FileDefinition } from 'src/types'
type Props = { type Props = {
data: any //(file) data: FileDefinition
meta: IMeta meta: IMeta
} }
@@ -26,25 +25,28 @@ const Page: NextPage<Props> = props => {
showAuthor={true} showAuthor={true}
> >
<Head> <Head>
<title>{props.data.title}</title> <title>{props.data.name}</title>
<Meta meta={props.meta} /> <Meta meta={props.meta} />
</Head> </Head>
<Document {...props.data} /> <File {...props.data} />
<Share /> <Share />
</App> </App>
) )
} }
export const getStaticProps = async (ctx: any) => { export const getStaticProps = async (ctx: any) => {
const id = ctx.params.slug const slug = ctx.params.slug
const data = await requestGet(createApiUrl(`/api/files/${id}`), {}) const data = await requestGet<FileDefinition>(createApiUrl(`/api/files/${slug}`), null)
const meta = (new MetaBuilder())
.setImage(data.cover)
.setTitle(data.name)
.setDescription(data.name)
.build()
return { return {
props: { props: {
data, data,
meta: meta({ meta,
// title: file.meta,
})
} }
} }
} }
+1 -1
View File
@@ -20,7 +20,7 @@ const Index: NextPage<IProps> = props => {
title: item.title, title: item.title,
featured: item.featured, featured: item.featured,
date: new Date(item.date), date: new Date(item.date),
coverSrc: item.coverSrc, coverSrc: item.cover?.src,
})) }))
return ( return (
-23
View File
@@ -1,23 +0,0 @@
const React = require('react')
const {ext, size} = require('../lib/file')
const {titleCase} = require('../lib/string')
const Document = ({title, url, imageUrl, fileUrl, fileName, fileSize}) => (
<div className="document">
<div className="document__image">
<a href={fileUrl} target="_blank" className="invisible">
<img src={imageUrl} alt={title}/>
</a>
</div>
<div className="document__file">
<span>{titleCase(title)}</span>
</div>
<div className="document__file-info">
<a href={fileUrl} target="_blank">{ext(fileName)} ({size(fileSize)})</a>
</div>
</div>
)
module.exports = Document
+25
View File
@@ -0,0 +1,25 @@
import { FileDefinition } from 'src/types'
import { ext, size } from 'src/lib/file'
import { titleCase } from 'src/lib/string'
export const File: React.SFC<FileDefinition> = props => (
<div className="document">
<h1>{titleCase(props.name)}</h1>
{!props.cover?.src ? null : (
<div className="document__image">
<a href={props.file.src} target="_blank" className="invisible">
<img src={props.cover.src} alt={props.name} />
</a>
</div>
)}
<div className="document__file">
<span>{titleCase(props.name)}</span>
</div>
<div className="document__file-info">
<a href={props.file.src} target="_blank">{ext(props.file.name)} ({size(props.file.size)})</a>
</div>
</div>
)
+3 -4
View File
@@ -66,11 +66,10 @@ export class MetaBuilder {
return null return null
} }
const artifact = this.image.artifacts.fb
return { return {
image: artifact.src, image: this.image.src,
imageWidth: artifact.width, imageWidth: this.image.width,
imageHeight: artifact.height, imageHeight: this.image.height,
} }
} }
} }
+1 -1
View File
@@ -27,7 +27,7 @@ export async function getPagesCardsByTags(tags: string[]): Promise<PageCardDto[]
'title', 'title',
'featured', 'featured',
'date', 'date',
'coverSrc' 'cover'
] ]
const items = await getPagesByTags<PageCardDto>(tags, { fields, skip, limit, sortBy: '-date' }) const items = await getPagesByTags<PageCardDto>(tags, { fields, skip, limit, sortBy: '-date' })
+25 -12
View File
@@ -21,7 +21,20 @@ export type PageCardDto = {
title: string title: string
featured: boolean featured: boolean
date: string date: string
coverSrc: string cover?: ImageDefinition
}
export type FileDefinition = {
url: string
slug: string
name: string
cover?: ImageDefinition
file: {
name: string
size: string
type: string
src: string
}
} }
export interface IPage { export interface IPage {
@@ -30,7 +43,7 @@ export interface IPage {
url: string url: string
data: string data: string
date: string date: string
preview: ImageDefinition cover: ImageDefinition
description: string description: string
tokens: any[] tokens: any[]
tags: ITag[] tags: ITag[]
@@ -96,14 +109,14 @@ export type ImageArtifact = {
} }
export type ImageDefinition = { export type ImageDefinition = {
file: string width: number
hash: string height: number
artifacts: { src: string
original: ImageArtifact
large?: ImageArtifact // file: string
big?: ImageArtifact // hash: string
medium?: ImageArtifact // artifacts: {
small?: ImageArtifact // original: ImageArtifact
fb?: ImageArtifact // large?: ImageArtifact
} // }
} }