mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a950e2e301 | ||
|
|
aac7bc154a | ||
|
|
a573ef728d | ||
|
|
1344c14933 | ||
|
|
c1f4ecd14b | ||
|
|
5942876c92 | ||
|
|
3218eb9fba | ||
|
|
48566eca20 | ||
|
|
8bd8346423 | ||
|
|
00411e9599 | ||
|
|
296125f6b4 | ||
|
|
1b385ccd0a | ||
|
|
a90e4871bb | ||
|
|
885ccba027 | ||
|
|
f282dde1b7 | ||
|
|
bc166d8db1 | ||
|
|
7612637951 | ||
|
|
e8b1617916 | ||
|
|
fd29ed820e |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -20,4 +20,7 @@ data.json
|
||||
|
||||
# Exclude macOS Finder (System Explorer) View States
|
||||
.DS_Store
|
||||
.history
|
||||
.history
|
||||
|
||||
# local data
|
||||
local-data
|
||||
|
||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,8 +1,15 @@
|
||||
## Features
|
||||
## Fix
|
||||
|
||||
- Support WebP format images. 支持 WebP 格式图片。
|
||||
- Support sync with long notes. 支持长文章同步。
|
||||
- Fix the bug that the plugin does not work in the mobile app.
|
||||
- 修复了在移动端应用中插件无法工作的问题。
|
||||
|
||||
## Feature
|
||||
|
||||
- Both desktop and mobile apps support syncing long markdown files.
|
||||
- 桌面端和移动端应用都支持长篇 markdown 文件同步。
|
||||
|
||||
## Issue
|
||||
- Bullet list over 3 levels is not supported.
|
||||
- 无法同步超过三个分支的列表。
|
||||
|
||||
Long articles or notes have been split into multiple parts, and the parts are synchronized in order.
|
||||
长文章同步是通过将长文章或笔记拆分为多个部分,按顺序同步这些部分。
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ const ctx = await esbuild.context({
|
||||
"@codemirror/view",
|
||||
...builtins,
|
||||
],
|
||||
platform: "node",
|
||||
format: "cjs",
|
||||
target: "es2016",
|
||||
logLevel: "info",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "share-to-notionnext",
|
||||
"name": "Share to NotionNext",
|
||||
"version": "2.4.0",
|
||||
"version": "2.5.0",
|
||||
"minAppVersion": "0.0.1",
|
||||
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
||||
"author": "EasyChris, jxpeng98",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "share-to-notionnext",
|
||||
"version": "2.4.0",
|
||||
"version": "2.5.0",
|
||||
"type": "module",
|
||||
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
||||
"description": "Share files to any Notion database using the Notion API, originally created by EasyChris/obsidian-to-notion.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
@@ -26,8 +26,6 @@
|
||||
"dependencies": {
|
||||
"@jxpeng98/martian": "^1.2.7",
|
||||
"https-proxy-agent": "^7.0.2",
|
||||
"node-fetch": "^3.3.2",
|
||||
"process": "^0.11.10",
|
||||
"remark-math": "^6.0.0",
|
||||
"yaml": "^2.3.4",
|
||||
"yaml-front-matter": "^4.1.1"
|
||||
|
||||
@@ -8,10 +8,42 @@ export const I18n: {[key: string]:any} = {
|
||||
ja,
|
||||
};
|
||||
|
||||
export const I18nConfig = (lang: string): any => {
|
||||
return I18n[lang];
|
||||
};
|
||||
class I18nManager {
|
||||
private currentLanguage: string;
|
||||
|
||||
const storedLanguage = window.localStorage.getItem("language");
|
||||
constructor() {
|
||||
this.currentLanguage = this.detectLanguage();
|
||||
}
|
||||
|
||||
export const i18nConfig = I18n[storedLanguage || window.navigator.language.split('-')[0] || "en"];
|
||||
// return the language to use
|
||||
private detectLanguage(): string {
|
||||
const storedLanguage = window.localStorage.getItem("language");
|
||||
if (storedLanguage && this.isLanguageSupported(storedLanguage)) {
|
||||
console.log(`Using stored language: ${storedLanguage}`);
|
||||
return storedLanguage;
|
||||
}
|
||||
|
||||
const browserLanguage = window.navigator.language.split("-")[0];
|
||||
if (this.isLanguageSupported(browserLanguage)) {
|
||||
console.log(`Using browser language: ${browserLanguage}`);
|
||||
return browserLanguage;
|
||||
}
|
||||
|
||||
// Default to English if no match is found
|
||||
console.log("Using default language: en");
|
||||
return "en";
|
||||
}
|
||||
|
||||
private isLanguageSupported(lang: string): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(I18n, lang);
|
||||
}
|
||||
|
||||
// Get the i18n configuration for the current language
|
||||
public getConfig(): any {
|
||||
return I18n[this.currentLanguage];
|
||||
}
|
||||
}
|
||||
|
||||
export const i18nManager = new I18nManager();
|
||||
|
||||
export const i18nConfig = i18nManager.getConfig();
|
||||
|
||||
@@ -79,4 +79,5 @@ export const en = {
|
||||
BlockUploaded: "All blocks uploaded",
|
||||
ExtraBlockUploaded: "Extra blocks uploaded",
|
||||
CheckConsole: "Check the console for more information \n opt+cmd+i/ctrl+shift+i",
|
||||
"reach-mobile-limit": "The number of blocks exceeds the limit of 100, please use the desktop plugin",
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
||||
|
||||
addIcons();
|
||||
// This creates an icon in the left ribbon.
|
||||
const ribbonIconEl = this.addRibbonIcon(
|
||||
this.addRibbonIcon(
|
||||
"notion-logo",
|
||||
i18nConfig.ribbonIcon,
|
||||
async (evt: MouseEvent) => {
|
||||
|
||||
@@ -50,8 +50,10 @@ export async function uploadCommandNext(
|
||||
const {response} = res;
|
||||
if (response.status === 200) {
|
||||
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||
console.log(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`);
|
||||
} else {
|
||||
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
||||
console.log(`${i18nConfig["sync-fail"]} ${basename}`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,6 +78,9 @@ export async function uploadCommandGeneral(
|
||||
|
||||
const {markDownData, nowFile, cover, tags} = await getNowFileMarkdownContentGeneral(app, settings)
|
||||
|
||||
new Notice(`Start upload ${nowFile.basename}`);
|
||||
console.log(`Start upload ${nowFile.basename}`);
|
||||
|
||||
if (markDownData) {
|
||||
const {basename} = nowFile;
|
||||
|
||||
@@ -85,8 +90,10 @@ export async function uploadCommandGeneral(
|
||||
const {response} = res;
|
||||
if (response.status === 200) {
|
||||
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||
console.log(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`);
|
||||
} else {
|
||||
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
||||
console.log(`${i18nConfig["sync-fail"]} ${basename}`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,6 +118,9 @@ export async function uploadCommandCustom(
|
||||
|
||||
const {markDownData, nowFile, cover, customValues} = await getNowFileMarkdownContentCustom(app, dbDetails)
|
||||
|
||||
new Notice(`Start upload ${nowFile.basename}`);
|
||||
console.log(`Start upload ${nowFile.basename}`);
|
||||
|
||||
if (markDownData) {
|
||||
const {basename} = nowFile;
|
||||
|
||||
@@ -118,10 +128,13 @@ export async function uploadCommandCustom(
|
||||
const res = await upload.syncMarkdownToNotionCustom(cover, customValues, markDownData, nowFile, this.app);
|
||||
|
||||
const {response} = res;
|
||||
|
||||
if (response.status === 200) {
|
||||
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||
console.log(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`);
|
||||
} else {
|
||||
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
||||
console.log(`${i18nConfig["sync-fail"]} ${basename}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import {App, Notice, TFile} from "obsidian";
|
||||
import {Client} from "@notionhq/client";
|
||||
import {App, Notice, TFile, requestUrl} from "obsidian";
|
||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||
import * as yamlFrontMatter from "yaml-front-matter";
|
||||
// import * as yaml from "yaml"
|
||||
import MyPlugin from "src/main";
|
||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
|
||||
import {updateYamlInfo} from "../updateYaml";
|
||||
import fetch from 'node-fetch';
|
||||
import {i18nConfig} from "../../lang/I18n";
|
||||
|
||||
interface CreatePageResponse {
|
||||
response: any;
|
||||
data: any;
|
||||
}
|
||||
|
||||
export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
settings: PluginSettings;
|
||||
dbDetails: DatabaseDetails;
|
||||
@@ -48,7 +50,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
cover: string,
|
||||
tags: string[],
|
||||
childArr: any,
|
||||
) {
|
||||
): Promise<CreatePageResponse> {
|
||||
|
||||
const {
|
||||
databaseID,
|
||||
@@ -58,6 +60,19 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
notionAPI
|
||||
} = this.dbDetails;
|
||||
|
||||
// remove the annotations from the childArr if type is code block
|
||||
childArr.forEach((block: any) => {
|
||||
if (block.type === "code") {
|
||||
block.code.rich_text.forEach((item: any) => {
|
||||
if (item.type === "text" && item.annotations) {
|
||||
delete item.annotations;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// check the length of the childArr and split it into chunks of 100
|
||||
const childArrLength = childArr.length;
|
||||
let extraArr: any[] = [];
|
||||
@@ -127,25 +142,36 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
|
||||
console.log(bodyString)
|
||||
|
||||
const response = await fetch("https://api.notion.com/v1/pages", {
|
||||
let response: any;
|
||||
let data: any;
|
||||
|
||||
response = await requestUrl({
|
||||
url: `https://api.notion.com/v1/pages`,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + notionAPI,
|
||||
// 'User-Agent': 'obsidian.md',
|
||||
Authorization:
|
||||
"Bearer " + notionAPI,
|
||||
"Notion-Version": "2022-06-28",
|
||||
},
|
||||
body: JSON.stringify(bodyString),
|
||||
throw: false
|
||||
});
|
||||
|
||||
const data: any = await response.json();
|
||||
data = await response.json;
|
||||
|
||||
if (!response.ok) {
|
||||
// console.log(data)
|
||||
// console.log(response.status)
|
||||
|
||||
if (response.status !== 200) {
|
||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||
console.log(`Error message: \n ${data.message}`);
|
||||
} else {
|
||||
console.log(`Page created: ${data.url}`);
|
||||
console.log(`Page ID: ${data.id}`);
|
||||
}
|
||||
|
||||
//
|
||||
// upload the rest of the blocks
|
||||
if (pushCount > 0) {
|
||||
for (let i = 0; i < pushCount; i++) {
|
||||
@@ -155,7 +181,8 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
|
||||
console.log(extraBlocks)
|
||||
|
||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
||||
const extraResponse = await requestUrl({
|
||||
url: `https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -165,9 +192,9 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
body: JSON.stringify(extraBlocks),
|
||||
});
|
||||
|
||||
const extraData: any = await extraResponse.json();
|
||||
const extraData: any = await extraResponse.json;
|
||||
|
||||
if (!extraResponse.ok) {
|
||||
if (extraResponse.status !== 200) {
|
||||
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||
console.log(`Error message: \n ${extraData.message}`);
|
||||
} else {
|
||||
@@ -181,8 +208,8 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
}
|
||||
|
||||
return {
|
||||
response, // for status code
|
||||
data // for id and url
|
||||
response,
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,11 +230,11 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
const yamlContent: any = yamlFrontMatter.loadFront(markdown);
|
||||
const __content = yamlContent.__content;
|
||||
const file2Block = markdownToBlocks(__content, options);
|
||||
const frontmasster =
|
||||
const frontMatter =
|
||||
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
||||
const {abName} = this.dbDetails
|
||||
const notionIDKey = `NotionID-${abName}`;
|
||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||
const notionID = frontMatter ? frontMatter[notionIDKey] : null;
|
||||
|
||||
|
||||
if (notionID) {
|
||||
@@ -227,7 +254,14 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
// console.log(response)
|
||||
|
||||
if (response && response.status === 200) {
|
||||
await updateYamlInfo(markdown, nowFile, data, app, this.plugin, this.dbDetails);
|
||||
await updateYamlInfo(
|
||||
markdown,
|
||||
nowFile,
|
||||
data,
|
||||
app,
|
||||
this.plugin,
|
||||
this.dbDetails,
|
||||
);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
||||
import {App, Notice, TFile} from "obsidian";
|
||||
import {Client} from "@notionhq/client";
|
||||
import {App, Notice, TFile, requestUrl} from "obsidian";
|
||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||
import * as yamlFrontMatter from "yaml-front-matter";
|
||||
// import * as yaml from "yaml"
|
||||
import MyPlugin from "src/main";
|
||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||
import {updateYamlInfo} from "../updateYaml";
|
||||
import {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
||||
import fetch from "node-fetch";
|
||||
import {i18nConfig} from "../../lang/I18n";
|
||||
|
||||
interface CreatePageResponse {
|
||||
response: any;
|
||||
data: any;
|
||||
}
|
||||
|
||||
export class Upload2NotionNext extends UploadBaseNext {
|
||||
settings: PluginSettings;
|
||||
dbDetails: DatabaseDetails;
|
||||
@@ -79,9 +81,22 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
favicon: string,
|
||||
datetime: string,
|
||||
childArr: any,
|
||||
) {
|
||||
): Promise<CreatePageResponse> {
|
||||
const {databaseID, notionAPI} = this.dbDetails;
|
||||
|
||||
// remove the annotations from the childArr if type is code block
|
||||
childArr.forEach((block: any) => {
|
||||
if (block.type === "code") {
|
||||
block.code.rich_text.forEach((item: any) => {
|
||||
if (item.type === "text" && item.annotations) {
|
||||
delete item.annotations;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// check the length of the childArr
|
||||
// if it is too long, split it into multiple pages
|
||||
const childArrLength = childArr.length;
|
||||
@@ -228,55 +243,60 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
|
||||
console.log(bodyString);
|
||||
|
||||
const response = await fetch("https://api.notion.com/v1/pages", {
|
||||
let response: any;
|
||||
let data: any;
|
||||
|
||||
response = await requestUrl({
|
||||
url: `https://api.notion.com/v1/pages`,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + notionAPI,
|
||||
// 'User-Agent': 'obsidian.md',
|
||||
Authorization:
|
||||
"Bearer " + notionAPI,
|
||||
"Notion-Version": "2022-06-28",
|
||||
},
|
||||
body: JSON.stringify(bodyString),
|
||||
throw: false
|
||||
});
|
||||
|
||||
const data: any = await response.json();
|
||||
data = await response.json;
|
||||
|
||||
// can use response.ok or response.status === 200
|
||||
if (!response.ok) {
|
||||
// console.log(data)
|
||||
// console.log(response.status)
|
||||
|
||||
if (response.status !== 200) {
|
||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||
console.log(`Error message: \n ${data.message}`);
|
||||
} else {
|
||||
console.log(`Page created: ${data.url}`);
|
||||
console.log(`Page ID: ${data.id}`);
|
||||
}
|
||||
|
||||
// if the childArr is over 100, patch the rest of the blocks append to the page
|
||||
//
|
||||
// upload the rest of the blocks
|
||||
if (pushCount > 0) {
|
||||
for (let i = 0; i < pushCount; i++) {
|
||||
const extraBlocks = {
|
||||
children: extraArr[i]
|
||||
}
|
||||
children: extraArr[i],
|
||||
};
|
||||
|
||||
console.log(extraBlocks)
|
||||
|
||||
const extraResponse = await fetch(
|
||||
`https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + notionAPI,
|
||||
"Notion-Version": "2022-06-28",
|
||||
},
|
||||
body: JSON.stringify(extraBlocks),
|
||||
});
|
||||
const extraResponse = await requestUrl({
|
||||
url: `https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + notionAPI,
|
||||
"Notion-Version": "2022-06-28",
|
||||
},
|
||||
body: JSON.stringify(extraBlocks),
|
||||
});
|
||||
|
||||
const extraData: any = await extraResponse.json();
|
||||
const extraData: any = await extraResponse.json;
|
||||
|
||||
if (!extraResponse.ok) {
|
||||
new Notice(
|
||||
`Extra Block: Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`,
|
||||
5000,
|
||||
);
|
||||
if (extraResponse.status !== 200) {
|
||||
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||
console.log(`Error message: \n ${extraData.message}`);
|
||||
} else {
|
||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
||||
@@ -289,8 +309,8 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
}
|
||||
|
||||
return {
|
||||
response, // for status code
|
||||
data, // for id and url
|
||||
response,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
@@ -382,6 +402,8 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
|
||||
let {response, data} = res;
|
||||
|
||||
// console.log(response)
|
||||
|
||||
if (response && response.status === 200) {
|
||||
await updateYamlInfo(
|
||||
markdown,
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import {App, Notice, TFile} from "obsidian";
|
||||
import {App, Notice, TFile, requestUrl} from "obsidian";
|
||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||
import * as yamlFrontMatter from "yaml-front-matter";
|
||||
// import * as yaml from "yaml"
|
||||
import MyPlugin from "src/main";
|
||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||
import {updateYamlInfo} from "../updateYaml";
|
||||
import {UploadBaseCustom} from "./BaseUpload2NotionCustom";
|
||||
import fetch from 'node-fetch';
|
||||
import {i18nConfig} from "../../lang/I18n";
|
||||
|
||||
|
||||
interface CreatePageResponse {
|
||||
response: any;
|
||||
data: any;
|
||||
}
|
||||
|
||||
export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
settings: PluginSettings;
|
||||
dbDetails: DatabaseDetails;
|
||||
@@ -46,7 +49,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
cover: string,
|
||||
customValues: Record<string, string>,
|
||||
childArr: any,
|
||||
) {
|
||||
): Promise<CreatePageResponse> {
|
||||
|
||||
const {
|
||||
databaseID,
|
||||
@@ -54,6 +57,19 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
notionAPI
|
||||
} = this.dbDetails;
|
||||
|
||||
// remove the annotations from the childArr if type is code block
|
||||
childArr.forEach((block: any) => {
|
||||
if (block.type === "code") {
|
||||
block.code.rich_text.forEach((item: any) => {
|
||||
if (item.type === "text" && item.annotations) {
|
||||
delete item.annotations;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// check the length of the childArr and split it into chunks of 100
|
||||
const childArrLength = childArr.length;
|
||||
let extraArr: any[] = [];
|
||||
@@ -98,26 +114,36 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
|
||||
console.log(bodyString)
|
||||
|
||||
const response = await fetch("https://api.notion.com/v1/pages", {
|
||||
let response: any;
|
||||
let data: any;
|
||||
|
||||
response = await requestUrl({
|
||||
url: `https://api.notion.com/v1/pages`,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + notionAPI,
|
||||
// 'User-Agent': 'obsidian.md',
|
||||
Authorization:
|
||||
"Bearer " + notionAPI,
|
||||
"Notion-Version": "2022-06-28",
|
||||
},
|
||||
body: JSON.stringify(bodyString),
|
||||
throw: false
|
||||
});
|
||||
|
||||
const data: any = await response.json();
|
||||
data = await response.json;
|
||||
|
||||
if (!response.ok) {
|
||||
// console.log(data)
|
||||
// console.log(response.status)
|
||||
|
||||
if (response.status !== 200) {
|
||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||
console.log(`Error message: \n ${data.message}`);
|
||||
} else {
|
||||
console.log(`Page created: ${data.url}`);
|
||||
console.log(`Page ID: ${data.id}`);
|
||||
}
|
||||
|
||||
//
|
||||
// upload the rest of the blocks
|
||||
if (pushCount > 0) {
|
||||
for (let i = 0; i < pushCount; i++) {
|
||||
@@ -127,7 +153,8 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
|
||||
console.log(extraBlocks)
|
||||
|
||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
||||
const extraResponse = await requestUrl({
|
||||
url: `https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -137,9 +164,9 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
body: JSON.stringify(extraBlocks),
|
||||
});
|
||||
|
||||
const extraData: any = await extraResponse.json();
|
||||
const extraData: any = await extraResponse.json;
|
||||
|
||||
if (!extraResponse.ok) {
|
||||
if (extraResponse.status !== 200) {
|
||||
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||
console.log(`Error message: \n ${extraData.message}`);
|
||||
} else {
|
||||
@@ -197,7 +224,14 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
// console.log(response)
|
||||
|
||||
if (response && response.status === 200) {
|
||||
await updateYamlInfo(markdown, nowFile, data, app, this.plugin, this.dbDetails);
|
||||
await updateYamlInfo(
|
||||
markdown,
|
||||
nowFile,
|
||||
data,
|
||||
app,
|
||||
this.plugin,
|
||||
this.dbDetails,
|
||||
);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -35,7 +35,10 @@ export async function getNowFileMarkdownContentCustom(
|
||||
|
||||
// If a 'title' type property exists, use the file's basename as its value
|
||||
if (titleProperty) {
|
||||
customValues[titleProperty.customName] = nowFile.basename; // Use 'basename' for the file name without extension
|
||||
customValues[titleProperty.customName] =
|
||||
(FileCache.frontmatter && FileCache.frontmatter[titleProperty.customName]) ?
|
||||
FileCache.frontmatter[titleProperty.customName] : // use the front matter value if it exists
|
||||
nowFile.basename; // Use 'basename' for the file name without extension
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
14
yarn.lock
14
yarn.lock
@@ -460,6 +460,13 @@ commander@^8.3.0:
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
|
||||
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
|
||||
|
||||
cross-fetch@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-4.0.0.tgz#f037aef1580bb3a1a35164ea2a848ba81b445983"
|
||||
integrity sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==
|
||||
dependencies:
|
||||
node-fetch "^2.6.12"
|
||||
|
||||
data-uri-to-buffer@^4.0.0:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e"
|
||||
@@ -1199,7 +1206,7 @@ node-domexception@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
|
||||
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
|
||||
|
||||
node-fetch@^2.6.1:
|
||||
node-fetch@^2.6.1, node-fetch@^2.6.12:
|
||||
version "2.7.0"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
|
||||
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
|
||||
@@ -1245,11 +1252,6 @@ picomatch@^2.3.1:
|
||||
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
|
||||
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
|
||||
|
||||
process@^0.11.10:
|
||||
version "0.11.10"
|
||||
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
|
||||
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==
|
||||
|
||||
queue-microtask@^1.2.2:
|
||||
version "1.2.3"
|
||||
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
|
||||
|
||||
Reference in New Issue
Block a user