home page strapi integration
This commit is contained in:
1 parent
91982b8c99
commit
87f4f6a1b8
8 files changed
+101
-136
No files matched your search
+27
-2
@@ -1,7 +1,7 @@
|
||||
import { getResizedUrl, imageSrc } from "@/lib/image";
|
||||
import { IPage, Token } from "@/types";
|
||||
import { IPage, PageCardDto, Token } from "@/types";
|
||||
import { asItem } from "./lib";
|
||||
import { StrapiComponent, StrapiPage } from "./types";
|
||||
import { StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard } from "./types";
|
||||
|
||||
export function createPageTokens(components: StrapiComponent[]): Token[] {
|
||||
return components.map(component => {
|
||||
@@ -86,4 +86,29 @@ export function createPage(res: StrapiPage | StrapiPage[]): IPage {
|
||||
// breadcrumb?: [],
|
||||
featured: false,
|
||||
}
|
||||
}
|
||||
|
||||
function isCardFeatured(card: StrapiPageCard): boolean {
|
||||
return card.layout === 'big' || card.layout === 'medium'
|
||||
}
|
||||
|
||||
export function createHomeCards(data: StrapiHome): PageCardDto[] {
|
||||
// const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE
|
||||
|
||||
return data.cards.map(card => {
|
||||
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: '',
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -110,4 +110,19 @@ export type StrapiPage = {
|
||||
// ],
|
||||
// "breadcrumbs": [],
|
||||
// "breadcrumbRelations": []
|
||||
}
|
||||
|
||||
export type StrapiHome = {
|
||||
id: number,
|
||||
title: string
|
||||
cards: StrapiPageCard[]
|
||||
// "created_at": "2021-02-04T04:12:38.291Z",
|
||||
// "updated_at": "2021-02-04T16:28:30.961Z",
|
||||
}
|
||||
|
||||
export type StrapiPageCard = {
|
||||
__component: 'hudozka.page-card',
|
||||
id: number,
|
||||
page: StrapiPage,
|
||||
layout: 'small' | 'medium' | 'big',
|
||||
}
|
||||
Reference in new issue
Block a user