diff --git a/README.md b/README.md index 700999f..d61d060 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,125 @@ -[Eng](./README.md) | [中文版](./readMe_中文.md) -This plugin depends on: [Templater](https://github.com/SilentVoid13/Templater) and [NoteChain](https://github.com/zigholding/obsidian-notechain-plugin) -### Exporting Notes +### 导出笔记/Export Notes -Sync files or folders: -1. Right-click on the file or folder in the file list; -2. Click `Sync to other vault`; -3. Enter the target vault root directory; -4. Notes, folders, and attachments embedded in notes will be copied to the target vault following the same file structure. If a file with the same name exists in the target vault, it will be determined whether to overwrite based on the last modified time; +同步文件或文件夹: +To sync a file or folder: -Exporting plugins: -1. `Note Sync: export plugin` -2. Select the plugin to export; -3. Choose whether to export `data.json`; -4. Enter the plugin save directory; -5. Press Enter to confirm. +1. 在文件列表中,右键点击文件或文件夹; + Right-click the file or folder in the file list; + +2. 点击 `mirror to other vault`; + Click `mirror to other vault`; + +3. 输入目标库根目录; + Enter the root directory of the target vault; + +4. 笔记、文件夹以及笔记嵌入的附件,会按相同的文件结构复制到目标库。如果目录库中存在同名文件,则根据更新时间判定是否覆盖; + Notes, folders, and embedded attachments will be copied to the target vault with the same structure. If a file with the same name exists, it will be overwritten only if the source is newer. -### Exporting Notes as readMe +### 导出插件/Export Plugins -Execute `Note Sync:Set config to export note` to set export information: -- `Dir`: Export path -- `Name`: File name, default is readMe -- `Assets`: Attachment storage path -- `RemoveMeta`: Whether to remove metadata, default is true -- `UseGitLink`: Use Git format for attachment links, default is true +1. 执行命令 `Note Sync: export plugin`; + Run the command `Note Sync: export plugin`; + +2. 选择要导出的插件; + Select the plugin you want to export; + +3. 选择是否导出 `data.json`; + Choose whether to export `data.json`; + +4. 输入插件保存目录; + Enter the directory where the plugin will be saved; + +5. 输入回车键确认; + Press Enter to confirm. -> [!NOTE]+ Example of file export configuration + +### 将笔记导出为 readMe / Export a Note as `readMe` + +执行 `Note Sync:Set config to export note`,设置导出信息: +Run `Note Sync:Set config to export note` to configure the export settings: + +- `Dir`:导出路径 + `Dir`: Export directory +- `Name`:文件名称,默认为 readMe + `Name`: File name (default: readMe) +- `Assets`:附件存放路径 + `Assets`: Path to save attachments +- `RemoveMeta`:是否移除元数据,默认为 true + `RemoveMeta`: Whether to remove metadata (default: true) +- `UseGitLink`:附件链接使用 Git 格式,默认 true + `UseGitLink`: Use Git-style links for attachments (default: true) + +> [!NOTE]+ 文件导出配置示例 +> [!NOTE]+ Example Export Configuration +> > ```yaml > note-sync: > Dir: D:\github\ObsidianZ-dev\.obsidian\plugins\note-sync -> Name: readMe_en +> Name: readMe_中文 > Assets: ./assets > RemoveMeta: true > UseGitLink: true > ``` -Then execute `Note Sync:Export current note` to set the export note. +然后执行 `Note Sync:Export current note` 导出当前笔记。 +Then run `Note Sync:Export current note` to export the current note. -### Settings Page +--- -![Pasted image 20241215125538.png](./assets/Pasted%20image%2020241215125538.png) +### 下载示例库文件/Download Example Vault Files -> [!NOTE]+ Root dir of vault -> When exporting plugins, right-click to sync files and select the preset vault. Use line breaks to separate multiple vaults. +在 `设置` 页面配置 `Git 仓库`,需要包含分支名称: +Configure the `Git repository` in the **Settings** page. The URL must include the branch name: -> [!Danger]+ Strict mode -> When right-clicking to sync a folder, delete notes or attachments that are in the target folder but not in the source folder. This ensures that the synced folder and the current folder are the same. This setting will delete files, please operate with caution. +> [https://github.com/zigholding/ObsidianZ/tree/master](https://github.com/zigholding/ObsidianZ/tree/master) +> [https://gitee.com/zigholding/ObsidianZ/tree/master](https://gitee.com/zigholding/ObsidianZ/tree/master) -### Functions +执行 `下载 Git 仓库文件` 命令,依次选择仓库、文件夹和文件进行下载。输入 `all` 可下载所有文件(不包括子文件夹)。 +Run `Download git repo`, select the repository, then choose folders and files to download. Enter `all` to download all top-level files (excluding subfolders). -`NoteSync` provides three functions for synchronizing files and folders, which can be used in your own script notes. +![](././assets/下载笔记.gif) -`mode` specifies the handling method when a file already exists in the target vault: -- `pass`: Skip; -- `overwrite`: Overwrite; -- `mtime`: Take the latest modified time; +下载文件时,也可以预设路径,快速下载: +You can also preset the path for quick download when fetching files: +> [https://github.com/zigholding/ObsidianZ/tree/master/.obsidian/plugins](https://github.com/zigholding/ObsidianZ/tree/master/.obsidian/plugins) + + +### 设置页/Settings Page + +![](././assets/Pasted image 20241215125538.png) + +> [!NOTE]+ Root dir of vault +> 导出插件或同步文件时,选择预设的目标库。多个库请用换行符分隔。 +> Set predefined vaults for export/sync. Use newlines to separate multiple vaults. + +> [!Danger]+ Strict mode +> 启用严格模式,在目标文件夹中删除源文件夹中不存在的笔记或附件。请谨慎操作,此设置会**删除文件**。 +> Enabling strict mode will delete notes or attachments in the target folder that are not present in the source. **Use with caution**—this option will delete files. + + +### 函数/Functions + +`NoteSync` 提供了两个个函数用于同步文件和文件夹,可用于脚本笔记中。 +`NoteSync` provides two functions to sync files and folders, which can be used in your script notes. + +参数 `mode` 用于指定当目标库中已有文件时的处理方式: +The `mode` parameter determines how to handle existing files in the target vault: +- `pass`:跳过 + `pass`: Skip +- `overwrite`:覆盖 + `overwrite`: Overwrite +- `mtime`:根据更新时间覆盖 + `mtime`: Overwrite if the source is newer ```js let ns = app.plugins.plugins['note-sync'] -// 同步系统文件夹 +// 同步系统文件夹 +// Sync system folder ns.fsEditor.sync_folder( src:string, dst:string, @@ -70,7 +127,8 @@ ns.fsEditor.sync_folder( strict=false ) -// 同步笔记文件夹 +// 同步 Obsidian 笔记文件夹 +// Sync Obsidian TFolder ns.fsEditor.sync_tfolder( tfolder:TFolder, vault_root:string, @@ -79,4 +137,5 @@ ns.fsEditor.sync_tfolder( outlink=false, strict=false ) -``` \ No newline at end of file +``` + diff --git a/assets/下载笔记.gif b/assets/下载笔记.gif new file mode 100644 index 0000000..90985b3 Binary files /dev/null and b/assets/下载笔记.gif differ diff --git a/main.ts b/main.ts index 22ab0fd..b5146ee 100644 --- a/main.ts +++ b/main.ts @@ -116,18 +116,20 @@ export default class NoteSyncPlugin extends Plugin { } if(fm[this.yaml]?.RemoveMeta){ - ctx = ctx.replace( - /---[\n(\r\n)][\s\S]*?---[\n(\r\n)]/, - '' - ) - } - let assets = fm[this.yaml]?.Assets - - if(fm[this.yaml]?.UseGitLink && assets){ if(mcache?.frontmatterPosition?.end?.offset){ ctx = ctx.slice(mcache.frontmatterPosition.end.offset); } } + + let assets = fm[this.yaml]?.Assets + + if(fm[this.yaml]?.UseGitLink && assets){ + ctx = ctx.replace( + /\!\[\[(.*?)\]\]/g, + (match, filename) => { + return `![](./${assets}/${filename})`; + }) + } await this.fsEditor.fs.writeFile( target, ctx, 'utf-8', (err:Error) => {return;} diff --git a/readMe_中文.md b/readMe_中文.md deleted file mode 100644 index a5c014e..0000000 --- a/readMe_中文.md +++ /dev/null @@ -1,88 +0,0 @@ -v -[English](./README.md) | [中文版](./readMe_中文.md) - - -本插件依赖:[Templater](https://github.com/SilentVoid13/Templater) 和 [NoteChain](https://github.com/zigholding/obsidian-notechain-plugin) - -### 导出笔记 - -同步文件或文件夹: -1. 在文件列表中,右键点击文件或文件夹; -2. 点击 `mirror to other vault`; -3. 输入目标库根目录; -4. 笔记、文件夹以及笔记嵌入的附件,会按相同的文件结构复制到目标库。如果目录库中存在同名文件,则根据更新时间判定是否覆盖; - -导出插件 -1. `Note Sync: export plugin` -2. 选择要导出的插件; -4. 选择是否导出 `data.json`; -3. 输入插件保存目录; -5. 输入回车键确认 - -### 将笔记导出为 readMe - -执行 `Note Sync:Set config to export note`,设置导出信息: -- `Dir`:导出路径 -- `Name`:文件名称,默认为 readMe -- `Assets`:附件存放路径 -- `RemoveMeta`:是否移除元数据,默认为 true -- `UseGitLink`:附件链接使用 Git 格式,默认 true - -> [!NOTE]+ 文件导出配置示例 -> ```yaml -> note-sync: -> Dir: D:\github\ObsidianZ-dev\.obsidian\plugins\note-sync -> Name: readMe_中文 -> Assets: ./assets -> RemoveMeta: true -> UseGitLink: true -> ``` - -再执行 `Note Sync:Export current note`,设置导出笔记。 - -### 设置页 - -![Pasted image 20241215125538.png](./assets/Pasted%20image%2020241215125538.png) - -> [!NOTE]+ Root dir of vault -> 在导出插件,右键同步文件时,选择预设的库。多个库使用换行分割。 - -> [!Danger]+ Strict mode -> 右键同步文件夹时,删除在目标文件夹中,但不在源文件夹中的笔记或附件。保证同步的文件夹和当前文件夹是相同的。此设置会删除文件,请谨慎操作。 - -### 函数 - -`NoteSync` 提供了三个函数用于同步文件和文件夹,可以在自己的脚本笔记中使用。 - -`mode` 指当目标库中存在文件时的处理方法: -- `pass`:跳过; -- `overwrite`:覆盖; -- `mtime`:取最新更新时间; - -```js -let ns = app.plugins.plugins['note-sync'] - -// 同步系统文件夹 -ns.fsEditor.sync_folder( - src:string, - dst:string, - mode='mtime', - strict=false -) - -// 同步笔记文件夹 -ns.fsEditor.sync_tfolder( - tfolder:TFolder, - vault_root:string, - mode='mtime', - attachment=true, - outlink=false, - strict=false -) -``` - - - - - -