在后台打日志

This commit is contained in:
ZigHolding 2025-06-23 22:02:23 +08:00
parent fbcbad87ad
commit d8fefd2af8
4 changed files with 33 additions and 12 deletions

View file

@ -1,4 +1,5 @@
{
"strict_mode": false,
"vaultDir": "D:\\iLanix\\Obsidian"
"vaultDir": "D:\\iLanix\\Obsidian\nD:\\github\\ObsidianZY",
"git_repo": "https://github.com/zigholding/ObsidianZ/tree/master\nhttps://gitee.com/zigholding/ObsidianZ/tree/master"
}

View file

@ -59,7 +59,7 @@ export default class NoteSyncPlugin extends Plugin {
this.fsEditor.sync_tfile(file,dst,'mtime',true,false);
}else if(file instanceof TFolder){
this.fsEditor.sync_tfolder(file,dst,'mtime',true,false);
this.fsEditor.sync_tfolder(file,dst,'mtime',true,false,this.settings.strict_mode);
}
});
});
@ -124,10 +124,11 @@ export default class NoteSyncPlugin extends Plugin {
let assets = fm[this.yaml]?.Assets
if(fm[this.yaml]?.UseGitLink && assets){
ctx = ctx.replace(
/\!\[\[(.*?)\]\]/g,
(match, filename) => {
return `![](./${assets}/${filename})`;
return `![](./${assets}/${filename.replace(/ /g,'%20')})`;
})
}
await this.fsEditor.fs.writeFile(

View file

@ -102,7 +102,7 @@ const cmd_export_plugin = (plugin:NoteSyncPlugin) => ({
let dst = `${target}/${item}`;
let flag = plugin.fsEditor.copy_file(src,dst,'overwrite');
if(flag){
new Notice(`Copy ${item} to ${target}`,5000)
console.log(`Copy ${item} to ${target}`,5000)
}
}
}

View file

@ -94,8 +94,11 @@ export class FsEditor{
}
abspath(tfile:TFile|TFolder){
if(tfile){
abspath(tfile:TFile|TFolder|string){
if(typeof tfile == 'string'){
return (this.root+'/'+tfile).replace(/\\/g,'/');
}
else if(tfile){
return (this.root+'/'+tfile.path).replace(/\\/g,'/');
}else{
return null;
@ -179,17 +182,20 @@ export class FsEditor{
if(mode==='overwrite'){
fs.unlinkSync(dst);
fs.copyFileSync(src,dst);
console.log('Overwrite: '+src+' to '+dst);
return true;
}else if(mode==='mtime'){
// dst 更新时间小于 src
if(fs.statSync(dst).mtimeMs<fs.statSync(src).mtimeMs){
fs.unlinkSync(dst);
fs.copyFileSync(src,dst);
console.log('Update: '+src+' to '+dst);
return true;
}
}
}else{
fs.copyFileSync(src,dst);
console.log('Copy: '+src+' to '+dst);
return true;
}
return false;
@ -243,15 +249,28 @@ export class FsEditor{
}
}
delete_file_or_dir(path:string){
async delete_file_or_dir(path:string){
if(this.isfile(path)){
this.fs.unlinkSync(path)
if (await this.plugin.dialog_suggest(['❌','✔️'],[false,true],path)){
console.log(`Delete file: ${path}`)
this.fs.unlinkSync(path)
}
}else if(this.isdir(path)){
let items = this.list_dir(path,true)
for(let item of items){
this.delete_file_or_dir(item)
if (await this.plugin.dialog_suggest(['❌','✔️'],[false,true],path)){
console.log(`Delete folder: ${path}`)
this.fs.rmdirSync(path)
}else{
return;
}
this.fs.rmdirSync(path)
for(let item of items){
if (await this.plugin.dialog_suggest(['❌','✔️'],[false,true],item)){
console.log(`Delete file: ${path}`)
this.delete_file_or_dir(item)
}
}
}
}
@ -264,7 +283,7 @@ export class FsEditor{
let asrc = src+'/'+item
if(this.isfile(adst)){
if(!this.isfile(asrc)){
this.fs.unlinkSync(adst)
this.delete_file_or_dir(adst);
}
}else if(this.isdir(adst)){
if(!this.isdir(asrc)){