mirror of
https://github.com/zigholding/obsidian-notesync-plugin.git
synced 2026-07-22 05:43:30 +00:00
替换链接
This commit is contained in:
parent
d9a8befc3b
commit
452e1e4f8b
4 changed files with 87 additions and 5 deletions
43
README.md
43
README.md
|
|
@ -14,6 +14,45 @@ NextNote: "[[vexporter readMe]]"
|
|||
LocalGitProject: D:\iLanix\isync\Obsidian\.obsidian\plugins\obsidian-vaultexporter-plugin
|
||||
---
|
||||
|
||||
![[Pasted image 20240422213449.png]]
|
||||
下载 [obsidian-sample-plugin](https://github.com/obsidianmd/obsidian-sample-plugin),
|
||||
|
||||
```bash
|
||||
cd Your_Vault_DIR/.obsidian/plugins
|
||||
git clone https://github.com/obsidianmd/obsidian-sample-plugin.git
|
||||
```
|
||||
|
||||
修改 `manifest.json`:
|
||||
|
||||
```jsn
|
||||
{
|
||||
"id": "vault-exporter",
|
||||
"name": "Vault Exporter",
|
||||
"version": "1.0.0",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Export current note to another Vault.",
|
||||
"author": "ZigHolding",
|
||||
"isDesktopOnly": true
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
cd obsidian-sample-plugin
|
||||
npm i # 下载依赖包
|
||||
npm run dev # 将 main.ts 编译为 main.js
|
||||
```
|
||||
|
||||
开发完成后:将`main.js`、`styles.css`、`mainfest.json` 复制到 :`VaultFolder/.obsidian/plugins/your-plugin-id/`。
|
||||
|
||||
|
||||
需要先安装 [[obsidian-notechain-plugin]] 和 [[Templater]] 插件。
|
||||
|
||||
`Vault Exporter: Set Git Project`:将当前笔记绑定项目笔记。输入目录,生成 `LocalGitProject` 的元数据。
|
||||
|
||||

|
||||
|
||||
`Vault Exporter: Export readMe`:将当前笔记输出到 readme,笔记引用的图和文件复制到 `LocalGitProject/assets` 下。复制 readme 时,会更换链接。
|
||||
|
||||
元数据和附录可以在设置页面更改。
|
||||
|
||||

|
||||
|
||||
![[Pasted image 20240422214245.png]]
|
||||
BIN
assets/Pasted image 20240422220412.png
Normal file
BIN
assets/Pasted image 20240422220412.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
23
main.js
23
main.js
File diff suppressed because one or more lines are too long
26
main.ts
26
main.ts
|
|
@ -153,6 +153,7 @@ export default class VaultExpoterPlugin extends Plugin {
|
|||
}
|
||||
|
||||
this.copy_tfile(tfile,tmp);
|
||||
await this.replace_readme(tmp);
|
||||
|
||||
let adir = dst+'/'+assets;
|
||||
if(!fs.existsSync(adir)){
|
||||
|
|
@ -164,6 +165,29 @@ export default class VaultExpoterPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
replace_readme(path:string){
|
||||
fs.readFile(path, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
const replacedContent = data.replace(
|
||||
/\!\[\[(.*?)\]\]/g,
|
||||
(match, filename) => {
|
||||
return ``;
|
||||
});
|
||||
|
||||
// 异步写入新内容到文件
|
||||
fs.writeFile(path, replacedContent, 'utf8', (err) => {
|
||||
if (err) {
|
||||
console.error('Error writing file:', err);
|
||||
} else {
|
||||
console.log('File content updated successfully.');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class VExporterSettingTab extends PluginSettingTab {
|
||||
|
|
@ -199,7 +223,5 @@ class VExporterSettingTab extends PluginSettingTab {
|
|||
this.plugin.settings.assetsLocalGitProject = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue