添加中文

This commit is contained in:
zigholding 2024-12-15 13:01:31 +08:00
parent cc8f432ef1
commit 5dc27073d1
6 changed files with 124 additions and 17 deletions

View file

@ -1,13 +1,28 @@
需要先安装 [[obsidian-notechain-plugin]] 和 [[Templater]] 插件。
Install [[NoteChain]] and [[Templater]] first.
`Vault Exporter: Set Git Project`:将当前笔记绑定项目笔记。输入目录,生成 `LocalGitProject` 的元数据。
![Pasted image 20240422220412.png](./assets/Pasted image 20240422220412.png)
Right click file for folder in files-explorer
Click `mirror to other vault`
Input the root of other vault and then press `enter`
NoteSync will mirror file or folder and this attachments, with same structure
You can set default paths of target vaults in setting pages
`Vault Exporter: Export readMe`:将当前笔记输出到 readme笔记引用的图和文件复制到 `LocalGitProject/assets` 下。复制 readme 时,会更换链接。
## 导出插件
Sun command `Note Sync: export plugin`
Select plugin name
Select whether to export data.json
Select vault
## 导出笔记
执行 `Set config to export note` 设置要导出的路径,笔记名称,附件路径,是否移除元数据以及是否将附件双链替换为 Github 格式。然后执行 `Export current note` 即可导出当前笔记。如果不先设置元数据,也可以输入导出路径后导出,但只能导出当前笔记,不支持附件输出。
![Pasted image 20240508213503.png](./assets/Pasted%20image%2020240508213503.png)
元数据和附录可以在设置页面更改。
![Pasted image 20240422213449.png](./assets/Pasted image 20240422213449.png)

21
main.ts
View file

@ -11,6 +11,7 @@ export default class NoteSyncPlugin extends Plugin {
strings : Strings;
settings: MySettings;
fsEditor : FsEditor;
yaml: string;
async onload() {
@ -26,6 +27,7 @@ export default class NoteSyncPlugin extends Plugin {
}
async _onload_() {
this.yaml = 'note-sync'
this.strings = new Strings();
await this.loadSettings();
@ -38,7 +40,7 @@ export default class NoteSyncPlugin extends Plugin {
this.app.workspace.on("file-menu", (menu, file) => {
menu.addItem((item) => {
item
.setTitle("Mirror to other vault")
.setTitle(this.strings.item_sync_vault)
.setIcon("document")
.onClick(async () => {
let dst = await this.fsEditor.select_valid_dir(
@ -90,7 +92,7 @@ export default class NoteSyncPlugin extends Plugin {
// 设置输出目录
if(!dst){
dst = nc.editor.get_frontmatter(tfile,'vexporter')?.Dir;
dst = nc.editor.get_frontmatter(tfile,this.yaml)?.Dir;
if(!dst){
dst = await nc.chain.tp_prompt('Path of LocalGitProject');
}
@ -104,7 +106,7 @@ export default class NoteSyncPlugin extends Plugin {
// 导出当前笔记
let tmp;
let name = nc.editor.get_frontmatter(tfile,'vexporter')?.Name;
let name = nc.editor.get_frontmatter(tfile,this.yaml)?.Name;
if(name && !(name==='')){
tmp = dst+'/'+name+'.md';
}else{
@ -112,16 +114,16 @@ export default class NoteSyncPlugin extends Plugin {
}
if(this.fsEditor.copy_tfile(tfile,tmp)){
if(nc.editor.get_frontmatter(tfile,'vexporter')?.RemoveMeta){
if(nc.editor.get_frontmatter(tfile,this.yaml)?.RemoveMeta){
const ufunc = (path:string,data:string)=>{
let res = data;
if(nc.editor.get_frontmatter(tfile,'vexporter')?.RemoveMeta){
if(nc.editor.get_frontmatter(tfile,this.yaml)?.RemoveMeta){
res = res.replace(
/---[\n(\r\n)][\s\S]*?---[\n(\r\n)]/,
''
)
}
if(nc.editor.get_frontmatter(tfile,'vexporter')?.UseGitLink && assets){
if(nc.editor.get_frontmatter(tfile,this.yaml)?.UseGitLink && assets){
res = res.replace(
/\!\[\[(.*?)\]\]/g,
(match:any, name:string) => {
@ -135,14 +137,17 @@ export default class NoteSyncPlugin extends Plugin {
}
}
// 导出附件
let assets = nc.editor.get_frontmatter(tfile,'vexporter')?.Assets;
let assets = nc.editor.get_frontmatter(tfile,this.yaml)?.Assets;
if(assets){
let olinks = nc.chain.get_outlinks(tfile);
let adir = dst+'/'+assets;
this.fsEditor.mkdir_recursive(adir);
for(let f of olinks){
if(!(f.extension==='md')){
this.fsEditor.copy_tfile(f,adir+'/'+f.basename+'.'+f.extension);
let flag = this.fsEditor.copy_tfile(f,adir+'/'+f.basename+'.'+f.extension);
if(flag){
new Notice(`Copy ${f}`,5000)
}
}
}
}

55
readMe_中文.md Normal file
View file

@ -0,0 +1,55 @@
本插件依赖:[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
> 右键同步文件夹时,删除在目标文件夹中,但不在源文件夹中的笔记或附件。保证同步的文件夹和当前文件夹是相同的。此设置会删除文件,请谨慎操作。

View file

@ -31,7 +31,7 @@ const cmd_set_vexporter = (plugin:NoteSyncPlugin) => ({
await nc.editor.set_frontmatter(
nc.chain.current_note,
'vexporter',
plugin.yaml,
item
)
}
@ -67,8 +67,8 @@ const cmd_export_plugin = (plugin:NoteSyncPlugin) => ({
}
let items = ['main.js','manifest.json','styles.css'];
let dj = await plugin.fsEditor.notechain.chain.tp_suggester(
[plugin.strings.item_copy_data_json,plugin.strings.item_skip_data_json],
[true,false],true,''
[plugin.strings.item_skip_data_json,plugin.strings.item_copy_data_json],
[false,true],true,''
)
if(dj){
items.push('data.json')

View file

@ -5,10 +5,12 @@ import {
import NoteSyncPlugin from '../main';
export interface MySettings {
strict_mode: boolean;
vaultDir:string;
}
export const DEFAULT_SETTINGS: MySettings = {
strict_mode:false,
vaultDir:''
}
@ -52,5 +54,11 @@ export class MySettingTab extends PluginSettingTab {
this.plugin.settings.vaultDir = value;
await this.plugin.saveSettings();
}));
this.add_toggle(
this.plugin.strings.setting_strict_mode,
this.plugin.strings.setting_strict_mode_desc,
'strict_mode'
);
}
}

View file

@ -65,6 +65,22 @@ export class Strings{
}
}
get setting_strict_mode(){
if(this.language=='zh'){
return '严格模式?';
}else{
return 'Strict mode?';
}
}
get setting_strict_mode_desc(){
if(this.language=='zh'){
return '危险!同步时删除目标库中多出的文件';
}else{
return 'Danger! Delet files or folders in target vault but not in current vault.';
}
}
get item_copy_data_json(){
if(this.language=='zh'){
return '复制 data.json';
@ -80,6 +96,14 @@ export class Strings{
return 'Skip data.json';
}
}
get item_sync_vault(){
if(this.language=='zh'){
return '同步到其它库';
}else{
return 'Sync to other vault';
}
}
}
export let strings = new Strings();