Skip to content

Commit 3902bbe

Browse files
committed
Minor edits
1 parent 2a2ea85 commit 3902bbe

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const pool = new pg.Pool({
88

99
//await addNoteInfo({ title: 'test', filePath: 'testpath', imported: true })
1010

11-
export async function addNoteInfo({ noteId, title, filePath, imported, error }) {
11+
export async function addImportStatus({ noteId, title, filePath, imported, error }) {
1212
const text = 'INSERT INTO imported_notes(note_id, title, file_path, imported, error) VALUES($1, $2, $3, $4, $5)'
1313
const values = [noteId, title, filePath, imported, error]
1414
const res = await pool.query(text, values)

src/index.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { lstatSync, readdirSync, readFileSync } from 'node:fs'
22
import { markdownToBlocks } from '@tryfabric/martian'
33
import { addBlocks, createPage } from './notion_api.js'
4-
import { addNoteInfo } from './db.js'
4+
import { addImportStatus } from './db.js'
55

66

77
await importNotes()
@@ -25,25 +25,26 @@ async function importNotes() {
2525
continue
2626
}
2727

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)
4731
}
4832
}
4933

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

Comments
 (0)