1772530674

This commit is contained in:
Docker7530
2026-03-03 17:37:57 +08:00
parent 546b32c344
commit a0d7c1ba97
18 changed files with 725 additions and 355 deletions
@@ -1,21 +1,9 @@
module.exports = async (params) => {
const { app } = params;
// 获取当前仓库路径
const vaultPath = app.vault.adapter.basePath;
// 构建 Windows Terminal 命令
const command = `wt -d "${vaultPath}"`;
// 使用 Node.js child_process 执行命令
const { exec } = require('child_process');
exec(command, (error, stdout, stderr) => {
if (error) {
console.error('执行失败:', error);
new Notice('无法打开终端');
return;
}
console.log('终端已打开');
});
module.exports = async function openTerminal(params) {
const { app } = params;
const vaultPath = app.vault.adapter.basePath;
const command = `wt -d "${vaultPath}"`;
const { exec } = require("node:child_process");
exec(command, (error) => {
if (error) console.error("执行失败:", error);
});
};
@@ -1,77 +0,0 @@
module.exports = async (params) => {
const { app, obsidian, quickAddApi } = params;
// 获取当前选中的文件或让用户选择图片文件
const activeFile = app.workspace.getActiveFile();
if (
!activeFile ||
!activeFile.extension.match(/(png|jpg|jpeg|gif|webp|svg)/i)
) {
new obsidian.Notice("请先选择一个图片文件");
return;
}
// 生成UUID
const uuid = crypto.randomUUID();
const newFileName = `${uuid}.${activeFile.extension}`;
const newPath = activeFile.path.replace(activeFile.name, newFileName);
// 获取所有引用该文件的笔记
const backlinks = app.metadataCache.getBacklinksForFile(activeFile);
console.log("引用文件的列表:");
for (const [file, links] of backlinks.data) {
console.log(`- ${file}: ${links.length} 个引用`);
for (const link of links) {
console.log(` ${link.link}`);
}
}
// 确认操作
const confirm = await quickAddApi.yesNoPrompt(
"确认重命名",
`${activeFile.name} 重命名为 ${newFileName}\n` +
`将更新 ${backlinks.data.size} 个文件中的引用`,
);
if (!confirm) return;
try {
// 重命名文件
await app.fileManager.renameFile(activeFile, newPath);
// 更新所有引用
let updatedCount = 0;
for (const [file, links] of backlinks.data) {
const fileObj = app.vault.getAbstractFileByPath(file);
if (fileObj instanceof obsidian.TFile) {
let content = await app.vault.read(fileObj);
// 更新所有链接引用
for (const link of links) {
const oldLink = `[[${activeFile.path}]]`;
const newLink = `[[${newPath}]]`;
const oldEmbed = `![[${activeFile.path}]]`;
const newEmbed = `![[${newPath}]]`;
content = content.replace(
new RegExp(oldLink.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
newLink,
);
content = content.replace(
new RegExp(oldEmbed.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
newEmbed,
);
}
await app.vault.modify(fileObj, content);
updatedCount++;
}
}
new obsidian.Notice(`成功重命名并更新了 ${updatedCount} 个文件`);
} catch (error) {
console.error("重命名失败:", error);
new obsidian.Notice("重命名失败: " + error.message);
}
};