diff --git a/pages/[...slug].tsx b/pages/[...slug].tsx index 0af772c7..b7a4031b 100644 --- a/pages/[...slug].tsx +++ b/pages/[...slug].tsx @@ -62,7 +62,7 @@ export const getStaticProps = async (ctx: any) => { const breadcrumbSize = page?.breadcrumb?.length ?? 0 const breadcrumb = breadcrumbSize < 2 ? null : page.breadcrumb const meta = (new MetaBuilder()) - .setImage(page.preview) + .setImage(page.cover) .setTitle(page.title) .setDescription(description) .build() diff --git a/pages/collective.tsx b/pages/collective.tsx index 30e02884..f111d753 100644 --- a/pages/collective.tsx +++ b/pages/collective.tsx @@ -109,15 +109,13 @@ export const getStaticProps = async (ctx: NextPageContext) => { const data: CardData[] = pages .filter(Boolean) .map(x => { - const image = x.preview.artifacts.large - return { title: x.title, caption: x.description, href: x.url, imageAlt: title, - imageSrc: image.src, - imageSrcSet: imageSrcSet(image.src, [ImageSize.medium, ImageSize.small]) + imageSrc: x.cover.src, + imageSrcSet: imageSrcSet(x.cover.src, [ImageSize.medium, ImageSize.small]) } }) diff --git a/pages/document/[slug].tsx b/pages/document/[slug].tsx index 16327895..667a4beb 100644 --- a/pages/document/[slug].tsx +++ b/pages/document/[slug].tsx @@ -1,16 +1,15 @@ -import React from 'react' import Head from 'next/head' 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 { meta } from 'src/lib/meta' +import { MetaBuilder } from 'src/lib/meta' import { Meta } from 'src/components/Meta' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage } from 'next' -import { IMeta } from 'src/types' +import { IMeta, FileDefinition } from 'src/types' type Props = { - data: any //(file) + data: FileDefinition meta: IMeta } @@ -26,25 +25,28 @@ const Page: NextPage = props => { showAuthor={true} > - {props.data.title} + {props.data.name} - + ) } export const getStaticProps = async (ctx: any) => { - const id = ctx.params.slug - const data = await requestGet(createApiUrl(`/api/files/${id}`), {}) + const slug = ctx.params.slug + const data = await requestGet(createApiUrl(`/api/files/${slug}`), null) + const meta = (new MetaBuilder()) + .setImage(data.cover) + .setTitle(data.name) + .setDescription(data.name) + .build() return { props: { data, - meta: meta({ - // title: file.meta, - }) + meta, } } } diff --git a/pages/index.tsx b/pages/index.tsx index ce5a84c7..0df49ce2 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -20,7 +20,7 @@ const Index: NextPage = props => { title: item.title, featured: item.featured, date: new Date(item.date), - coverSrc: item.coverSrc, + coverSrc: item.cover?.src, })) return ( diff --git a/src/components/Document.js b/src/components/Document.js deleted file mode 100644 index 1b3a473b..00000000 --- a/src/components/Document.js +++ /dev/null @@ -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}) => ( -
-
- - {title}/ - -
- -
- {titleCase(title)} -
- - -
-) - -module.exports = Document diff --git a/src/components/File/index.tsx b/src/components/File/index.tsx new file mode 100644 index 00000000..c2c81632 --- /dev/null +++ b/src/components/File/index.tsx @@ -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 = props => ( +
+

{titleCase(props.name)}

+ + {!props.cover?.src ? null : ( +
+ + {props.name} + +
+ )} + +
+ {titleCase(props.name)} +
+ + +
+) diff --git a/src/lib/meta.ts b/src/lib/meta.ts index 667607f2..6763aed7 100644 --- a/src/lib/meta.ts +++ b/src/lib/meta.ts @@ -66,11 +66,10 @@ export class MetaBuilder { return null } - const artifact = this.image.artifacts.fb return { - image: artifact.src, - imageWidth: artifact.width, - imageHeight: artifact.height, + image: this.image.src, + imageWidth: this.image.width, + imageHeight: this.image.height, } } } diff --git a/src/rest.ts b/src/rest.ts index a792e864..a8f0fc91 100644 --- a/src/rest.ts +++ b/src/rest.ts @@ -27,7 +27,7 @@ export async function getPagesCardsByTags(tags: string[]): Promise(tags, { fields, skip, limit, sortBy: '-date' }) diff --git a/src/types.ts b/src/types.ts index 7945e4e6..e4a97764 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,7 +21,20 @@ export type PageCardDto = { title: string featured: boolean 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 { @@ -30,7 +43,7 @@ export interface IPage { url: string data: string date: string - preview: ImageDefinition + cover: ImageDefinition description: string tokens: any[] tags: ITag[] @@ -96,14 +109,14 @@ export type ImageArtifact = { } export type ImageDefinition = { - file: string - hash: string - artifacts: { - original: ImageArtifact - large?: ImageArtifact - big?: ImageArtifact - medium?: ImageArtifact - small?: ImageArtifact - fb?: ImageArtifact - } + width: number + height: number + src: string + + // file: string + // hash: string + // artifacts: { + // original: ImageArtifact + // large?: ImageArtifact + // } }