api fixes
This commit is contained in:
1 parent
70094eab73
commit
6dceff6c85
3 files changed
+25
-22
No files matched your search
+21
-18
@@ -1,7 +1,6 @@
|
|||||||
import { getResizedUrl } from "@/lib/image";
|
import { ImageDefinition, IPage, ITag, PageCardDto, Token } from "@/types";
|
||||||
import { IPage, ITag, PageCardDto, Token } from "@/types";
|
|
||||||
import { asItem } from "./lib";
|
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[]) {
|
export function createPageUrls(pages: StrapiPage[]) {
|
||||||
return {
|
return {
|
||||||
@@ -59,11 +58,6 @@ export function createPageTokens(components: StrapiComponent[]): Token[] {
|
|||||||
url: component.media.url,
|
url: component.media.url,
|
||||||
slug: 'jopa',
|
slug: 'jopa',
|
||||||
image_url: component.media.url,
|
image_url: component.media.url,
|
||||||
// image_url: getResizedUrl(component.media.url, {
|
|
||||||
// width: 200,
|
|
||||||
// height: 200,
|
|
||||||
// n: 1,
|
|
||||||
// }),
|
|
||||||
file_url: component.media.url,
|
file_url: component.media.url,
|
||||||
title: component.title,
|
title: component.title,
|
||||||
file_size: component.media.size * 1000,
|
file_size: component.media.size * 1000,
|
||||||
@@ -144,27 +138,36 @@ function isCardFeatured(card: StrapiPageCard): boolean {
|
|||||||
return card.layout === 'big' || card.layout === 'medium'
|
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 {
|
export function createCardGrid(card: StrapiPageCard): PageCardDto {
|
||||||
// const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE
|
// 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 {
|
return {
|
||||||
id: card.id,
|
id: card.id,
|
||||||
// id: card.page.id,
|
|
||||||
url: card.page.slug,
|
url: card.page.slug,
|
||||||
title: card.page.title,
|
title: card.page.title,
|
||||||
featured: isCardFeatured(card),
|
featured: isCardFeatured(card),
|
||||||
date: card.page.date,
|
date: card.page.date,
|
||||||
cover: {
|
cover,
|
||||||
src: card.page.cover.url,
|
|
||||||
width: card.page.cover.width,
|
|
||||||
height: card.page.cover.height,
|
|
||||||
alt: card.page.title,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createHomeCards(data: StrapiHome): PageCardDto[] {
|
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)
|
||||||
}
|
}
|
||||||
+2
-2
@@ -10,7 +10,7 @@ type StrapiMediaObject = {
|
|||||||
// "path": null,
|
// "path": null,
|
||||||
}
|
}
|
||||||
|
|
||||||
type StrapiMedia = StrapiMediaObject & {
|
export type StrapiMedia = StrapiMediaObject & {
|
||||||
id: number,
|
id: number,
|
||||||
alternativeText: string | null,
|
alternativeText: string | null,
|
||||||
caption: string | null,
|
caption: string | null,
|
||||||
@@ -100,7 +100,7 @@ export type StrapiPage = {
|
|||||||
title: string,
|
title: string,
|
||||||
excerpt: string,
|
excerpt: string,
|
||||||
slug: string,
|
slug: string,
|
||||||
date?: string,
|
date: string | null,
|
||||||
cover?: StrapiMedia,
|
cover?: StrapiMedia,
|
||||||
published_at: string,
|
published_at: string,
|
||||||
created_at: string,
|
created_at: string,
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ export type PageCardDto = {
|
|||||||
url: string
|
url: string
|
||||||
title: string
|
title: string
|
||||||
featured: boolean
|
featured: boolean
|
||||||
date: string
|
date: string | null
|
||||||
cover?: ImageDefinition
|
cover: ImageDefinition
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FileDefinition = {
|
export type FileDefinition = {
|
||||||
|
|||||||
Reference in new issue
Block a user