mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-30 00:48:36 +08:00
complete the basic customisation feature
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { FuzzySuggestModal, FuzzyMatch } from 'obsidian';
|
import { FuzzySuggestModal, FuzzyMatch } from 'obsidian';
|
||||||
import MyPlugin from "../main";
|
import MyPlugin from "../main";
|
||||||
import {i18nConfig} from "../lang/I18n";
|
import { i18nConfig } from "../lang/I18n";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple interface for what should be displayed and stored for suggester
|
* Simple interface for what should be displayed and stored for suggester
|
||||||
@@ -38,7 +38,7 @@ export class FuzzySuggester extends FuzzySuggestModal<DatabaseList>{
|
|||||||
return item.name
|
return item.name
|
||||||
}
|
}
|
||||||
|
|
||||||
onChooseItem(item: DatabaseList, evt:MouseEvent | KeyboardEvent): void { }
|
onChooseItem(item: DatabaseList, evt: MouseEvent | KeyboardEvent): void { }
|
||||||
|
|
||||||
onChooseSuggestion(item: FuzzyMatch<DatabaseList>, evt: MouseEvent | KeyboardEvent): void {
|
onChooseSuggestion(item: FuzzyMatch<DatabaseList>, evt: MouseEvent | KeyboardEvent): void {
|
||||||
this.callback(item.item, evt)
|
this.callback(item.item, evt)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {i18nConfig} from "src/lang/I18n";
|
import { i18nConfig } from "src/lang/I18n";
|
||||||
import {Editor, MarkdownView} from "obsidian";
|
import { Editor, MarkdownView } from "obsidian";
|
||||||
import {FuzzySuggester, DatabaseList} from "./FuzzySuggester";
|
import { FuzzySuggester, DatabaseList } from "./FuzzySuggester";
|
||||||
import {uploadCommandGeneral, uploadCommandNext} from "../upload/uploadCommand";
|
import { uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand";
|
||||||
import ObsidianSyncNotionPlugin from "src/main";
|
import ObsidianSyncNotionPlugin from "src/main";
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ export default class RibbonCommands {
|
|||||||
|
|
||||||
this.Ncommand.map(command => NcommandList.push(
|
this.Ncommand.map(command => NcommandList.push(
|
||||||
{
|
{
|
||||||
name:command.name,
|
name: command.name,
|
||||||
match: command.editorCallback
|
match: command.editorCallback
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -69,7 +69,7 @@ export default class RibbonCommands {
|
|||||||
const fusg = new FuzzySuggester(this.plugin);
|
const fusg = new FuzzySuggester(this.plugin);
|
||||||
|
|
||||||
fusg.setSuggesterData(NcommandList);
|
fusg.setSuggesterData(NcommandList);
|
||||||
await fusg.display(async (results) => {await results.match()})
|
await fusg.display(async (results) => { await results.match() })
|
||||||
};
|
};
|
||||||
|
|
||||||
// if the setting has been changed, try to rebuild the command list
|
// if the setting has been changed, try to rebuild the command list
|
||||||
|
|||||||
10
src/main.ts
10
src/main.ts
@@ -1,8 +1,8 @@
|
|||||||
import {App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting} from "obsidian";
|
import { App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting } from "obsidian";
|
||||||
import {addIcons} from 'src/ui/icon';
|
import { addIcons } from 'src/ui/icon';
|
||||||
import {Upload2NotionGeneral} from "src/upload/upload_general/Upload2NotionGeneral";
|
import { Upload2NotionGeneral } from "src/upload/upload_general/Upload2NotionGeneral";
|
||||||
import {Upload2NotionNext} from "src/upload/upload_next/Upload2NotionNext";
|
import { Upload2NotionNext } from "src/upload/upload_next/Upload2NotionNext";
|
||||||
import {i18nConfig} from "src/lang/I18n";
|
import { i18nConfig } from "src/lang/I18n";
|
||||||
import ribbonCommands from "src/commands/NotionCommands";
|
import ribbonCommands from "src/commands/NotionCommands";
|
||||||
import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS } from "src/ui/settingTabs";
|
import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS } from "src/ui/settingTabs";
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export interface PluginSettings {
|
|||||||
CustomButton: boolean;
|
CustomButton: boolean;
|
||||||
notionAPICustom: string;
|
notionAPICustom: string;
|
||||||
databaseIDCustom: string;
|
databaseIDCustom: string;
|
||||||
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: PluginSettings = {
|
export const DEFAULT_SETTINGS: PluginSettings = {
|
||||||
@@ -53,9 +54,9 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
// General Settings
|
// General Settings
|
||||||
containerEl.createEl('h2', { text: i18nConfig.GeneralSetting });
|
containerEl.createEl('h2', { text: i18nConfig.GeneralSetting });
|
||||||
|
|
||||||
this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl)
|
this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl, 'bannerUrl')
|
||||||
|
|
||||||
this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser)
|
this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser, 'notionUser')
|
||||||
|
|
||||||
containerEl.createEl('h2', { text: i18nConfig.NotionNextSettingHeader })
|
containerEl.createEl('h2', { text: i18nConfig.NotionNextSettingHeader })
|
||||||
|
|
||||||
@@ -80,10 +81,10 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
|
|
||||||
|
|
||||||
const notionAPINextEl = this.createStyleDiv('api-next', this.plugin.settings.NextButton)
|
const notionAPINextEl = this.createStyleDiv('api-next', this.plugin.settings.NextButton)
|
||||||
this.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext)
|
this.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext, 'notionAPINext')
|
||||||
|
|
||||||
const databaseIDNextEl = this.createStyleDiv('databaseID-next', this.plugin.settings.NextButton)
|
const databaseIDNextEl = this.createStyleDiv('databaseID-next', this.plugin.settings.NextButton)
|
||||||
this.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext)
|
this.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext, 'databaseIDNext')
|
||||||
|
|
||||||
|
|
||||||
// General Database Settings
|
// General Database Settings
|
||||||
@@ -129,7 +130,7 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const CustomNameEl = this.createStyleDiv('custom-name', this.plugin.settings.CustomTitleButton);
|
const CustomNameEl = this.createStyleDiv('custom-name', this.plugin.settings.CustomTitleButton);
|
||||||
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.plugin.settings.CustomTitleName)
|
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.plugin.settings.CustomTitleName, 'CustomTitleName')
|
||||||
|
|
||||||
// new Setting(containerEl)
|
// new Setting(containerEl)
|
||||||
// .setName("Convert tags(optional)")
|
// .setName("Convert tags(optional)")
|
||||||
@@ -144,11 +145,11 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
// );
|
// );
|
||||||
|
|
||||||
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton);
|
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton);
|
||||||
this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPIGeneral)
|
this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPIGeneral, 'notionAPIGeneral')
|
||||||
|
|
||||||
|
|
||||||
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton);
|
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton);
|
||||||
this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDGeneral)
|
this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDGeneral, 'databaseIDGeneral')
|
||||||
|
|
||||||
// Custom Database Settings
|
// Custom Database Settings
|
||||||
|
|
||||||
@@ -177,12 +178,12 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
private updateSettingEl(element: HTMLElement, commandValue: boolean) {
|
private updateSettingEl(element: HTMLElement, commandValue: boolean) {
|
||||||
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
|
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
|
||||||
element.style.paddingTop = commandValue ? "0.75em" : "0";
|
element.style.paddingTop = commandValue ? "0.75em" : "0";
|
||||||
element.style.display = commandValue? "block" : "none";
|
element.style.display = commandValue ? "block" : "none";
|
||||||
element.style.alignItems = "center";
|
element.style.alignItems = "center";
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to add one setting element in the setting tab.
|
// function to add one setting element in the setting tab.
|
||||||
private createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any) {
|
private createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any, settingsKey: string) {
|
||||||
if (type === 'password') {
|
if (type === 'password') {
|
||||||
return new Setting(containerEl)
|
return new Setting(containerEl)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
@@ -193,11 +194,10 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
.setPlaceholder(placeholder)
|
.setPlaceholder(placeholder)
|
||||||
.setValue(holderValue)
|
.setValue(holderValue)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
holderValue = value;
|
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
)
|
|
||||||
} else if (type === 'toggle') {
|
} else if (type === 'toggle') {
|
||||||
return new Setting(containerEl)
|
return new Setting(containerEl)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
@@ -206,13 +206,13 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
toggle
|
toggle
|
||||||
.setValue(holderValue)
|
.setValue(holderValue)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
holderValue = value;
|
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
await this.plugin.commands.updateCommand();
|
await this.plugin.commands.updateCommand();
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
} else if (type === 'text') {
|
} else if (type === 'text') {
|
||||||
new Setting(containerEl)
|
return new Setting(containerEl)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
.setDesc(desc)
|
.setDesc(desc)
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
@@ -220,11 +220,11 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
.setPlaceholder(placeholder)
|
.setPlaceholder(placeholder)
|
||||||
.setValue(holderValue)
|
.setValue(holderValue)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
holderValue = value;
|
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
await this.plugin.commands.updateCommand();
|
await this.plugin.commands.updateCommand();
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {App, Notice, TFile} from "obsidian";
|
import { App, Notice, TFile } from "obsidian";
|
||||||
import ObsidianSyncNotionPlugin from "../main";
|
import ObsidianSyncNotionPlugin from "../main";
|
||||||
import {PluginSettings} from "../ui/settingTabs";
|
import { PluginSettings } from "../ui/settingTabs";
|
||||||
|
|
||||||
export async function updateYamlInfo(
|
export async function updateYamlInfo(
|
||||||
yamlContent: string,
|
yamlContent: string,
|
||||||
@@ -9,7 +9,7 @@ export async function updateYamlInfo(
|
|||||||
app: App,
|
app: App,
|
||||||
plugin: ObsidianSyncNotionPlugin,
|
plugin: ObsidianSyncNotionPlugin,
|
||||||
) {
|
) {
|
||||||
let {url, id} = res.json
|
let { url, id } = res.json
|
||||||
// replace www to notionID
|
// replace www to notionID
|
||||||
const { notionUser } = plugin.settings;
|
const { notionUser } = plugin.settings;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import {i18nConfig} from "../lang/I18n";
|
import { i18nConfig } from "../lang/I18n";
|
||||||
import {App, Notice} from "obsidian";
|
import { App, Notice } from "obsidian";
|
||||||
import {Upload2NotionNext} from "./upload_next/Upload2NotionNext";
|
import { Upload2NotionNext } from "./upload_next/Upload2NotionNext";
|
||||||
import {Upload2NotionGeneral} from "./upload_general/Upload2NotionGeneral";
|
import { Upload2NotionGeneral } from "./upload_general/Upload2NotionGeneral";
|
||||||
import {PluginSettings} from "../ui/settingTabs";
|
import { PluginSettings } from "../ui/settingTabs";
|
||||||
import ObsidianSyncNotionPlugin from "../main";
|
import ObsidianSyncNotionPlugin from "../main";
|
||||||
import {getNowFileMarkdownContentNext} from "./upload_next/getMarkdownNext";
|
import { getNowFileMarkdownContentNext } from "./upload_next/getMarkdownNext";
|
||||||
import {getNowFileMarkdownContentGeneral} from "./upload_general/getMarkdownGeneral";
|
import { getNowFileMarkdownContentGeneral } from "./upload_general/getMarkdownGeneral";
|
||||||
|
|
||||||
export async function uploadCommandNext(
|
export async function uploadCommandNext(
|
||||||
plugin: ObsidianSyncNotionPlugin,
|
plugin: ObsidianSyncNotionPlugin,
|
||||||
@@ -13,7 +13,7 @@ export async function uploadCommandNext(
|
|||||||
app: App,
|
app: App,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const {notionAPINext, databaseIDNext} = settings;
|
const { notionAPINext, databaseIDNext } = settings;
|
||||||
|
|
||||||
// Check if NNon exists
|
// Check if NNon exists
|
||||||
// if (NNon === undefined) {
|
// if (NNon === undefined) {
|
||||||
@@ -29,10 +29,10 @@ export async function uploadCommandNext(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime} = await getNowFileMarkdownContentNext(app, settings)
|
const { markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime } = await getNowFileMarkdownContentNext(app, settings)
|
||||||
|
|
||||||
if (markDownData) {
|
if (markDownData) {
|
||||||
const {basename} = nowFile;
|
const { basename } = nowFile;
|
||||||
const upload = new Upload2NotionNext(plugin);
|
const upload = new Upload2NotionNext(plugin);
|
||||||
const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app);
|
const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app);
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ export async function uploadCommandGeneral(
|
|||||||
app: App,
|
app: App,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const{ notionAPIGeneral, databaseIDGeneral} = settings;
|
const { notionAPIGeneral, databaseIDGeneral } = settings;
|
||||||
|
|
||||||
// Check if the user has set up the Notion API and database ID
|
// Check if the user has set up the Notion API and database ID
|
||||||
if (notionAPIGeneral === "" || databaseIDGeneral === "") {
|
if (notionAPIGeneral === "" || databaseIDGeneral === "") {
|
||||||
@@ -62,10 +62,10 @@ export async function uploadCommandGeneral(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {markDownData, nowFile,cover, tags} = await getNowFileMarkdownContentGeneral(app, settings)
|
const { markDownData, nowFile, cover, tags } = await getNowFileMarkdownContentGeneral(app, settings)
|
||||||
|
|
||||||
if (markDownData) {
|
if (markDownData) {
|
||||||
const {basename} = nowFile;
|
const { basename } = nowFile;
|
||||||
|
|
||||||
const upload = new Upload2NotionGeneral(plugin);
|
const upload = new Upload2NotionGeneral(plugin);
|
||||||
const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app);
|
const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app);
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { markdownToBlocks, } from "@tryfabric/martian";
|
|||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
// import * as yaml from "yaml"
|
// import * as yaml from "yaml"
|
||||||
import MyPlugin from "src/main";
|
import MyPlugin from "src/main";
|
||||||
import {PluginSettings} from "../../ui/settingTabs";
|
import { PluginSettings } from "../../ui/settingTabs";
|
||||||
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
|
import { UploadBaseGeneral } from "./BaseUpload2NotionGeneral";
|
||||||
import {updateYamlInfo} from "../updateYaml";
|
import { updateYamlInfo } from "../updateYaml";
|
||||||
|
|
||||||
export class Upload2NotionGeneral extends UploadBaseGeneral {
|
export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||||
settings: PluginSettings;
|
settings: PluginSettings;
|
||||||
@@ -22,7 +22,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
title: string,
|
title: string,
|
||||||
cover: string,
|
cover: string,
|
||||||
tags: string[],
|
tags: string[],
|
||||||
childArr: any
|
childArr: any,
|
||||||
) {
|
) {
|
||||||
await this.deletePage(notionID)
|
await this.deletePage(notionID)
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
database_id: this.plugin.settings.databaseIDGeneral,
|
database_id: this.plugin.settings.databaseIDGeneral,
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
title: {
|
[this.plugin.settings.CustomTitleButton ? this.plugin.settings.CustomTitleName : 'title']: {
|
||||||
title: [
|
title: [
|
||||||
{
|
{
|
||||||
text: {
|
text: {
|
||||||
|
|||||||
Reference in New Issue
Block a user