card images blur
This commit is contained in:
1 parent
6f3632fa15
commit
42fdf429e2
4 files changed
+63
-49
No files matched your search
@@ -48,6 +48,8 @@ export const PageGrid: React.FC<PageGridProps> = props => {
|
|||||||
objectFit={'cover'}
|
objectFit={'cover'}
|
||||||
src={item.cover.src}
|
src={item.cover.src}
|
||||||
alt={item.cover.alt}
|
alt={item.cover.alt}
|
||||||
|
placeholder={'blur'}
|
||||||
|
blurDataURL={item.cover.blur}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
layout={layout}
|
layout={layout}
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
import { IMeta, ImageDefinition } from 'src/types'
|
import { IMeta, Pic } from 'src/types'
|
||||||
|
|
||||||
export function meta(props: Partial<IMeta>): IMeta {
|
export function meta(props: Partial<IMeta>): IMeta {
|
||||||
const path = props.url || '/'
|
const path = props.url || '/'
|
||||||
@@ -25,7 +25,7 @@ export function meta(props: Partial<IMeta>): IMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MetaBuilder {
|
export class MetaBuilder {
|
||||||
private image: ImageDefinition
|
private image: Pic
|
||||||
private title: string
|
private title: string
|
||||||
private description: string
|
private description: string
|
||||||
private data: Partial<IMeta>
|
private data: Partial<IMeta>
|
||||||
@@ -45,7 +45,7 @@ export class MetaBuilder {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setImage(param: ImageDefinition) {
|
setImage(param: Pic) {
|
||||||
this.image = param
|
this.image = param
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-36
@@ -1,4 +1,4 @@
|
|||||||
import { ImageDefinition, IMenu, IPage, ITag, PageCardDto, Pic, Token } from "@/types";
|
import { IMenu, IPage, ITag, PageCardDto, Pic, Token } from "@/types";
|
||||||
import { asItem } from "./lib";
|
import { asItem } from "./lib";
|
||||||
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia, StrapiMenu } from "./types";
|
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia, StrapiMenu } from "./types";
|
||||||
import { typograf, markdownToHtml } from 'src/lib/text'
|
import { typograf, markdownToHtml } from 'src/lib/text'
|
||||||
@@ -16,15 +16,6 @@ export function isYoutubeUrl(url: string): boolean {
|
|||||||
return /youtube\.com/.test(url)
|
return /youtube\.com/.test(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCoverImage(media?: StrapiMedia) {
|
|
||||||
return media ? createImageFromMedia(media) : {
|
|
||||||
src: 'https://hudozkacdn.tmshv.com/main_fad9fdf29a.jpg',
|
|
||||||
width: 1920,
|
|
||||||
height: 1858,
|
|
||||||
alt: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createEmbed(component: StrapiComponentEmbed): Token {
|
export function createEmbed(component: StrapiComponentEmbed): Token {
|
||||||
if (isYoutubeUrl(component.src)) {
|
if (isYoutubeUrl(component.src)) {
|
||||||
return {
|
return {
|
||||||
@@ -51,20 +42,10 @@ export async function createPageToken(component: StrapiComponent): Promise<Token
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'hudozka.image': {
|
case 'hudozka.image': {
|
||||||
const src = component.media.formats?.large?.url ?? component.media.url
|
const data = await createPicFromMedia(component.media, {
|
||||||
const thumb = component.media.formats?.thumbnail?.url ?? component.media.url
|
alternativeText: component.caption,
|
||||||
const data: Pic = {
|
|
||||||
alt: component.caption,
|
|
||||||
caption: component.caption,
|
caption: component.caption,
|
||||||
src,
|
})
|
||||||
width: component.media.width,
|
|
||||||
height: component.media.height,
|
|
||||||
}
|
|
||||||
|
|
||||||
const blur = await encodeImageToBlurhash(thumb)
|
|
||||||
if (blur) {
|
|
||||||
data.blur = blur
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
token: 'image',
|
token: 'image',
|
||||||
@@ -94,12 +75,14 @@ export async function createPageToken(component: StrapiComponent): Promise<Token
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'hudozka.card-grid': {
|
case 'hudozka.card-grid': {
|
||||||
|
const items = await Promise.all(component.items
|
||||||
|
.filter(Boolean)
|
||||||
|
.map(createCardGrid)
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
token: 'grid',
|
token: 'grid',
|
||||||
data: {
|
data: {
|
||||||
items: component.items
|
items,
|
||||||
.filter(Boolean)
|
|
||||||
.map(createCardGrid)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +113,7 @@ export async function createPage(res: StrapiPage | StrapiPage[]): Promise<IPage
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const cover = getCoverImage(item.cover)
|
const cover = await getCoverImage(item.cover)
|
||||||
const tags: ITag[] = item.tags.map(tag => ({
|
const tags: ITag[] = item.tags.map(tag => ({
|
||||||
id: tag.id,
|
id: tag.id,
|
||||||
name: tag.name,
|
name: tag.name,
|
||||||
@@ -167,17 +150,50 @@ function isCardFeatured(card: StrapiPageCard): boolean {
|
|||||||
return card.layout === 'big' || card.layout === 'medium'
|
return card.layout === 'big' || card.layout === 'medium'
|
||||||
}
|
}
|
||||||
|
|
||||||
function createImageFromMedia(media: StrapiMedia): ImageDefinition {
|
export async function getCoverImage(media?: StrapiMedia): Promise<Pic> {
|
||||||
|
if (media) {
|
||||||
|
return createPicFromMedia(media)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
src: media.url,
|
src: 'https://hudozkacdn.tmshv.com/main_fad9fdf29a.jpg',
|
||||||
width: media.width,
|
width: 1920,
|
||||||
height: media.height,
|
height: 1858,
|
||||||
alt: media.alternativeText ?? '',
|
// alt: '',
|
||||||
|
// caption: '',
|
||||||
|
// blur: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createCardGrid(card: StrapiPageCard): PageCardDto {
|
async function createPicFromMedia(media: StrapiMedia, overrides?: Partial<StrapiMedia>): Promise<Pic> {
|
||||||
const cover = getCoverImage(card.page.cover)
|
const src = media.formats?.large?.url ?? media.url
|
||||||
|
const pic: Pic = {
|
||||||
|
src,
|
||||||
|
width: media.width,
|
||||||
|
height: media.height,
|
||||||
|
}
|
||||||
|
|
||||||
|
const alt = overrides?.alternativeText ?? media.alternativeText ?? undefined
|
||||||
|
if (alt) {
|
||||||
|
pic.alt = alt
|
||||||
|
}
|
||||||
|
|
||||||
|
const caption = overrides?.caption ?? media.caption ?? undefined
|
||||||
|
if (caption) {
|
||||||
|
pic.caption = caption
|
||||||
|
}
|
||||||
|
|
||||||
|
const thumb = media.formats?.thumbnail?.url ?? media.url
|
||||||
|
const blur = await encodeImageToBlurhash(thumb)
|
||||||
|
if (blur) {
|
||||||
|
pic.blur = blur
|
||||||
|
}
|
||||||
|
|
||||||
|
return pic
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCardGrid(card: StrapiPageCard): Promise<PageCardDto> {
|
||||||
|
const cover = await getCoverImage(card.page.cover)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: card.id,
|
id: card.id,
|
||||||
@@ -189,8 +205,10 @@ export function createCardGrid(card: StrapiPageCard): PageCardDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createHomeCards(data: StrapiHome): PageCardDto[] {
|
export async function createHomeCards(data: StrapiHome): Promise<PageCardDto[]> {
|
||||||
return data.cards
|
const items = await Promise.all(data.cards
|
||||||
.map(createCardGrid)
|
.map(createCardGrid)
|
||||||
|
)
|
||||||
|
return items
|
||||||
.filter(x => !!x.url)
|
.filter(x => !!x.url)
|
||||||
}
|
}
|
||||||
+4
-10
@@ -14,14 +14,14 @@ export type PageCardDto = {
|
|||||||
title: string
|
title: string
|
||||||
featured: boolean
|
featured: boolean
|
||||||
date: string | null
|
date: string | null
|
||||||
cover: ImageDefinition
|
cover: Pic
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FileDefinition = {
|
export type FileDefinition = {
|
||||||
url: string
|
url: string
|
||||||
slug: string
|
slug: string
|
||||||
name: string
|
name: string
|
||||||
cover?: ImageDefinition
|
cover?: Pic
|
||||||
file: {
|
file: {
|
||||||
name: string
|
name: string
|
||||||
size: string
|
size: string
|
||||||
@@ -36,7 +36,7 @@ export interface IPage {
|
|||||||
url: string
|
url: string
|
||||||
data: string
|
data: string
|
||||||
date: string
|
date: string
|
||||||
cover: ImageDefinition
|
cover: Pic
|
||||||
description: string
|
description: string
|
||||||
tokens: any[]
|
tokens: any[]
|
||||||
tags: ITag[]
|
tags: ITag[]
|
||||||
@@ -89,13 +89,7 @@ export interface ITag {
|
|||||||
name: string
|
name: string
|
||||||
slug: string
|
slug: string
|
||||||
href: string
|
href: string
|
||||||
}
|
count: number
|
||||||
|
|
||||||
export type ImageDefinition = {
|
|
||||||
width: number
|
|
||||||
height: number
|
|
||||||
src: string
|
|
||||||
alt?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Pic = {
|
export type Pic = {
|
||||||
|
|||||||
Reference in new issue
Block a user