Socket
Socket
Sign inDemoInstall

notion-translator

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notion-translator - npm Package Compare versions

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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc