notion-translator
Advanced tools
Comparing version 0.0.5 to 0.0.6
71
index.js
@@ -256,9 +256,25 @@ #!/usr/bin/env node | ||
b = { | ||
type: "paragraph", | ||
paragraph: { | ||
color: "default", | ||
rich_text: notice, | ||
type: "table", | ||
table: { | ||
table_width: b.table.table_width, | ||
has_column_header: b.table.has_column_header, | ||
has_row_header: b.table.has_row_header | ||
}, | ||
has_children: true, | ||
id: b.id, | ||
}; | ||
} | ||
if (b.type === 'table_row') { | ||
// translate each cell | ||
for (const row of b.table_row.cells) { | ||
await translateText(row, from, to); | ||
} | ||
b = { | ||
has_children: false, | ||
archived: false, | ||
type: 'table_row', | ||
table_row: { cells: b.table_row.cells } | ||
}; | ||
} | ||
if (b.type === "image") { | ||
@@ -353,23 +369,2 @@ if (b.image.type !== "external") { | ||
} | ||
if (translatedBlocks.length > 100) { | ||
// When you have 100+ children under a block, | ||
// {"object":"error","status":400,"code":"validation_error","message":"body failed validation: body.children.length should be ≤ `100`, instead was `133`."} can be returned. | ||
const reducedBlocks = translatedBlocks.slice(0, 99); | ||
const notice = [ | ||
{ | ||
plain_text: "(Sorry! notion-translator had to omit all the following blocks due to Notion public API's limitation)", | ||
text: { content: "" }, | ||
}, | ||
]; | ||
await translateText(notice, "en", to); | ||
b = { | ||
type: "paragraph", | ||
paragraph: { | ||
color: "default", | ||
rich_text: notice, | ||
}, | ||
}; | ||
reducedBlocks.push(b); | ||
return reducedBlocks; | ||
} | ||
return translatedBlocks; | ||
@@ -438,8 +433,22 @@ } | ||
} | ||
const blocksAddition = await notion.blocks.children.append( | ||
blocksAppendParams | ||
); | ||
if (debug) { | ||
console.log(`Block creation response: ${toPrettifiedJSON(blocksAddition)}`); | ||
} | ||
const pageSize = 10; | ||
let beginIndex = 0; | ||
let endIndex = 0; | ||
do { | ||
beginIndex = endIndex; | ||
endIndex = (beginIndex + pageSize) < translatedBlocks.length ? beginIndex + pageSize : translatedBlocks.length; | ||
const reducedBlocks = translatedBlocks.slice(beginIndex, endIndex); | ||
const blocksAppendParams = { | ||
block_id: newPage.id, | ||
children: reducedBlocks, | ||
}; | ||
const blocksAddition = await notion.blocks.children.append(blocksAppendParams); | ||
if (debug) { | ||
console.log(`Block creation response: ${toPrettifiedJSON(blocksAddition)}`); | ||
} | ||
} while(endIndex < translatedBlocks.length); | ||
console.log( | ||
@@ -446,0 +455,0 @@ "... Done!\n\nDisclaimer:\nSome parts might not be perfect.\nIf the generated page is missing something, please adjust the details on your own.\n" |
{ | ||
"name": "notion-translator", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "CLI tool to translate Notion pages into a different language by levergign DeepL's API", | ||
@@ -29,8 +29,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"@notionhq/client": "^1.0.4", | ||
"commander": "^9.4.1", | ||
"deepl-node": "^1.7.1", | ||
"@notionhq/client": "^2.2.4", | ||
"commander": "^10.0.1", | ||
"deepl-node": "^1.9.0", | ||
"dotenv": "^16.0.3", | ||
"open": "^8.4.0" | ||
"open": "^9.1.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21186
420
+ Added@notionhq/client@2.2.15(transitive)
+ Addedbig-integer@1.6.52(transitive)
+ Addedbplist-parser@0.2.0(transitive)
+ Addedbundle-name@3.0.0(transitive)
+ Addedcommander@10.0.1(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addeddefault-browser@4.0.0(transitive)
+ Addeddefault-browser-id@3.0.0(transitive)
+ Addeddefine-lazy-prop@3.0.0(transitive)
+ Addedexeca@5.1.17.2.0(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedhuman-signals@2.1.04.3.1(transitive)
+ Addedis-docker@3.0.0(transitive)
+ Addedis-inside-container@1.0.0(transitive)
+ Addedis-stream@2.0.13.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmimic-fn@2.1.04.0.0(transitive)
+ Addednpm-run-path@4.0.15.3.0(transitive)
+ Addedonetime@5.1.26.0.0(transitive)
+ Addedopen@9.1.0(transitive)
+ Addedpath-key@3.1.14.0.0(transitive)
+ Addedrun-applescript@5.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstrip-final-newline@2.0.03.0.0(transitive)
+ Addedtitleize@3.0.0(transitive)
+ Addeduntildify@4.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removed@notionhq/client@1.0.4(transitive)
- Removedcommander@9.5.0(transitive)
- Removeddefine-lazy-prop@2.0.0(transitive)
- Removedopen@8.4.2(transitive)
Updated@notionhq/client@^2.2.4
Updatedcommander@^10.0.1
Updateddeepl-node@^1.9.0
Updatedopen@^9.1.0