Skip to content

Commit

Permalink
feat: implemented new paramters
Browse files Browse the repository at this point in the history
  • Loading branch information
yungblud committed Dec 29, 2023
1 parent 12853b5 commit 1bc942a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 16 additions & 3 deletions packages/notion-utils/src/utils/notions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export const queryDetail = async (
return null;
};

export const getBlocks = async (_blockId: string) => {
export const getBlocks = async ({
blockId: _blockId,
withUploadCloudinary = false,
}: {
blockId: string;
withUploadCloudinary?: boolean;
}) => {
const blockId = _blockId.replaceAll("-", "");

let next: string | undefined = "";
Expand Down Expand Up @@ -79,10 +85,17 @@ export const getBlocks = async (_blockId: string) => {
children: any;
};
if (generated.has_children) {
const children = await getBlocks(block.id);
const children = await getBlocks({
blockId: block.id,
withUploadCloudinary,
});
generated.children = children;
}
if (process.env.NODE_ENV === "production" && generated.type === "image") {
if (
process.env.NODE_ENV === "production" &&
generated.type === "image" &&
withUploadCloudinary
) {
if (generated.image.type === "file") {
const cloudinary = await uploadCloudinary(generated.image.file.url);
generated.image.file.url = cloudinary.secure_url;
Expand Down
6 changes: 5 additions & 1 deletion packages/surflog/lib/notion.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ export const getPageFromSlug = cache(
)

export const getBlocks = cache(
async (blockID) => await getBlocksNotion(blockID)
async (blockId) =>
await getBlocksNotion({
blockId,
withUploadCloudinary: true,
})
)

0 comments on commit 1bc942a

Please sign in to comment.