1
1
import { lstatSync , readdirSync , readFileSync } from 'node:fs'
2
2
import { markdownToBlocks } from '@tryfabric/martian'
3
3
import { addBlocks , createPage } from './notion_api.js'
4
- import { addNoteInfo } from './db.js'
4
+ import { addImportStatus } from './db.js'
5
5
6
6
7
7
await importNotes ( )
@@ -25,25 +25,26 @@ async function importNotes() {
25
25
continue
26
26
}
27
27
28
- const page = await createPage ( { title : relFilePath } )
29
-
30
- console . log ( `\n${ relFilePath } ` )
31
- console . log ( '-' . repeat ( 30 ) + '\n' )
32
- //console.log(data);
33
-
34
- const noteInfo = { noteId : page . id , title : relFilePath , filePath : relFilePath }
35
-
36
- const blocks = markdownToBlocks ( data )
37
- try {
38
- await addBlocks ( { parentId : page . id , blocks } )
39
- noteInfo . imported = true
40
- } catch ( e ) {
41
- noteInfo . imported = false
42
- noteInfo . error = JSON . stringify ( e )
43
- console . error ( 'ERROR' )
44
- }
45
-
46
- await addNoteInfo ( noteInfo )
28
+ const noteInfo = { title : relFilePath , filePath : relFilePath , data }
29
+ await saveNoteToNotion ( noteInfo )
30
+ await addImportStatus ( noteInfo )
47
31
}
48
32
}
49
33
34
+ async function saveNoteToNotion ( noteInfo ) {
35
+ const page = await createPage ( { title : noteInfo . title } )
36
+ noteInfo . noteId = page . id
37
+
38
+ console . log ( `\n${ noteInfo . filePath } ` )
39
+ console . log ( '-' . repeat ( 30 ) + '\n' )
40
+
41
+ const blocks = markdownToBlocks ( noteInfo . data )
42
+ try {
43
+ await addBlocks ( { parentId : page . id , blocks } )
44
+ noteInfo . imported = true
45
+ } catch ( e ) {
46
+ noteInfo . imported = false
47
+ noteInfo . error = JSON . stringify ( e )
48
+ console . error ( 'ERROR' )
49
+ }
50
+ }
0 commit comments