mirror of
https://github.com/zigholding/obsidian-notesync-plugin.git
synced 2026-07-22 05:43:30 +00:00
update
This commit is contained in:
parent
0f6e0325a3
commit
cc8f432ef1
7 changed files with 49 additions and 48 deletions
|
|
@ -1,4 +1,3 @@
|
|||
{
|
||||
"pluginDirExporter": "D:\\iLanix\\Obsidian\\.obsidian\\plugins\nD:\\iLanix\\Obsidian\\.mobile\\plugins\nD:\\DataSync\\BaiduSyncdisk\\ZigHoldingShare\\ObsidianBaiduDisk\\.obsidian\\plugins\nD:\\github\\ObsidianZ-final\\.obsidian\\plugins\nD:\\github\\ObsidianZY\\.obsidian\\plugins",
|
||||
"vaultDir": "\n"
|
||||
"vaultDir": ""
|
||||
}
|
||||
8
main.ts
8
main.ts
|
|
@ -3,13 +3,13 @@ import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Set
|
|||
|
||||
import { FsEditor } from 'src/fseditor';
|
||||
import { Strings } from 'src/strings';
|
||||
import {VExporterSettings,VExporterSettingTab,DEFAULT_SETTINGS} from 'src/setting'
|
||||
import {MySettings,MySettingTab,DEFAULT_SETTINGS} from 'src/setting'
|
||||
|
||||
import { addCommands } from 'src/commands';
|
||||
|
||||
export default class VaultExpoterPlugin extends Plugin {
|
||||
export default class NoteSyncPlugin extends Plugin {
|
||||
strings : Strings;
|
||||
settings: VExporterSettings;
|
||||
settings: MySettings;
|
||||
fsEditor : FsEditor;
|
||||
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ export default class VaultExpoterPlugin extends Plugin {
|
|||
await this.loadSettings();
|
||||
this.fsEditor = new FsEditor(this);
|
||||
// This adds a settings tab so the user can configure various aspects of the plugin
|
||||
this.addSettingTab(new VExporterSettingTab(this.app, this));
|
||||
this.addSettingTab(new MySettingTab(this.app, this));
|
||||
addCommands(this);
|
||||
|
||||
this.registerEvent(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"id": "vault-exporter",
|
||||
"name": "Vault Exporter",
|
||||
"id": "note-sync",
|
||||
"name": "Note Sync",
|
||||
"version": "0.5.0",
|
||||
"minAppVersion": "1.7.7",
|
||||
"description": "Export current note to another Vault.",
|
||||
"description": "Sync notes or plugins between vaults.",
|
||||
"author": "ZigHolding",
|
||||
"isDesktopOnly": true
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@ import {
|
|||
Notice, TFile
|
||||
} from 'obsidian';
|
||||
|
||||
import VaultExpoterPlugin from '../main';
|
||||
import NoteSyncPlugin from '../main';
|
||||
|
||||
const cmd_export_current_note = (plugin:VaultExpoterPlugin) => ({
|
||||
const cmd_export_current_note = (plugin:NoteSyncPlugin) => ({
|
||||
id: 'cmd_export_current_note',
|
||||
name: plugin.strings.cmd_export_current_note,
|
||||
callback: async () => {
|
||||
|
|
@ -14,7 +14,7 @@ const cmd_export_current_note = (plugin:VaultExpoterPlugin) => ({
|
|||
}
|
||||
});
|
||||
|
||||
const cmd_set_vexporter = (plugin:VaultExpoterPlugin) => ({
|
||||
const cmd_set_vexporter = (plugin:NoteSyncPlugin) => ({
|
||||
id: 'cmd_set_vexporter',
|
||||
name: plugin.strings.cmd_set_vexporter,
|
||||
callback: async () => {
|
||||
|
|
@ -37,7 +37,7 @@ const cmd_set_vexporter = (plugin:VaultExpoterPlugin) => ({
|
|||
}
|
||||
});
|
||||
|
||||
const cmd_export_plugin = (plugin:VaultExpoterPlugin) => ({
|
||||
const cmd_export_plugin = (plugin:NoteSyncPlugin) => ({
|
||||
id: 'cmd_export_plugin',
|
||||
name: plugin.strings.cmd_export_plugin,
|
||||
callback: async () => {
|
||||
|
|
@ -47,8 +47,13 @@ const cmd_export_plugin = (plugin:VaultExpoterPlugin) => ({
|
|||
let p = await nc.chain.tp_suggester(plugins,plugins);
|
||||
let eplugin = (plugin.app as any).plugins.getPlugin(p);
|
||||
if(eplugin){
|
||||
let paths = plugin.settings.vaultDir.split("\n").map(
|
||||
(x:string)=>{
|
||||
return plugin.fsEditor.path.join(x,'.obsidian','plugins')
|
||||
}
|
||||
)
|
||||
let target = await plugin.fsEditor.select_valid_dir(
|
||||
plugin.settings.pluginDirExporter.split("\n")
|
||||
paths
|
||||
)
|
||||
if(!plugin.fsEditor.fs.existsSync(target)){
|
||||
target = await nc.chain.tp_prompt(plugin.strings.prompt_path_of_folder);
|
||||
|
|
@ -62,7 +67,8 @@ const cmd_export_plugin = (plugin:VaultExpoterPlugin) => ({
|
|||
}
|
||||
let items = ['main.js','manifest.json','styles.css'];
|
||||
let dj = await plugin.fsEditor.notechain.chain.tp_suggester(
|
||||
['true','false'],[true,false],true,'Export data.json?'
|
||||
[plugin.strings.item_copy_data_json,plugin.strings.item_skip_data_json],
|
||||
[true,false],true,''
|
||||
)
|
||||
if(dj){
|
||||
items.push('data.json')
|
||||
|
|
@ -70,9 +76,11 @@ const cmd_export_plugin = (plugin:VaultExpoterPlugin) => ({
|
|||
for(let item of items){
|
||||
let src = `${plugin.fsEditor.root}/${eplugin.manifest.dir}/${item}`;
|
||||
let dst = `${target}/${item}`;
|
||||
plugin.fsEditor.copy_file(src,dst,'overwrite');
|
||||
let flag = plugin.fsEditor.copy_file(src,dst,'overwrite');
|
||||
if(flag){
|
||||
new Notice(`Copy ${item} to ${target}`,5000)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -87,7 +95,7 @@ const commandBuildersDesktop:Array<Function> = [
|
|||
cmd_export_plugin
|
||||
];
|
||||
|
||||
export function addCommands(plugin:VaultExpoterPlugin) {
|
||||
export function addCommands(plugin:NoteSyncPlugin) {
|
||||
commandBuilders.forEach((c) => {
|
||||
plugin.addCommand(c(plugin));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -72,8 +72,6 @@ export class FsEditor{
|
|||
let xpaths = paths.filter((p:string)=>this.isdir(p));
|
||||
if(xpaths.length===0){
|
||||
return null;
|
||||
}else if(xpaths.length==1){
|
||||
return xpaths[0];
|
||||
}else{
|
||||
let nc = (this.plugin.app as any).plugins.getPlugin('note-chain');
|
||||
if(nc){
|
||||
|
|
@ -84,7 +82,6 @@ export class FsEditor{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mkdir_recursive(path:string){
|
||||
if(this.isdir(path)){return true;}
|
||||
|
|
|
|||
|
|
@ -2,30 +2,28 @@ import {
|
|||
App, PluginSettingTab, Setting,Plugin
|
||||
} from 'obsidian';
|
||||
|
||||
import VaultExpoterPlugin from '../main';
|
||||
import NoteSyncPlugin from '../main';
|
||||
|
||||
export interface VExporterSettings {
|
||||
pluginDirExporter:string;
|
||||
export interface MySettings {
|
||||
vaultDir:string;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: VExporterSettings = {
|
||||
pluginDirExporter:'',
|
||||
export const DEFAULT_SETTINGS: MySettings = {
|
||||
vaultDir:''
|
||||
}
|
||||
|
||||
export class VExporterSettingTab extends PluginSettingTab {
|
||||
plugin: VaultExpoterPlugin;
|
||||
constructor(app: App, plugin: VaultExpoterPlugin) {
|
||||
export class MySettingTab extends PluginSettingTab {
|
||||
plugin: NoteSyncPlugin;
|
||||
constructor(app: App, plugin: NoteSyncPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
getSettingValue(field: keyof VExporterSettings) {
|
||||
getSettingValue(field: keyof MySettings) {
|
||||
return this.plugin.settings[field];
|
||||
}
|
||||
|
||||
add_toggle(name:string,desc:string,field:keyof VExporterSettings){
|
||||
add_toggle(name:string,desc:string,field:keyof MySettings){
|
||||
let {containerEl} = this;
|
||||
let value = (this.plugin.settings as any)[field] as boolean;
|
||||
let item = new Setting(containerEl)
|
||||
|
|
@ -46,15 +44,6 @@ export class VExporterSettingTab extends PluginSettingTab {
|
|||
|
||||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(this.plugin.strings.setting_plugin_dir)
|
||||
.addTextArea(text => text
|
||||
.setValue(this.plugin.settings.pluginDirExporter)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.pluginDirExporter = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(this.plugin.strings.setting_vault_dir)
|
||||
.addTextArea(text => text
|
||||
|
|
|
|||
|
|
@ -57,14 +57,6 @@ export class Strings{
|
|||
}
|
||||
}
|
||||
|
||||
get setting_plugin_dir(){
|
||||
if(this.language=='zh'){
|
||||
return '插件导出目录';
|
||||
}else{
|
||||
return 'Plugin dir to export';
|
||||
}
|
||||
}
|
||||
|
||||
get setting_vault_dir(){
|
||||
if(this.language=='zh'){
|
||||
return '库目录';
|
||||
|
|
@ -72,6 +64,22 @@ export class Strings{
|
|||
return 'Root dir of vault';
|
||||
}
|
||||
}
|
||||
|
||||
get item_copy_data_json(){
|
||||
if(this.language=='zh'){
|
||||
return '复制 data.json';
|
||||
}else{
|
||||
return 'Copy data.json';
|
||||
}
|
||||
}
|
||||
|
||||
get item_skip_data_json(){
|
||||
if(this.language=='zh'){
|
||||
return '跳过 data.json';
|
||||
}else{
|
||||
return 'Skip data.json';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export let strings = new Strings();
|
||||
Loading…
Reference in a new issue