Skip to content

Commit cbdc2ed

Browse files
committed
lint
1 parent 2d5a3d5 commit cbdc2ed

File tree

4 files changed

+2557
-1300
lines changed

4 files changed

+2557
-1300
lines changed

.eslintrc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true
6+
},
7+
"extends": "standard",
8+
"overrides": [
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": "latest"
12+
},
13+
"rules": {
14+
"indent": ["error", 2]
15+
}
16+
}

index.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const fs = require("fs");
2-
const { globSync } = require("glob");
3-
const { markdownToBlocks } = require('@tryfabric/martian');
4-
const { Client } = require("@notionhq/client");
5-
const { nextTick } = require("process");
6-
const { root } = require("@tryfabric/martian/build/src/markdown");
1+
const fs = require('fs')
2+
const { globSync } = require('glob')
3+
const { markdownToBlocks } = require('@tryfabric/martian')
4+
const { Client } = require('@notionhq/client');
5+
// const { execSync } = require('child_process');
76

87
// TODO: add sleep interval for all requests
98
// TODO: fix tables width
@@ -18,33 +17,33 @@ const { root } = require("@tryfabric/martian/build/src/markdown");
1817

1918
const notionUrlMatch = process.env.NOTION_ROOT_ID.match(/[^-]*$/)
2019
if (notionUrlMatch == null) {
21-
throw new SyntaxError('Provided page was not in a valid format, url must end with "-<page-id>"');
20+
throw new SyntaxError('Provided page was not in a valid format, url must end with "-<page-id>"')
2221
}
2322
const notionPageId = notionUrlMatch[0]
2423

2524
const notion = new Client({
26-
auth: process.env.NOTION_TOKEN
25+
auth: process.env.NOTION_TOKEN
2726
})
2827

2928
notion.pages.retrieve({ page_id: notionPageId }).then((rootPage) => {
3029
// console.log("Root page-> ", rootPage)
3130

32-
var files = globSync(`${process.env.FOLDER}/**/*.md`, { ignore: 'node_modules/**' })
31+
const files = globSync(`${process.env.FOLDER}/**/*.md`, { ignore: 'node_modules/**' })
3332
// console.log("Files to sync ->", files)
3433

35-
notion.blocks.children.list({block_id: notionPageId}).then((blocksResponse) => {
34+
notion.blocks.children.list({ block_id: notionPageId }).then((blocksResponse) => {
3635
const blockIdsToRemove = blocksResponse.results.map((e) => e.id)
3736

3837
// sequencially delete all page blocks
39-
var doDelete = function(idToDelete) {
40-
if (!idToDelete) return;
38+
const doDelete = function (idToDelete) {
39+
if (!idToDelete) return
4140

4241
notion.blocks.delete({
4342
block_id: idToDelete
44-
}).then(function() {
45-
console.log("Block deleted:", idToDelete)
46-
if (idToDelete != blockIdsToRemove[blockIdsToRemove.length - 1]) {
47-
nextDeleteId = blockIdsToRemove[blockIdsToRemove.indexOf(idToDelete) + 1]
43+
}).then(function () {
44+
console.log('Block deleted:', idToDelete)
45+
if (idToDelete !== blockIdsToRemove[blockIdsToRemove.length - 1]) {
46+
const nextDeleteId = blockIdsToRemove[blockIdsToRemove.indexOf(idToDelete) + 1]
4847
doDelete(nextDeleteId)
4948
}
5049
})
@@ -53,49 +52,47 @@ notion.pages.retrieve({ page_id: notionPageId }).then((rootPage) => {
5352
doDelete(blockIdsToRemove[0])
5453
console.log('Block deletion complete')
5554

56-
var doCreate = (filePath) => {
55+
const doCreate = (filePath) => {
5756
const mdContent = fs.readFileSync(filePath, 'utf8')
5857
const newBlocks = markdownToBlocks(mdContent)
5958

60-
var title
59+
let title
6160

6261
try {
6362
title = newBlocks[0][newBlocks[0].type].rich_text[0].text.content
6463
} catch (error) {
65-
console.log("Cannot extract page title from", newBlocks[0])
64+
console.log('Cannot extract page title from', newBlocks[0])
6665
process.exit(1)
6766
}
6867

6968
notion.pages.create({
7069
parent: {
71-
type: "page_id",
70+
type: 'page_id',
7271
page_id: rootPage.id
7372
},
7473
properties: {
75-
"title": {
76-
"title": [{ "text": { "content": title} }], type: "title"
74+
title: {
75+
title: [{ text: { content: title } }], type: 'title'
7776
}
78-
},
77+
}
7978
}).then((pageResponse) => {
8079
console.log('Page created', pageResponse)
8180

8281
notion.blocks.children.append({ block_id: pageResponse.id, children: newBlocks }).then(() => {
8382
// process next page
84-
if (filePath != files[files.length - 1]) {
83+
if (filePath !== files[files.length - 1]) {
8584
doCreate(files[files.indexOf(filePath) + 1])
8685
}
8786
})
88-
8987
}).catch((error) => {
90-
console.log("Page creation failed", error)
88+
console.log('Page creation failed', error)
9189
process.exit(1)
9290
})
9391
}
9492

9593
doCreate(files[0])
9694
})
97-
9895
}).catch((error) => {
99-
console.log("Root page not found", error.body)
96+
console.log('Root page not found', error.body)
10097
process.exit(1)
101-
})
98+
})

0 commit comments

Comments
 (0)