Skip to content

Commit 9a7c5d1

Browse files
authored
Merge pull request #17 from saitoukun/hotfix/fix-BookmarkValueType
fix BookmarkValueType
2 parents 2c1b017 + 6cdd2e7 commit 9a7c5d1

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/block.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -363,39 +363,53 @@ export const Block: React.FC<Block> = props => {
363363
</div>
364364
);
365365
case "bookmark":
366+
const link = blockValue.properties.link
367+
const title = blockValue.properties.title ?? link
368+
const description = blockValue.properties.description
369+
const block_color = blockValue.format?.block_color
370+
const bookmark_icon = blockValue.format?.bookmark_icon
371+
const bookmark_cover = blockValue.format?.bookmark_cover
372+
366373
return (
367374
<div className="notion-row">
368375
<a
369376
target="_blank"
370377
rel="noopener noreferrer"
371378
className={classNames(
372379
"notion-bookmark",
373-
blockValue.format.block_color &&
374-
`notion-${blockValue.format.block_color}`
380+
block_color &&
381+
`notion-${block_color}`
375382
)}
376-
href={blockValue.properties.link[0][0]}
383+
href={link[0][0]}
377384
>
378385
<div>
379386
<div className="notion-bookmark-title">
380-
{renderChildText(blockValue.properties.title)}
381-
</div>
382-
<div className="notion-bookmark-description">
383-
{renderChildText(blockValue.properties.description)}
387+
{renderChildText(title)}
384388
</div>
389+
{description && (
390+
<div className="notion-bookmark-description">
391+
{renderChildText(description)}
392+
</div>
393+
)}
394+
385395
<div className="notion-bookmark-link">
396+
{bookmark_icon && (
397+
<img
398+
src={bookmark_icon}
399+
alt={getTextContent(title)}
400+
/>
401+
)}
402+
<div>{renderChildText(link)}</div>
403+
</div>
404+
</div>
405+
{bookmark_cover && (
406+
<div className="notion-bookmark-image">
386407
<img
387-
src={blockValue.format.bookmark_icon}
388-
alt={getTextContent(blockValue.properties.title)}
408+
src={bookmark_cover}
409+
alt={getTextContent(title)}
389410
/>
390-
<div>{renderChildText(blockValue.properties.link)}</div>
391411
</div>
392-
</div>
393-
<div className="notion-bookmark-image">
394-
<img
395-
src={blockValue.format.bookmark_cover}
396-
alt={getTextContent(blockValue.properties.title)}
397-
/>
398-
</div>
412+
)}
399413
</a>
400414
</div>
401415
);

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ interface BookmarkValueType extends BaseValueType {
110110
type: "bookmark";
111111
properties: {
112112
link: DecorationType[];
113-
title: DecorationType[];
114-
description: DecorationType[];
113+
title?: DecorationType[];
114+
description?: DecorationType[];
115115
};
116-
format: {
116+
format?: {
117117
block_color?: string;
118118
bookmark_icon: string;
119119
bookmark_cover: string;

0 commit comments

Comments
 (0)