Skip to content

Commit 1a019ca

Browse files
author
Sergei Orlov
committed
🐛 Compose page title from all chunks it includes
Date, user, and page mentions are added as plain text The title is trimmed CAVEAT: Mentioning a page that has a title mentioning a date will produce a title different from the same title of the mentioned page. E.g.: 'Page1 @yesterday' will be transformed into 'Page1 2021-05-15' as of today, but 'Post2 @post1' will produce 'Post2 Post1 @yesterday'. That's what Notion API returns right now
1 parent 9cdb197 commit 1a019ca

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

gatsby-node.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,37 @@ exports.sourceNodes = async (
2424
[],
2525
)
2626

27-
const title = properties.find((property) => property.type == "title").title[0].plain_text
27+
const title = properties
28+
.find((property) => property.type == "title")
29+
.title.reduce((acc, chunk) => {
30+
if (chunk.type == "text") {
31+
return acc.concat(chunk.plain_text)
32+
}
33+
34+
if (chunk.type == "mention") {
35+
if (chunk.mention.type == "user") {
36+
return acc.concat(chunk.mention.user.name)
37+
}
38+
39+
if (chunk.mention.type == "date") {
40+
if (chunk.mention.date.end) {
41+
return acc.concat(`${chunk.mention.date.start}${chunk.mention.date.start}`)
42+
}
43+
44+
return acc.concat(chunk.mention.date.start)
45+
}
46+
47+
if (chunk.mention.type == "page") {
48+
return acc.concat(chunk.plain_text)
49+
}
50+
}
51+
52+
return acc
53+
}, "")
2854

2955
createNode({
3056
id: createNodeId(`${NODE_TYPE}-${page.id}`),
31-
title,
57+
title: title.trim(),
3258
properties,
3359
archived: page.archived,
3460
createdAt: page.created_time,

0 commit comments

Comments
 (0)