Skip to content

Commit

Permalink
feat: add "Template file location" option to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
anpigon committed Aug 14, 2022
1 parent f4d0c23 commit aa961cf
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { replaceDateInString } from '@utils/utils';
import BookSearchPlugin from '../main';
import { FileNameFormatSuggest } from './suggesters/FileNameFormatSuggester';
import { FolderSuggest } from './suggesters/FolderSuggester';
import { FileSuggest } from './suggesters/FileSuggester';

const docUrl = 'https://github.com/anpigon/obsidian-book-search-plugin';

Expand All @@ -13,12 +14,13 @@ export enum DefaultFrontmatterKeyType {
}

export interface BookSearchPluginSettings {
folder: string;
fileNameFormat: string;
frontmatter: string;
content: string;
folder: string; // new file location
fileNameFormat: string; // new file name format
frontmatter: string; // frontmatter that is inserted into the file
content: string; // what is automatically written to the file.
useDefaultFrontmatter: boolean;
defaultFrontmatterKeyType: DefaultFrontmatterKeyType;
templateFile: string;
}

export const DEFAULT_SETTINGS: BookSearchPluginSettings = {
Expand All @@ -28,6 +30,7 @@ export const DEFAULT_SETTINGS: BookSearchPluginSettings = {
content: '',
useDefaultFrontmatter: true,
defaultFrontmatterKeyType: DefaultFrontmatterKeyType.snakeCase,
templateFile: '',
};

export class BookSearchSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -92,6 +95,23 @@ export class BookSearchSettingTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName('Template file location')
.setDesc('Files will be available as templates.')
.addSearch(cb => {
try {
new FileSuggest(this.app, cb.inputEl);
} catch {
// eslint-disable
}
cb.setPlaceholder('Example: templates/template-file')
.setValue(this.plugin.settings.templateFile)
.onChange(newTemplateFile => {
this.plugin.settings.templateFile = newTemplateFile;
this.plugin.saveSettings();
});
});

containerEl.createEl('h2', { text: 'Frontmatter Settings' });

new Setting(containerEl)
Expand Down

0 comments on commit aa961cf

Please sign in to comment.