-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b373b5f
commit 322c4a6
Showing
12 changed files
with
315 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { cn } from "@/lib/utils"; | ||
import { IconRender } from "./emoji"; | ||
import RichText from "../text"; | ||
|
||
interface CalloutBlockProps { | ||
block: any; | ||
className?: string | undefined; | ||
} | ||
|
||
export function CalloutRender({ block, className }: CalloutBlockProps) { | ||
const {id, callout: {icon, rich_text}} = block; | ||
return ( | ||
<div id={id} | ||
className={cn( | ||
className, | ||
"inline-flex w-full items-center box-border border rounded-[4px] border-none p-4 bg-stone-100" | ||
)} | ||
> | ||
{icon && ( | ||
<IconRender type={icon.type} emoji={icon.emoji} external={icon.external} file={icon.file}/> | ||
)} | ||
<div className="whitespace-pre-wrap break-words ml-3"> | ||
<RichText title={rich_text} /> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// import { cn } from "@/lib/utils"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
import Image from "next/image"; | ||
|
||
|
||
interface IconProps { | ||
type: string; | ||
emoji?: string | undefined; | ||
external?: | ||
| { | ||
url: string; | ||
} | ||
| undefined; | ||
file?: | ||
| { | ||
url: string; | ||
expiry_time: string; | ||
} | ||
| undefined; | ||
} | ||
|
||
export function IconRender( | ||
{ type, emoji, external, file }: IconProps, | ||
className?: string | undefined | ||
) { | ||
if (type == "emoji") { | ||
return ( | ||
<div | ||
className={cn(className, "self-start w-6 h-6 text-xl leading-[1em]")} | ||
> | ||
{emoji} | ||
</div> | ||
); | ||
} | ||
const url = external?.url || file?.url; | ||
if (!url) { | ||
return null; | ||
} | ||
|
||
// TODO: use nextconfig.js to get the base path | ||
const u = new URL(url || ""); | ||
if ( | ||
u.hostname.endsWith("s3.us-west-2.amazonaws.com") || | ||
u.hostname.startsWith("www.notion.so") | ||
) { | ||
return ( | ||
<Image | ||
src={url} | ||
className={cn("self-start w-6 h-6 text-[1em] leading-[1em]", className)} | ||
width={40} | ||
height={40} | ||
loading="lazy" | ||
decoding="async" | ||
alt="external icon" | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img | ||
src={url} | ||
className={cn("self-start w-6 h-6 text-[1em] leading-[1em]", className)} | ||
loading="lazy" | ||
decoding="async" | ||
alt="external icon" | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// import { cn } from "@/lib/utils"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
import Image from "next/image"; | ||
import RichText from "../text"; | ||
|
||
// "image": { | ||
// "caption": [ | ||
// { | ||
// "type": "text", | ||
// "text": { | ||
// "content": "External Image", | ||
// "link": null | ||
// }, | ||
// "annotations": { | ||
// "bold": false, | ||
// "italic": false, | ||
// "strikethrough": false, | ||
// "underline": false, | ||
// "code": false, | ||
// "color": "default" | ||
// }, | ||
// "plain_text": "External Image", | ||
// "href": null | ||
// } | ||
// ], | ||
// "type": "external", | ||
// "external": { | ||
// "url": "https://images.unsplash.com/photo-1524995997946-a1c2e315a42f?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb" | ||
// } | ||
// } | ||
// "image": { | ||
// "caption": [ | ||
// { | ||
// "type": "text", | ||
// "text": { | ||
// "content": "Notion-hosted image", | ||
// "link": null | ||
// }, | ||
// "annotations": { | ||
// "bold": false, | ||
// "italic": false, | ||
// "strikethrough": false, | ||
// "underline": false, | ||
// "code": false, | ||
// "color": "default" | ||
// }, | ||
// "plain_text": "Notion-hosted image", | ||
// "href": null | ||
// } | ||
// ], | ||
// "type": "file", | ||
// "file": { | ||
// "url": "https://prod-files-secure.s3.us-west-2.amazonaws.com/0bb5601d-5b11-49c2-a0fd-29f4c2b522b6/d61aedd6-da5f-473d-a08a-da664b6c1456/isaac-martin-Apkr4nfK1mU-unsplash.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240201%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240201T112113Z&X-Amz-Expires=3600&X-Amz-Signature=112d428a047b0f58c46e0c1a00278728e3099b737b63d25df5ea09f97f5771f4&X-Amz-SignedHeaders=host&x-id=GetObject", | ||
// "expiry_time": "2024-02-01T12:21:13.031Z" | ||
// } | ||
// } | ||
|
||
// interface ImageProps { | ||
// id: string; | ||
// type: string; | ||
// external?: | ||
// | { | ||
// url: string; | ||
// } | ||
// | undefined; | ||
// file?: | ||
// | { | ||
// url: string; | ||
// expiry_time: string; | ||
// } | ||
// | undefined; | ||
// } | ||
|
||
export function ImageRender({block, className, size = "md"}: {block: any, className?: string | undefined, size ?: string | undefined}) { | ||
const { id, image: {caption, type, external, file} } = block; | ||
|
||
const url = external?.url || file?.url; | ||
if (!url) { | ||
return null; | ||
} | ||
|
||
// TODO: use nextconfig.js to get the base path | ||
let hosted = false; | ||
const u = new URL(url || ""); | ||
if ( | ||
u.hostname.endsWith("s3.us-west-2.amazonaws.com") || | ||
u.hostname.startsWith("www.notion.so") | ||
) { | ||
hosted = true; | ||
} | ||
|
||
// TODO: Notion API don't return the correct image size. May be we need to set the image size in caption? | ||
return ( | ||
<figure | ||
key={id} | ||
className={cn( | ||
className, | ||
"max-w-[100vw] min-w-full self-center flex flex-col mx-0 my-2 text-sm " | ||
)} | ||
> | ||
{hosted ? ( | ||
<Image | ||
src={url} | ||
className={cn("rounded-lg shadow-md w-fit")} | ||
width={448} | ||
height={448} | ||
sizes="(min-width: 1024px) 384px, (min-width: 768px) 288px, (min-width: 640px) 224px, 100vw" | ||
alt={caption[0]?.plain_text} | ||
/> | ||
) : ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img | ||
src={url} | ||
width="auto" | ||
className={cn("rounded-lg shadow-md w-fit", { | ||
"h-32": size === "sxm", | ||
"h-64": size === "md", | ||
"h-96": size === "lg", | ||
})} | ||
loading="lazy" | ||
decoding="async" | ||
alt={caption[0]?.plain_text} | ||
/> | ||
)} | ||
{caption && caption.length > 0 && ( | ||
<figcaption className="font-normal"> | ||
<RichText title={caption} /> | ||
</figcaption> | ||
)} | ||
</figure> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.