Skip to content

Commit 0be8b1b

Browse files
committed
feat: add pages' flattened properties in the frontmatter
1 parent 0a954af commit 0be8b1b

File tree

3 files changed

+68
-28
lines changed

3 files changed

+68
-28
lines changed

source/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ export class Notion {
190190
title,
191191
createdTime: page.created_time,
192192
lastEditedTime: page.last_edited_time,
193+
...Object.fromEntries(
194+
Object.entries(page.properties)
195+
// omit the already transformed title
196+
.filter(([key]) => !['title', 'Name'].includes(key))
197+
.map(([key, property]) => [key, getPropertyContent(property)]),
198+
),
193199
},
194200
{ forceQuotes: true },
195201
).trim(),

spec/client.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,36 @@ describe('cl:Notion', () => {
4242

4343
describe('fn:getPage', () => {
4444
const BLOCKS_PER_PAGE = 2;
45-
mockPage('page', BLOCKS_PER_PAGE);
45+
mockPage('page', BLOCKS_PER_PAGE, {
46+
title: {
47+
id: 'title',
48+
type: 'title',
49+
title: [
50+
{
51+
annotations: {
52+
bold: false,
53+
code: false,
54+
color: 'default',
55+
italic: false,
56+
strikethrough: false,
57+
underline: false,
58+
},
59+
href: null,
60+
plain_text: 'Title',
61+
text: {
62+
content: 'Title',
63+
link: null,
64+
},
65+
type: 'text',
66+
},
67+
],
68+
},
69+
extra: {
70+
id: 'extra',
71+
type: 'number',
72+
number: 0,
73+
},
74+
});
4675

4776
it('return a page in detail', async () => {
4877
const page = await client.getPage('page');
@@ -57,6 +86,7 @@ id: 'page'
5786
title: 'Title'
5887
createdTime: '2020-01-01T00:00:00Z'
5988
lastEditedTime: '2020-01-01T00:00:00Z'
89+
extra: 0
6090
---
6191
block 0 for block page
6292

spec/mock.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import nock from 'nock';
1717
import { URL } from 'url';
1818

19-
import type { Block, Database, List, Page } from '#types';
19+
import type { Block, Database, List, Page, PropertyValueMap } from '#types';
2020

2121
export function mockBlockList(
2222
blockID: string,
@@ -193,7 +193,35 @@ export function mockDatabasePageList(
193193
.persist();
194194
}
195195

196-
export function mockPage(pageID: string, blocks: number = 1) {
196+
export function mockPage(
197+
pageID: string,
198+
blocks: number = 1,
199+
properties: PropertyValueMap = {
200+
title: {
201+
id: 'title',
202+
type: 'title',
203+
title: [
204+
{
205+
annotations: {
206+
bold: false,
207+
code: false,
208+
color: 'default',
209+
italic: false,
210+
strikethrough: false,
211+
underline: false,
212+
},
213+
href: null,
214+
plain_text: 'Title',
215+
text: {
216+
content: 'Title',
217+
link: null,
218+
},
219+
type: 'text',
220+
},
221+
],
222+
},
223+
},
224+
) {
197225
mockBlockList(pageID, blocks);
198226

199227
const body: Page = {
@@ -207,31 +235,7 @@ export function mockPage(pageID: string, blocks: number = 1) {
207235
},
208236
archived: false,
209237
url: `https://www.notion.so/${pageID}`,
210-
properties: {
211-
title: {
212-
id: 'title',
213-
title: [
214-
{
215-
annotations: {
216-
bold: false,
217-
code: false,
218-
color: 'default',
219-
italic: false,
220-
strikethrough: false,
221-
underline: false,
222-
},
223-
href: null,
224-
plain_text: 'Title',
225-
text: {
226-
content: 'Title',
227-
link: null,
228-
},
229-
type: 'text',
230-
},
231-
],
232-
type: 'title',
233-
},
234-
},
238+
properties,
235239
};
236240

237241
nock('https://api.notion.com')

0 commit comments

Comments
 (0)