From 67b5a8d58cdb5df73689b5ac3162846935779e06 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Fri, 8 Apr 2022 09:07:25 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/NotionPage.tsx | 29 ++++++++++++++++++++++++----- package.json | 6 +++--- pages/api/social-image.tsx | 11 +---------- yarn.lock | 28 ++++++++++++++-------------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/components/NotionPage.tsx b/components/NotionPage.tsx index 24e229e263..562d8d9f35 100644 --- a/components/NotionPage.tsx +++ b/components/NotionPage.tsx @@ -76,9 +76,27 @@ const propertyLastEditedTimeValue = ( return `Last updated ${formatDate(block?.last_edited_time, { month: 'long' })}` - } else { - return defaultFn() } + + return defaultFn() +} + +const propertyDateValue = ( + { data, schema, pageHeader }, + defaultFn: () => React.ReactNode +) => { + if (pageHeader && schema?.name?.toLowerCase() === 'published') { + const publishDate = data?.[0]?.[1]?.[0]?.[1]?.start_date + console.log('date', { data, publishDate }) + + if (publishDate) { + return `Published ${formatDate(publishDate, { + month: 'long' + })}` + } + } + + return defaultFn() } const propertyTextValue = ( @@ -87,9 +105,9 @@ const propertyTextValue = ( ) => { if (pageHeader && schema?.name?.toLowerCase() === 'author') { return {defaultFn()} - } else { - return defaultFn() } + + return defaultFn() } export const NotionPage: React.FC = ({ @@ -113,7 +131,8 @@ export const NotionPage: React.FC = ({ Tweet, Header: NotionPageHeader, propertyLastEditedTimeValue, - propertyTextValue + propertyTextValue, + propertyDateValue }), [] ) diff --git a/package.json b/package.json index 29bc47b96d..308e3c5302 100644 --- a/package.json +++ b/package.json @@ -39,16 +39,16 @@ "next": "^12.1.1", "next-api-og-image": "^2.2.1", "node-fetch": "^2.6.1", - "notion-client": "^6.9.1", + "notion-client": "^6.9.2", "notion-types": "^6.7.0", - "notion-utils": "^6.9.1", + "notion-utils": "^6.9.2", "p-map": "^5.3.0", "p-memoize": "^6.0.1", "posthog-js": "^1.20.2", "react": "^17.0.2", "react-body-classname": "^1.3.1", "react-dom": "^17.0.2", - "react-notion-x": "^6.9.1", + "react-notion-x": "^6.9.2", "react-static-tweets": "^0.7.2", "react-use": "^17.3.2", "static-tweets": "^0.7.2" diff --git a/pages/api/social-image.tsx b/pages/api/social-image.tsx index cddc3b75fc..3d2761991f 100644 --- a/pages/api/social-image.tsx +++ b/pages/api/social-image.tsx @@ -75,21 +75,12 @@ export default withOGImage<'query', 'id'>({ // getPageProperty('Description', block, recordMap) || // config.description - const timeUpdated = getPageProperty( - 'Last Updated', - block, - recordMap - ) const timePublished = getPageProperty( 'Published', block, recordMap ) - const dateUpdated = timeUpdated - ? new Date(timeUpdated) - : timePublished - ? new Date(timePublished) - : undefined + const dateUpdated = timePublished ? new Date(timePublished) : undefined const date = isBlogPost && dateUpdated ? `${dateUpdated.toLocaleString('en-US', { diff --git a/yarn.lock b/yarn.lock index 847a44e758..1495394d3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2928,14 +2928,14 @@ normalize-url@^7.0.3: resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-7.0.3.tgz" integrity sha512-RiCOdwdPnzvwcBFJE4iI1ss3dMVRIrEzFpn8ftje6iBfzBInqlnRrNhxcLwBEKjPPXQKzm1Ptlxtaiv9wdcj5w== -notion-client@^6.9.1: - version "6.9.1" - resolved "https://registry.yarnpkg.com/notion-client/-/notion-client-6.9.1.tgz#8a1294fcd2609133aba681166c4363917fde0ce7" - integrity sha512-YRFe7B2uF4OoBHVpNZKEr6a/l03/9iJav3kE8/V1FBnSZkdx7Bi4qboQHwoviWWuMmpYKbCS7+nJtn4AvMCkJw== +notion-client@^6.9.2: + version "6.9.2" + resolved "https://registry.yarnpkg.com/notion-client/-/notion-client-6.9.2.tgz#789b3e5ba5be3a75dc7013212db9b9abe53fc3e6" + integrity sha512-VMuaXbd/du83r+4gKRdIgeePduWZMSYfISr8FM9gePdRFt2HoSsWQC1cxqX+V/S3N7xkUFSWbHJcJkWcDpSx+g== dependencies: got "^11.8.1" notion-types "^6.7.0" - notion-utils "^6.9.1" + notion-utils "^6.9.2" p-map "^5.3.0" notion-types@^6.7.0: @@ -2943,10 +2943,10 @@ notion-types@^6.7.0: resolved "https://registry.yarnpkg.com/notion-types/-/notion-types-6.7.0.tgz#f5ccb8ef701389b2bf52e5561bd31bc60c49ccdf" integrity sha512-j7O6juQDOPgAinELMMpvVn0c8Vgr+Dhqm7UTTnhILnBhbOtQKaIYPCNKA4AJw/OPzzy1iEJ6KrthTEkPbQYEeg== -notion-utils@^6.9.1: - version "6.9.1" - resolved "https://registry.yarnpkg.com/notion-utils/-/notion-utils-6.9.1.tgz#203fd0f94277ed3e55ffb8febbeacbf9714d347a" - integrity sha512-w5+ha+oGSZvFMgkHuNGtFl6b4ZrYu5wgqlDani3mKJMmdwgEd3koYKv8OkXYF8VS7+YAqX9y4Avqt7xR1z5dtQ== +notion-utils@^6.9.2: + version "6.9.2" + resolved "https://registry.yarnpkg.com/notion-utils/-/notion-utils-6.9.2.tgz#d295a10fcef28a1b75bd8e8dd4bb319554eb0719" + integrity sha512-bk2lbxARjZawqLjnmjH4uICHQAKFOTuu1j842ZC5XYq1DKZtatwZamTc4wwWQ9yQHyDAsY03cV9EQisUOnZLvQ== dependencies: is-url-superb "^6.1.0" mem "^9.0.2" @@ -3511,17 +3511,17 @@ react-modal@^3.14.3: react-lifecycles-compat "^3.0.0" warning "^4.0.3" -react-notion-x@^6.9.1: - version "6.9.1" - resolved "https://registry.yarnpkg.com/react-notion-x/-/react-notion-x-6.9.1.tgz#d209c262d83f66f374c4b507992b79789cf2c476" - integrity sha512-rTK7adUVo3FRtue1JOpBnG/ZOhNkv4NTqWi5Tf2/3Ptu5zqJed3Gu9Q/y6IfwMFoZmjIe4+yLIg/fO1TMSXPRg== +react-notion-x@^6.9.2: + version "6.9.2" + resolved "https://registry.yarnpkg.com/react-notion-x/-/react-notion-x-6.9.2.tgz#463a07d701cbbbf27d7b0cb245af861b546d5a07" + integrity sha512-2AqaGCYIw6wZa4KLg+HkPC00n99L+cJjcts6f51QuWTS0gsAd6m2Va3qHzpkkFIRBL+e82TK1fXAnvcI1/jvfA== dependencies: "@matejmazur/react-katex" "^3.1.3" "@radix-ui/react-dropdown-menu" "^0.1.6" katex "^0.13.18" medium-zoom "^1.0.6" notion-types "^6.7.0" - notion-utils "^6.9.1" + notion-utils "^6.9.2" prismjs "^1.27.0" react-fast-compare "^3.2.0" react-hotkeys-hook "^3.0.3"