77import { RateLimiter } from "limiter" ;
88import { Client } from "@notionhq/client" ;
99import { logDebug } from "./log" ;
10+ import { info } from "console" ;
1011
1112const notionLimiter = new RateLimiter ( {
1213 tokensPerInterval : 3 ,
@@ -33,17 +34,20 @@ export function initNotionClient(notionToken: string): Client {
3334export class NotionPage {
3435 private metadata : GetPageResponse ;
3536 public readonly pageId : string ;
37+ public readonly order : number ;
3638 public context : string ; // where we found it in the hierarchy of the outline
3739 public foundDirectlyInOutline : boolean ; // the page was found as a descendent of /outline instead of being linked to
3840
3941 private constructor (
4042 context : string ,
4143 pageId : string ,
44+ order : number ,
4245 metadata : GetPageResponse ,
4346 foundDirectlyInOutline : boolean
4447 ) {
4548 this . context = context ;
4649 this . pageId = pageId ;
50+ this . order = order ;
4751 this . metadata = metadata ;
4852 this . foundDirectlyInOutline = foundDirectlyInOutline ;
4953
@@ -55,11 +59,19 @@ export class NotionPage {
5559 public static async fromPageId (
5660 context : string ,
5761 pageId : string ,
62+ order : number ,
5863 foundDirectlyInOutline : boolean
5964 ) : Promise < NotionPage > {
6065 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+ ) ;
6375 }
6476
6577 public matchesLinkId ( id : string ) : boolean {
@@ -162,7 +174,6 @@ export class NotionPage {
162174 block_id : this . pageId ,
163175 page_size : 100 , // max hundred links in a page
164176 } ) ;
165-
166177 return children ;
167178 }
168179
@@ -257,19 +268,21 @@ export class NotionPage {
257268 }
258269
259270 public async getContentInfo ( ) : Promise < {
260- childPages : any [ ] ;
261- linksPages : any [ ] ;
271+ childPageIdsAndOrder : { id : string ; order : number } [ ] ;
272+ linksPageIdsAndOrder : { id : string ; order : number } [ ] ;
262273 hasParagraphs : boolean ;
263274 } > {
264275 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+ }
266279 return {
267- childPages : children . results
280+ childPageIdsAndOrder : children . results
268281 . 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
271284 . 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 } ) ) ,
273286 hasParagraphs : children . results . some (
274287 b =>
275288 ( b as any ) . type === "paragraph" &&
0 commit comments