complete the basic notionnext function

This commit is contained in:
Jiaxin Peng
2023-12-28 00:55:06 +00:00
parent fb463ceaae
commit cf08703fea
9 changed files with 127 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
import { App, Notice, TFile } from "obsidian";
import ObsidianSyncNotionPlugin from "../main";
import { PluginSettings } from "../ui/settingTabs";
import {DatabaseDetails, PluginSettings} from "../ui/settingTabs";
export async function updateYamlInfo(
yamlContent: string,
@@ -8,10 +8,14 @@ export async function updateYamlInfo(
res: any,
app: App,
plugin: ObsidianSyncNotionPlugin,
dbDetails: DatabaseDetails,
) {
let { url, id } = res.json
// replace www to notionID
const { notionUser } = plugin.settings;
const { abName } = dbDetails
const notionIDKey = `NotionID-${abName}`;
const linkKey = `link-${abName}`;
if (notionUser !== "") {
// replace url str "www" to notionID
@@ -19,15 +23,15 @@ export async function updateYamlInfo(
}
await app.fileManager.processFrontMatter(nowFile, yamlContent => {
if (yamlContent['notionID']) {
delete yamlContent['notionID']
if (yamlContent[notionIDKey]) {
delete yamlContent[notionIDKey]
}
if (yamlContent['link']) {
delete yamlContent['link']
if (yamlContent[linkKey]) {
delete yamlContent[linkKey]
}
// add new notionID and link
yamlContent.notionID = id;
yamlContent.link = url;
yamlContent[notionIDKey] = id;
yamlContent[linkKey] = url;
});
try {

View File

@@ -57,7 +57,7 @@ export async function uploadCommandGeneral(
app: App,
) {
const { notionAPI, databaseID } = settings;
const { notionAPI, databaseID } = dbDetails;
// Check if the user has set up the Notion API and database ID
if (notionAPI === "" || databaseID === "") {

View File

@@ -15,6 +15,7 @@ export class Upload2NotionNext extends UploadBaseNext {
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
super(plugin);
this.dbDetails = dbDetails
}
// 因为需要解析notion的block进行对比非常的麻烦
@@ -280,7 +281,7 @@ export class Upload2NotionNext extends UploadBaseNext {
);
}
if (res.status === 200) {
await updateYamlInfo(markdown, nowFile, res, app, this.plugin)
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails)
} else {
new Notice(`${res.text}`)
}