Skip to content

Commit 22a0499

Browse files
committed
add default images
1 parent c5e6c7f commit 22a0499

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

frontend/main/src/components/PostMedia.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function PostMedia({
2323
return false;
2424
}
2525
};
26-
26+
console.log(post);
2727
return (
2828
<>
2929
{post?.coverVideo && Object.keys(post.coverVideo).length ? (
@@ -82,6 +82,17 @@ export default function PostMedia({
8282
layout="responsive"
8383
priority
8484
/>
85+
) : !noImage &&
86+
(post?.cover?.external?.url || post?.cover?.file?.url) ? (
87+
<Image
88+
loader={({ src }) => src}
89+
src={post?.cover?.external?.url || post?.cover?.file?.url || ''}
90+
alt={post.title}
91+
width="480"
92+
height="270"
93+
layout="responsive"
94+
priority
95+
/>
8596
) : (
8697
<></>
8798
)}

frontend/main/src/components/notion-custom-blocks/RenderBlocks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const myMapper = {
3535
].includes(media?.src) ? (
3636
<Image
3737
className={`${className || ''} object-contain `}
38-
src={getCloudinaryPublicId(media?.src?.split('/'))}
38+
src={getCloudinaryPublicId(media?.src)}
3939
alt={media?.alt || media?.name || ''}
4040
layout="fill"
4141
height="100%"

frontend/main/src/models/post.model.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ export interface Post {
2828
slug: string;
2929
historyId?: string;
3030
postId?: string;
31+
cover?: {
32+
external?: {
33+
url: string;
34+
};
35+
file?: {
36+
url: string;
37+
};
38+
};
3139
coverPhoto?: CoverMedia;
3240
coverVideo?: CoverMedia;
3341
sections?: Section[];

frontend/main/src/services/notion.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const formatPost = async (
196196
authors.push(author);
197197
}
198198
}
199-
let coverPublicId = getCloudinaryPublicId(q?.cover?.external?.url.split('/'));
199+
let coverPublicId = getCloudinaryPublicId(q?.cover?.external?.url);
200200
post = {
201201
...post,
202202
_id: q?.id ? q.id : null,

frontend/main/src/utils/cloudinary/cloudinary.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
export const getCloudinaryPublicId = (coverSegments: string[]): string => {
1+
export const getCloudinaryPublicId = (cover: string): string => {
22
let coverPublicId = '';
3+
4+
const domains = [
5+
'main-codingcatdev-photo',
6+
'ccd-cloudinary',
7+
'dev-codingcatdev-photo',
8+
];
9+
10+
if (!domains.some((d) => cover?.includes(d))) {
11+
return coverPublicId;
12+
}
13+
14+
const coverSegments = cover?.split('/');
15+
316
for (let i = coverSegments?.length; i--; i === 0) {
417
const segment = coverSegments.at(i);
518
if (

0 commit comments

Comments
 (0)