strapi card grid support
This commit is contained in:
1 parent
10c27f0ad5
commit
88bb059094
6 files changed
+65
-22
No files matched your search
@@ -15,6 +15,7 @@ import { Html } from 'src/components/Html'
|
|||||||
import { Youtube } from '@/components/Youtube'
|
import { Youtube } from '@/components/Youtube'
|
||||||
import { createPage, createPageUrls } from '@/remote/factory'
|
import { createPage, createPageUrls } from '@/remote/factory'
|
||||||
import { paramsToSlug } from '@/remote/lib'
|
import { paramsToSlug } from '@/remote/lib'
|
||||||
|
import { PageGrid } from '@/components/PageGrid'
|
||||||
|
|
||||||
async function getUrls() {
|
async function getUrls() {
|
||||||
let urls = []
|
let urls = []
|
||||||
@@ -147,6 +148,14 @@ const Index: NextPage<Props> = props => (
|
|||||||
<File key={i} {...x.data} />
|
<File key={i} {...x.data} />
|
||||||
)
|
)
|
||||||
|
|
||||||
|
case 'grid':
|
||||||
|
return (
|
||||||
|
<PageGrid
|
||||||
|
key={i}
|
||||||
|
items={x.data.items}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<pre key={i}>
|
<pre key={i}>
|
||||||
|
|||||||
+3
-18
@@ -15,21 +15,7 @@ type Props = {
|
|||||||
items: PageCardDto[]
|
items: PageCardDto[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const Index: NextPage<Props> = props => {
|
const Index: NextPage<Props> = props => (
|
||||||
const items = props.items.map<PageCardData>(item => ({
|
|
||||||
id: item.id,
|
|
||||||
url: item.url,
|
|
||||||
title: item.title,
|
|
||||||
featured: item.featured,
|
|
||||||
date: new Date(item.date),
|
|
||||||
cover: {
|
|
||||||
src: item.cover.src,
|
|
||||||
width: item.cover.width,
|
|
||||||
height: item.cover.height,
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
return (
|
|
||||||
<App
|
<App
|
||||||
showAuthor={true}
|
showAuthor={true}
|
||||||
wide={true}
|
wide={true}
|
||||||
@@ -46,11 +32,10 @@ const Index: NextPage<Props> = props => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<PageGrid
|
<PageGrid
|
||||||
items={items}
|
items={props.items}
|
||||||
/>
|
/>
|
||||||
</App>
|
</App>
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
export const getStaticProps = async () => {
|
export const getStaticProps = async () => {
|
||||||
const url = 'https://hudozka.tmshv.com/home'
|
const url = 'https://hudozka.tmshv.com/home'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import { ImageSize, PageCardData } from 'src/types'
|
import { ImageSize, PageCardData, PageCardDto } from 'src/types'
|
||||||
import { CardGrid } from '../CardGrid'
|
import { CardGrid } from '../CardGrid'
|
||||||
import { Card, CardLayout } from '../Card'
|
import { Card, CardLayout } from '../Card'
|
||||||
import { Date } from './Date'
|
import { Date } from './Date'
|
||||||
@@ -10,7 +10,7 @@ import { Button } from '../Button'
|
|||||||
import { useState, useCallback } from 'react'
|
import { useState, useCallback } from 'react'
|
||||||
|
|
||||||
export type PageGridProps = {
|
export type PageGridProps = {
|
||||||
items: PageCardData[]
|
items: PageCardDto[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PageGrid: React.FC<PageGridProps> = props => {
|
export const PageGrid: React.FC<PageGridProps> = props => {
|
||||||
|
|||||||
+29
-1
@@ -1,7 +1,7 @@
|
|||||||
import { getResizedUrl } from "@/lib/image";
|
import { getResizedUrl } from "@/lib/image";
|
||||||
import { 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, StrapiComponentCardGrid } from "./types";
|
||||||
|
|
||||||
export function createPageUrls(pages: StrapiPage[]) {
|
export function createPageUrls(pages: StrapiPage[]) {
|
||||||
return {
|
return {
|
||||||
@@ -76,6 +76,15 @@ export function createPageTokens(components: StrapiComponent[]): Token[] {
|
|||||||
return createEmbed(component)
|
return createEmbed(component)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'hudozka.card-grid': {
|
||||||
|
return {
|
||||||
|
token: 'grid',
|
||||||
|
data: {
|
||||||
|
items: component.items.map(createCardGrid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
token: 'text',
|
token: 'text',
|
||||||
@@ -132,6 +141,25 @@ function isCardFeatured(card: StrapiPageCard): boolean {
|
|||||||
return card.layout === 'big' || card.layout === 'medium'
|
return card.layout === 'big' || card.layout === 'medium'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createCardGrid(card: StrapiPageCard): PageCardDto {
|
||||||
|
// const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE
|
||||||
|
|
||||||
|
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: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function createHomeCards(data: StrapiHome): PageCardDto[] {
|
export function createHomeCards(data: StrapiHome): PageCardDto[] {
|
||||||
// const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE
|
// const cover = item.coverSrc ?? process.env.APP_CARD_DEFAULT_IMAGE
|
||||||
|
|
||||||
|
|||||||
@@ -73,11 +73,18 @@ export type StrapiComponentEmbed = {
|
|||||||
src: string,
|
src: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type StrapiComponentCardGrid = {
|
||||||
|
__component: "hudozka.card-grid",
|
||||||
|
id: number,
|
||||||
|
items: StrapiPageCard[],
|
||||||
|
}
|
||||||
|
|
||||||
export type StrapiComponent =
|
export type StrapiComponent =
|
||||||
| StrapiComponentText
|
| StrapiComponentText
|
||||||
| StrapiComponentImage
|
| StrapiComponentImage
|
||||||
| StrapiComponentDocument
|
| StrapiComponentDocument
|
||||||
| StrapiComponentEmbed
|
| StrapiComponentEmbed
|
||||||
|
| StrapiComponentCardGrid
|
||||||
|
|
||||||
export type StrapiTag = {
|
export type StrapiTag = {
|
||||||
id: number,
|
id: number,
|
||||||
|
|||||||
+15
-1
@@ -158,4 +158,18 @@ export type InstagramToken = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Token = TextToken | ImageToken | FileToken | HtmlToken | YoutubeToken | InstagramToken
|
export type GridToken = {
|
||||||
|
token: 'grid'
|
||||||
|
data: {
|
||||||
|
items: PageCardDto[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Token =
|
||||||
|
| TextToken
|
||||||
|
| ImageToken
|
||||||
|
| FileToken
|
||||||
|
| HtmlToken
|
||||||
|
| YoutubeToken
|
||||||
|
| InstagramToken
|
||||||
|
| GridToken
|
||||||
Reference in new issue
Block a user