Skip to content

Commit 89b3c8f

Browse files
feat: improve page metadata display
1 parent 1147254 commit 89b3c8f

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

components/NotionPage.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Tweet, TwitterContextProvider } from 'react-static-tweets'
1515
import { NotionRenderer } from 'react-notion-x'
1616

1717
// utils
18-
import { getBlockTitle, getPageProperty } from 'notion-utils'
18+
import { getBlockTitle, getPageProperty, formatDate } from 'notion-utils'
1919
import { mapPageUrl, getCanonicalPageUrl } from 'lib/map-page-url'
2020
import { mapImageUrl } from 'lib/map-image-url'
2121
import { getPageTweet } from 'lib/get-page-tweet'
@@ -68,6 +68,30 @@ const Modal = dynamic(
6868
}
6969
)
7070

71+
const propertyLastEditedTimeValue = (
72+
{ block, pageHeader },
73+
defaultFn: () => React.ReactNode
74+
) => {
75+
if (pageHeader && block?.last_edited_time) {
76+
return `Last updated ${formatDate(block?.last_edited_time, {
77+
month: 'long'
78+
})}`
79+
} else {
80+
return defaultFn()
81+
}
82+
}
83+
84+
const propertyTextValue = (
85+
{ schema, pageHeader },
86+
defaultFn: () => React.ReactNode
87+
) => {
88+
if (pageHeader && schema?.name?.toLowerCase() === 'author') {
89+
return <b>{defaultFn()}</b>
90+
} else {
91+
return defaultFn()
92+
}
93+
}
94+
7195
export const NotionPage: React.FC<types.PageProps> = ({
7296
site,
7397
recordMap,
@@ -87,7 +111,9 @@ export const NotionPage: React.FC<types.PageProps> = ({
87111
Pdf,
88112
Modal,
89113
Tweet,
90-
Header: NotionPageHeader
114+
Header: NotionPageHeader,
115+
propertyLastEditedTimeValue,
116+
propertyTextValue
91117
}),
92118
[]
93119
)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939
"next": "^12.1.1",
4040
"next-api-og-image": "^2.2.1",
4141
"node-fetch": "^2.6.1",
42-
"notion-client": "^6.8.3",
42+
"notion-client": "^6.9.1",
4343
"notion-types": "^6.7.0",
44-
"notion-utils": "^6.8.3",
44+
"notion-utils": "^6.9.1",
4545
"p-map": "^5.3.0",
4646
"p-memoize": "^6.0.1",
4747
"posthog-js": "^1.20.2",
4848
"react": "^17.0.2",
4949
"react-body-classname": "^1.3.1",
5050
"react-dom": "^17.0.2",
51-
"react-notion-x": "^6.8.4",
51+
"react-notion-x": "^6.9.1",
5252
"react-static-tweets": "^0.7.2",
5353
"react-use": "^17.3.2",
5454
"static-tweets": "^0.7.2"

pages/api/social-image.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,26 @@ export default withOGImage<'query', 'id'>({
7575
// getPageProperty<string>('Description', block, recordMap) ||
7676
// config.description
7777

78+
const timeUpdated = getPageProperty<number>(
79+
'Last Updated',
80+
block,
81+
recordMap
82+
)
7883
const timePublished = getPageProperty<number>(
7984
'Published',
8085
block,
8186
recordMap
8287
)
83-
const datePublished = timePublished ? new Date(timePublished) : undefined
88+
const dateUpdated = timeUpdated
89+
? new Date(timeUpdated)
90+
: timePublished
91+
? new Date(timePublished)
92+
: undefined
8493
const date =
85-
isBlogPost && datePublished
86-
? `${datePublished.toLocaleString('en-US', {
94+
isBlogPost && dateUpdated
95+
? `${dateUpdated.toLocaleString('en-US', {
8796
month: 'long'
88-
})} ${datePublished.getFullYear()}`
97+
})} ${dateUpdated.getFullYear()}`
8998
: undefined
9099
const detail = date || site.domain
91100

styles/notion.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@
163163
text-align: center;
164164
}
165165

166+
.notion-collection-row {
167+
padding-bottom: 1em;
168+
}
169+
166170
.notion-collection-page-properties .notion-collection-column-title {
167171
display: none;
168172
}
@@ -173,7 +177,10 @@
173177
}
174178

175179
.notion-collection-row-value {
180+
display: flex;
181+
align-items: center;
176182
padding: 0;
183+
min-height: 23px;
177184
}
178185

179186
.notion-page-cover-wrapper,

yarn.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,25 +2928,25 @@ normalize-url@^7.0.3:
29282928
resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-7.0.3.tgz"
29292929
integrity sha512-RiCOdwdPnzvwcBFJE4iI1ss3dMVRIrEzFpn8ftje6iBfzBInqlnRrNhxcLwBEKjPPXQKzm1Ptlxtaiv9wdcj5w==
29302930

2931-
notion-client@^6.8.3:
2932-
version "6.8.3"
2933-
resolved "https://registry.yarnpkg.com/notion-client/-/notion-client-6.8.3.tgz#855f999fdddd0c69940b96ecf4045557bfdcecc1"
2934-
integrity sha512-o6ZJxn3N/cGqwxV9+3BY4cEIFsyb6zBbI5/GT2Xtj6+ZL7hBCK7OuJhOOhz3WyhIepQDUCt4z/YNwvWTdiBDyA==
2931+
notion-client@^6.9.1:
2932+
version "6.9.1"
2933+
resolved "https://registry.yarnpkg.com/notion-client/-/notion-client-6.9.1.tgz#8a1294fcd2609133aba681166c4363917fde0ce7"
2934+
integrity sha512-YRFe7B2uF4OoBHVpNZKEr6a/l03/9iJav3kE8/V1FBnSZkdx7Bi4qboQHwoviWWuMmpYKbCS7+nJtn4AvMCkJw==
29352935
dependencies:
29362936
got "^11.8.1"
29372937
notion-types "^6.7.0"
2938-
notion-utils "^6.8.3"
2938+
notion-utils "^6.9.1"
29392939
p-map "^5.3.0"
29402940

29412941
notion-types@^6.7.0:
29422942
version "6.7.0"
29432943
resolved "https://registry.yarnpkg.com/notion-types/-/notion-types-6.7.0.tgz#f5ccb8ef701389b2bf52e5561bd31bc60c49ccdf"
29442944
integrity sha512-j7O6juQDOPgAinELMMpvVn0c8Vgr+Dhqm7UTTnhILnBhbOtQKaIYPCNKA4AJw/OPzzy1iEJ6KrthTEkPbQYEeg==
29452945

2946-
notion-utils@^6.8.3:
2947-
version "6.8.3"
2948-
resolved "https://registry.yarnpkg.com/notion-utils/-/notion-utils-6.8.3.tgz#efc5973722517efa3e8cc915978996d689d84663"
2949-
integrity sha512-Nwqw19txK8WTHT5BhJLJ9BCqRkz7b1LdbCR3LeQuIhfs2zOHd56gWENT6jh5mmKrQn3PlinVjWo2pl3HwGKd3A==
2946+
notion-utils@^6.9.1:
2947+
version "6.9.1"
2948+
resolved "https://registry.yarnpkg.com/notion-utils/-/notion-utils-6.9.1.tgz#203fd0f94277ed3e55ffb8febbeacbf9714d347a"
2949+
integrity sha512-w5+ha+oGSZvFMgkHuNGtFl6b4ZrYu5wgqlDani3mKJMmdwgEd3koYKv8OkXYF8VS7+YAqX9y4Avqt7xR1z5dtQ==
29502950
dependencies:
29512951
is-url-superb "^6.1.0"
29522952
mem "^9.0.2"
@@ -3511,17 +3511,17 @@ react-modal@^3.14.3:
35113511
react-lifecycles-compat "^3.0.0"
35123512
warning "^4.0.3"
35133513

3514-
react-notion-x@^6.8.4:
3515-
version "6.8.4"
3516-
resolved "https://registry.yarnpkg.com/react-notion-x/-/react-notion-x-6.8.4.tgz#5ef6ae3ac4ee5cd320fbcca7cd2e1f6aa47c1123"
3517-
integrity sha512-a3C2mApZrfUuoqjfM6xfSYL5dsHlgOp6smcfgFLHYDbdmg/XBih2/hBgw1CGhKcRa7L5EBVbwuOUkA0z2GDpLg==
3514+
react-notion-x@^6.9.1:
3515+
version "6.9.1"
3516+
resolved "https://registry.yarnpkg.com/react-notion-x/-/react-notion-x-6.9.1.tgz#d209c262d83f66f374c4b507992b79789cf2c476"
3517+
integrity sha512-rTK7adUVo3FRtue1JOpBnG/ZOhNkv4NTqWi5Tf2/3Ptu5zqJed3Gu9Q/y6IfwMFoZmjIe4+yLIg/fO1TMSXPRg==
35183518
dependencies:
35193519
"@matejmazur/react-katex" "^3.1.3"
35203520
"@radix-ui/react-dropdown-menu" "^0.1.6"
35213521
katex "^0.13.18"
35223522
medium-zoom "^1.0.6"
35233523
notion-types "^6.7.0"
3524-
notion-utils "^6.8.3"
3524+
notion-utils "^6.9.1"
35253525
prismjs "^1.27.0"
35263526
react-fast-compare "^3.2.0"
35273527
react-hotkeys-hook "^3.0.3"
@@ -4191,7 +4191,7 @@ swr@^1.0.0-beta.5:
41914191
resolved "https://registry.npmjs.org/swr/-/swr-1.2.2.tgz"
41924192
integrity sha512-ky0BskS/V47GpW8d6RU7CPsr6J8cr7mQD6+do5eky3bM0IyJaoi3vO8UhvrzJaObuTlGhPl2szodeB2dUd76Xw==
41934193

4194-
tar-fs@*, tar-fs@^2.0.0, tar-fs@^2.1.1:
4194+
tar-fs@^2.0.0, tar-fs@^2.1.1:
41954195
version "2.1.1"
41964196
resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784"
41974197
integrity sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==

0 commit comments

Comments
 (0)