feat: restrict templater integration behind a setting
This commit is contained in:
parent
3369a4c6cc
commit
65540b5169
2 changed files with 18 additions and 2 deletions
|
|
@ -297,7 +297,9 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
|
|
||||||
const targetFile = await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options);
|
const targetFile = await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options);
|
||||||
|
|
||||||
await useTemplaterPluginInFile(this.app, targetFile);
|
if (this.settings.enableTemplaterIntegration) {
|
||||||
|
await useTemplaterPluginInFile(this.app, targetFile);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
new Notice(e.toString());
|
new Notice(e.toString());
|
||||||
|
|
@ -376,7 +378,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
frontMatter.dataSource = mediaTypeModel.dataSource;
|
frontMatter.dataSource = mediaTypeModel.dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasTemplaterPlugin(this.app)) {
|
if (this.settings.enableTemplaterIntegration && hasTemplaterPlugin(this.app)) {
|
||||||
// Only support stringifyYaml for templater plugin
|
// Only support stringifyYaml for templater plugin
|
||||||
// Include the media variable in all templater commands by using a top level JavaScript execution command.
|
// Include the media variable in all templater commands by using a top level JavaScript execution command.
|
||||||
fileContent = `---\n<%* const media = ${JSON.stringify(mediaTypeModel)} %>\n${stringifyYaml(frontMatter)}---\n${fileContent}`;
|
fileContent = `---\n<%* const media = ${JSON.stringify(mediaTypeModel)} %>\n${stringifyYaml(frontMatter)}---\n${fileContent}`;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ export interface MediaDbPluginSettings {
|
||||||
customDateFormat: string;
|
customDateFormat: string;
|
||||||
openNoteInNewTab: boolean;
|
openNoteInNewTab: boolean;
|
||||||
useDefaultFrontMatter: boolean;
|
useDefaultFrontMatter: boolean;
|
||||||
|
enableTemplaterIntegration: boolean;
|
||||||
|
|
||||||
movieTemplate: string;
|
movieTemplate: string;
|
||||||
seriesTemplate: string;
|
seriesTemplate: string;
|
||||||
|
|
@ -65,6 +66,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
customDateFormat: 'L',
|
customDateFormat: 'L',
|
||||||
openNoteInNewTab: true,
|
openNoteInNewTab: true,
|
||||||
useDefaultFrontMatter: true,
|
useDefaultFrontMatter: true,
|
||||||
|
enableTemplaterIntegration: false,
|
||||||
|
|
||||||
movieTemplate: '',
|
movieTemplate: '',
|
||||||
seriesTemplate: '',
|
seriesTemplate: '',
|
||||||
|
|
@ -232,6 +234,18 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Enable Templater integration')
|
||||||
|
.setDesc(
|
||||||
|
'Enable integration with the templater plugin, this also needs templater to be installed. Warning: Templater allows you to execute arbitrary JavaScript code and system commands.',
|
||||||
|
)
|
||||||
|
.addToggle(cb => {
|
||||||
|
cb.setValue(this.plugin.settings.enableTemplaterIntegration).onChange(data => {
|
||||||
|
this.plugin.settings.enableTemplaterIntegration = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
containerEl.createEl('h3', { text: 'New File Location' });
|
containerEl.createEl('h3', { text: 'New File Location' });
|
||||||
// region new file location
|
// region new file location
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue