7
7
import { RateLimiter } from "limiter" ;
8
8
import { Client } from "@notionhq/client" ;
9
9
import { logDebug } from "./log" ;
10
+ import { info } from "console" ;
10
11
11
12
const notionLimiter = new RateLimiter ( {
12
13
tokensPerInterval : 3 ,
@@ -33,17 +34,20 @@ export function initNotionClient(notionToken: string): Client {
33
34
export class NotionPage {
34
35
private metadata : GetPageResponse ;
35
36
public readonly pageId : string ;
37
+ public readonly order : number ;
36
38
public context : string ; // where we found it in the hierarchy of the outline
37
39
public foundDirectlyInOutline : boolean ; // the page was found as a descendent of /outline instead of being linked to
38
40
39
41
private constructor (
40
42
context : string ,
41
43
pageId : string ,
44
+ order : number ,
42
45
metadata : GetPageResponse ,
43
46
foundDirectlyInOutline : boolean
44
47
) {
45
48
this . context = context ;
46
49
this . pageId = pageId ;
50
+ this . order = order ;
47
51
this . metadata = metadata ;
48
52
this . foundDirectlyInOutline = foundDirectlyInOutline ;
49
53
@@ -55,11 +59,19 @@ export class NotionPage {
55
59
public static async fromPageId (
56
60
context : string ,
57
61
pageId : string ,
62
+ order : number ,
58
63
foundDirectlyInOutline : boolean
59
64
) : Promise < NotionPage > {
60
65
const metadata = await getPageMetadata ( pageId ) ;
61
- //logDebug(JSON.stringify(metadata));
62
- return new NotionPage ( context , pageId , metadata , foundDirectlyInOutline ) ;
66
+
67
+ //logDebug("notion metadata", JSON.stringify(metadata));
68
+ return new NotionPage (
69
+ context ,
70
+ pageId ,
71
+ order ,
72
+ metadata ,
73
+ foundDirectlyInOutline
74
+ ) ;
63
75
}
64
76
65
77
public matchesLinkId ( id : string ) : boolean {
@@ -162,7 +174,6 @@ export class NotionPage {
162
174
block_id : this . pageId ,
163
175
page_size : 100 , // max hundred links in a page
164
176
} ) ;
165
-
166
177
return children ;
167
178
}
168
179
@@ -257,19 +268,21 @@ export class NotionPage {
257
268
}
258
269
259
270
public async getContentInfo ( ) : Promise < {
260
- childPages : any [ ] ;
261
- linksPages : any [ ] ;
271
+ childPageIdsAndOrder : { id : string ; order : number } [ ] ;
272
+ linksPageIdsAndOrder : { id : string ; order : number } [ ] ;
262
273
hasParagraphs : boolean ;
263
274
} > {
264
275
const children = await this . getChildren ( ) ;
265
-
276
+ for ( let i = 0 ; i < children . results . length ; i ++ ) {
277
+ ( children . results [ i ] as any ) . order = i ;
278
+ }
266
279
return {
267
- childPages : children . results
280
+ childPageIdsAndOrder : children . results
268
281
. filter ( ( b : any ) => b . type === "child_page" )
269
- . map ( ( b : any ) => b . id ) ,
270
- linksPages : children . results
282
+ . map ( ( b : any ) => ( { id : b . id , order : b . order } ) ) ,
283
+ linksPageIdsAndOrder : children . results
271
284
. filter ( ( b : any ) => b . type === "link_to_page" )
272
- . map ( ( b : any ) => b . link_to_page . page_id ) ,
285
+ . map ( ( b : any ) => ( { id : b . link_to_page . page_id , order : b . order } ) ) ,
273
286
hasParagraphs : children . results . some (
274
287
b =>
275
288
( b as any ) . type === "paragraph" &&
0 commit comments