diff --git a/src/remote/factory.ts b/src/remote/factory.ts index 035acd58..95094168 100644 --- a/src/remote/factory.ts +++ b/src/remote/factory.ts @@ -1,7 +1,6 @@ -import { getResizedUrl } from "@/lib/image"; -import { IPage, ITag, PageCardDto, Token } from "@/types"; +import { ImageDefinition, IPage, ITag, PageCardDto, Token } from "@/types"; import { asItem } from "./lib"; -import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard } from "./types"; +import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia } from "./types"; export function createPageUrls(pages: StrapiPage[]) { return { @@ -59,11 +58,6 @@ export function createPageTokens(components: StrapiComponent[]): Token[] { url: component.media.url, slug: 'jopa', image_url: component.media.url, - // image_url: getResizedUrl(component.media.url, { - // width: 200, - // height: 200, - // n: 1, - // }), file_url: component.media.url, title: component.title, file_size: component.media.size * 1000, @@ -144,27 +138,36 @@ function isCardFeatured(card: StrapiPageCard): boolean { return card.layout === 'big' || card.layout === 'medium' } +function createImageFromMedia(media: StrapiMedia): ImageDefinition { + return { + src: media.url, + width: media.width, + height: media.height, + alt: media.alternativeText ?? '', + } +} + export function createCardGrid(card: StrapiPageCard): PageCardDto { // const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE + const cover = card.page.cover ? createImageFromMedia(card.page.cover) : { + src: 'https://hudozkacdn.tmshv.com/main_fad9fdf29a.jpg', + width: 1920, + height: 1858, + alt: '' + } return { id: card.id, - // id: card.page.id, url: card.page.slug, title: card.page.title, featured: isCardFeatured(card), date: card.page.date, - cover: { - src: card.page.cover.url, - width: card.page.cover.width, - height: card.page.cover.height, - alt: card.page.title, - } + cover, } } export function createHomeCards(data: StrapiHome): PageCardDto[] { - // const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE - - return data.cards.map(createCardGrid) + return data.cards + .map(createCardGrid) + .filter(x => !!x.url) } diff --git a/src/remote/types.ts b/src/remote/types.ts index 40d5124e..91d4d197 100644 --- a/src/remote/types.ts +++ b/src/remote/types.ts @@ -10,7 +10,7 @@ type StrapiMediaObject = { // "path": null, } -type StrapiMedia = StrapiMediaObject & { +export type StrapiMedia = StrapiMediaObject & { id: number, alternativeText: string | null, caption: string | null, @@ -100,7 +100,7 @@ export type StrapiPage = { title: string, excerpt: string, slug: string, - date?: string, + date: string | null, cover?: StrapiMedia, published_at: string, created_at: string, diff --git a/src/types.ts b/src/types.ts index 7408e48c..cb1082c4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,8 +13,8 @@ export type PageCardDto = { url: string title: string featured: boolean - date: string - cover?: ImageDefinition + date: string | null + cover: ImageDefinition } export type FileDefinition = {