feat: add setting to disable default front matter. support templater.

This commit is contained in:
Kelvin John Falk Szolnoky 2023-12-28 17:37:54 +01:00
parent 06946c73da
commit 89b5b0f16b
No known key found for this signature in database
GPG key ID: 02BA666D8C0E7E1B
3 changed files with 156 additions and 32 deletions

View file

@ -16,6 +16,7 @@ export interface MediaDbPluginSettings {
templates: boolean;
customDateFormat: string;
openNoteInNewTab: boolean;
useDefaultFrontMatter: boolean;
movieTemplate: string;
seriesTemplate: string;
@ -63,6 +64,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
templates: true,
customDateFormat: 'L',
openNoteInNewTab: true,
useDefaultFrontMatter: true,
movieTemplate: '',
seriesTemplate: '',
@ -218,6 +220,18 @@ export class MediaDbSettingTab extends PluginSettingTab {
});
});
new Setting(containerEl)
.setName('Use default front matter')
.setDesc('Wheter to use the default front matter. If disabled, the front matter from the template will be used. Same as mapping everything to remove.')
.addToggle(cb => {
cb.setValue(this.plugin.settings.useDefaultFrontMatter).onChange(data => {
this.plugin.settings.useDefaultFrontMatter = data;
this.plugin.saveSettings();
// Redraw settings to display/remove the property mappings
this.display();
});
});
containerEl.createEl('h3', { text: 'New File Location' });
// region new file location
new Setting(containerEl)
@ -531,11 +545,11 @@ export class MediaDbSettingTab extends PluginSettingTab {
// endregion
// region Property Mappings
if (this.plugin.settings.useDefaultFrontMatter) {
containerEl.createEl('h3', { text: 'Property Mappings' });
containerEl.createEl('h3', { text: 'Property Mappings' });
const propertyMappingExplanation = containerEl.createEl('div');
propertyMappingExplanation.innerHTML = `
const propertyMappingExplanation = containerEl.createEl('div');
propertyMappingExplanation.innerHTML = `
<p>Allow you to remap the metadata fields of newly created media db entries.</p>
<p>
The different options are:
@ -549,27 +563,28 @@ export class MediaDbSettingTab extends PluginSettingTab {
Don't forget to save your changes using the save button for each individual category.
</p>`;
new PropertyMappingModelsComponent({
target: this.containerEl,
props: {
models: this.plugin.settings.propertyMappingModels.map(x => x.copy()),
save: (model: PropertyMappingModel): void => {
const propertyMappingModels: PropertyMappingModel[] = [];
new PropertyMappingModelsComponent({
target: this.containerEl,
props: {
models: this.plugin.settings.propertyMappingModels.map(x => x.copy()),
save: (model: PropertyMappingModel): void => {
const propertyMappingModels: PropertyMappingModel[] = [];
for (const model2 of this.plugin.settings.propertyMappingModels) {
if (model2.type === model.type) {
propertyMappingModels.push(model);
} else {
propertyMappingModels.push(model2);
for (const model2 of this.plugin.settings.propertyMappingModels) {
if (model2.type === model.type) {
propertyMappingModels.push(model);
} else {
propertyMappingModels.push(model2);
}
}
}
this.plugin.settings.propertyMappingModels = propertyMappingModels;
new Notice(`MDB: Property Mappings for ${model.type} saved successfully.`);
this.plugin.saveSettings();
this.plugin.settings.propertyMappingModels = propertyMappingModels;
new Notice(`MDB: Property Mappings for ${model.type} saved successfully.`);
this.plugin.saveSettings();
},
},
},
});
});
}
// endregion
}