Skip to content

Commit 17f4d62

Browse files
author
Sergei Orlov
committed
🐛 Only apply block transformations to frontmatter
✨ Add simplified date access
1 parent 2f3f4fa commit 17f4d62

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

gatsby-node.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,36 @@ exports.sourceNodes = async (
1515
reporter,
1616
)
1717

18+
/*
19+
if (page.properties[key].type == "rich_text") {
20+
page.properties[key].rich_text = blockToString(page.properties[key].rich_text)
21+
}
22+
*/
23+
1824
pages.forEach((page) => {
1925
const title = getNotionPageTitle(page)
2026
const properties = getNotionPageProperties(page)
2127
const frontmatter = Object.keys(properties).reduce(
22-
(acc, key) => ({
23-
...acc,
24-
[key]: properties[key].value,
25-
}),
28+
(acc, key) => {
29+
if (properties[key].type == "date") {
30+
return {
31+
...acc,
32+
[key]: properties[key].value.start,
33+
}
34+
}
35+
36+
if (properties[key].type == "rich_text") {
37+
return {
38+
...acc,
39+
[key]: blockToString(properties[key].value),
40+
}
41+
}
42+
43+
return {
44+
...acc,
45+
[key]: properties[key].value,
46+
}
47+
},
2648
{ title },
2749
)
2850
const markdown = "---\n"

src/transformers/get-page-properties.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
const { blockToString } = require("../block-to-string")
2-
31
exports.getNotionPageProperties = (page) =>
42
Object.keys(page.properties).reduce((acc, key) => {
53
if (page.properties[key].type == "title") {
64
return acc
75
}
86

9-
if (page.properties[key].type == "rich_text") {
10-
page.properties[key].rich_text = blockToString(page.properties[key].rich_text)
11-
}
12-
137
return {
148
...acc,
159
[key]: {

0 commit comments

Comments
 (0)