Skip to content

Commit

Permalink
feat: add book id file type
Browse files Browse the repository at this point in the history
update
  • Loading branch information
zhaohongxuan committed Feb 24, 2024
1 parent 05d5675 commit f82a313
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
11 changes: 0 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@ export default class WereadPlugin extends Plugin {
console.log('load weread plugin');
settingsStore.initialise(this);

<<<<<<< HEAD
const fileManager = new FileManager(this.app.vault, this.app.metadataCache);
=======
const trimBlocks = get(settingsStore).trimBlocks;
console.log('trim', trimBlocks);
this.renderer = new Renderer({
autoescape: false,
trimBlocks: trimBlocks,
lstripBlocks: trimBlocks
});
const fileManager = new FileManager(this.app.vault, this.app.metadataCache, this.renderer);
>>>>>>> 61366f2 (feat: convert tag to bilink)
const apiManager = new ApiManager();
this.syncNotebooks = new SyncNotebooks(fileManager, apiManager);

Expand Down
32 changes: 22 additions & 10 deletions src/fileManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Vault, MetadataCache, TFile, TFolder, Notice, TAbstractFile } from 'obsidian';
import { Renderer } from './renderer';
import { sanitizeTitle } from './utils/sanitizeTitle';
import type { AnnotationFile, DailyNoteReferenece, Metadata, Notebook } from './models';
import { AnnotationFile, DailyNoteReferenece, Metadata, Notebook } from './models';
import { frontMatterDocType, buildFrontMatter } from './utils/frontmatter';
import { get } from 'svelte/store';
import { settingsStore } from './settings';
Expand Down Expand Up @@ -195,16 +195,28 @@ export default class FileManager {
private getFileName(metaData: Metadata): string {
const fileNameType = get(settingsStore).fileNameType;
const baseFileName = sanitizeTitle(metaData.title);
if (fileNameType == 'BOOK_NAME_AUTHOR') {
if (metaData.duplicate) {
return `${baseFileName}-${metaData.author}-${metaData.bookId}`;
}
return `${baseFileName}-${metaData.author}`;
} else {
if (metaData.duplicate || fileNameType == 'BOOK_NAME_BOOKID') {

switch (fileNameType) {
case 'BOOK_ID':
return metaData.bookId;

case 'BOOK_NAME_AUTHOR':
if (metaData.duplicate) {
return `${baseFileName}-${metaData.author}-${metaData.bookId}`;
}
return `${baseFileName}-${metaData.author}`;

case 'BOOK_NAME_BOOKID':
return `${baseFileName}-${metaData.bookId}`;
}
return baseFileName;

case 'BOOK_NAME':
if (metaData.duplicate) {
return `${baseFileName}-${metaData.bookId}`;
}
return baseFileName;

default:
return baseFileName;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/settingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class WereadSettingsTab extends PluginSettingTab {
private convertTagToggle(): void {
new Setting(this.containerEl)
.setName('是否将笔记中标签转换为双链?')
.setDesc('开启此选项会笔记中的#标签转换为[[标签]]')
.setDesc('开启此选项会笔记中的 #标签 转换为:[[标签]]')
.addToggle((toggle) => {
return toggle.setValue(get(settingsStore).convertTags).onChange((value) => {
settingsStore.actions.setConvertTags(value);
Expand Down Expand Up @@ -221,6 +221,7 @@ export class WereadSettingsTab extends PluginSettingTab {
.setDesc('你选择你喜欢的文件名模板,重复的书会在文件名后加上ID')
.addDropdown((dropdown) => {
dropdown.addOptions({
BOOK_ID: 'bookId',
BOOK_NAME: '书名',
BOOK_NAME_AUTHOR: '书名-作者名',
BOOK_NAME_BOOKID: '书名-bookId'
Expand Down

0 comments on commit f82a313

Please sign in to comment.