diff --git a/contributing.md b/contributing.md index 82b351c6..2ef12c7f 100644 --- a/contributing.md +++ b/contributing.md @@ -6,12 +6,12 @@ Suggestions and pull requests are highly encouraged. Have a look at the [open is To develop the project locally, you'll need a recent version of Node.js and `pnpm` installed globally. -To get started, clone the repo and run `pnpm` from the root directory: +To get started, clone the repo and run `pnpm install` from the root directory: ```bash git clone https://github.com/NotionX/react-notion-x.git cd react-notion-x -pnpm +pnpm install ``` This will install dependencies and link all of the local packages together using `lerna`. This includes the example projects which will now point to the local version of your packages. diff --git a/examples/full/pages/[pageId].tsx b/examples/full/pages/[pageId].tsx index bc6c8fe2..99d8227e 100644 --- a/examples/full/pages/[pageId].tsx +++ b/examples/full/pages/[pageId].tsx @@ -16,7 +16,9 @@ export const getStaticProps = async (context: any) => { const recordMap = await notion.getPage(pageId) // NOTE: this isn't necessary; trying to reduce my vercel bill - if (recordMap.block[0]?.value?.space_id !== rootNotionSpaceId) { + const blockIds = Object.keys(recordMap.block) + const firstBlock = blockIds.length > 0 ? recordMap.block[blockIds[0]!] : null + if (rootNotionSpaceId && firstBlock?.value?.space_id !== rootNotionSpaceId) { return { notFound: true } diff --git a/examples/minimal/pages/[pageId].tsx b/examples/minimal/pages/[pageId].tsx index 0f03fc50..96afe004 100644 --- a/examples/minimal/pages/[pageId].tsx +++ b/examples/minimal/pages/[pageId].tsx @@ -9,7 +9,9 @@ export const getStaticProps = async (context: any) => { const recordMap = await notion.getPage(pageId) // NOTE: this isn't necessary; trying to reduce my vercel bill - if (recordMap.block[0]?.value?.space_id !== rootNotionSpaceId) { + const blockIds = Object.keys(recordMap.block) + const firstBlock = blockIds.length > 0 ? recordMap.block[blockIds[0]!] : null + if (rootNotionSpaceId && firstBlock?.value?.space_id !== rootNotionSpaceId) { return { notFound: true } diff --git a/packages/notion-utils/src/map-image-url.ts b/packages/notion-utils/src/map-image-url.ts index 48e4a7f9..fe3d62df 100644 --- a/packages/notion-utils/src/map-image-url.ts +++ b/packages/notion-utils/src/map-image-url.ts @@ -1,5 +1,8 @@ import { type Block } from 'notion-types' +// eslint-disable-next-line security/detect-unsafe-regex +const GIF_REGEXP = /(?:https?:\/\/)?[^\s]+\.gif(?=$|\?|#)/ + export const defaultMapImageUrl = ( url: string | undefined, block: Block @@ -12,6 +15,10 @@ export const defaultMapImageUrl = ( return url } + if (GIF_REGEXP.test(url)) { + return url + } + // more recent versions of notion don't proxy unsplash images if (url.startsWith('https://images.unsplash.com')) { return url diff --git a/packages/react-notion-x/src/components/asset.tsx b/packages/react-notion-x/src/components/asset.tsx index acff9a4b..5e7f07d7 100644 --- a/packages/react-notion-x/src/components/asset.tsx +++ b/packages/react-notion-x/src/components/asset.tsx @@ -274,9 +274,9 @@ export function Asset({ } } } else if (block.type === 'image') { - // console.log('image', block) // TODO: kind of a hack for now. New file.notion.so images aren't signed correctly - if (source.includes('file.notion.so')) { + // Gifs need to use their original file URLs and not the source prop (see #663) + if (!source.includes('.gif') && source.includes('file.notion.so')) { source = block.properties?.source?.[0]?.[0] } const src = mapImageUrl(source, block as Block)