fix: use file path instead of filename for finding templates
This commit is contained in:
parent
841fbec1a3
commit
06946c73da
2 changed files with 17 additions and 11 deletions
|
|
@ -17,11 +17,11 @@ export class FileSuggest extends TextInputSuggest<TFile> {
|
|||
}
|
||||
|
||||
renderSuggestion(file: TFile, el: HTMLElement): void {
|
||||
el.setText(file.name);
|
||||
el.setText(file.path);
|
||||
}
|
||||
|
||||
selectSuggestion(file: TFile): void {
|
||||
this.inputEl.value = file.name;
|
||||
this.inputEl.value = file.path;
|
||||
this.inputEl.trigger('input');
|
||||
this.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,22 +69,28 @@ export class MediaTypeManager {
|
|||
}
|
||||
|
||||
async getTemplate(mediaTypeModel: MediaTypeModel, app: App): Promise<string> {
|
||||
const templateFileName = this.mediaTemplateMap.get(mediaTypeModel.getMediaType());
|
||||
const templateFilePath = this.mediaTemplateMap.get(mediaTypeModel.getMediaType());
|
||||
|
||||
if (!templateFileName) {
|
||||
if (!templateFilePath) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const templateFile: TFile = app.vault
|
||||
.getFiles()
|
||||
.filter((f: TFile) => f.name === templateFileName)
|
||||
.first();
|
||||
let templateFile = app.vault.getAbstractFileByPath(templateFilePath);
|
||||
|
||||
if (!templateFile) {
|
||||
return '';
|
||||
// WARNING: This was previously selected by filename, but that could lead to collisions and unwanted effects.
|
||||
// This now falls back to the previous method if no file is found
|
||||
if (!templateFile || templateFile instanceof TFolder) {
|
||||
templateFile = app.vault
|
||||
.getFiles()
|
||||
.filter((f: TFile) => f.name === templateFilePath)
|
||||
.first();
|
||||
|
||||
if (!templateFile) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
const template = await app.vault.cachedRead(templateFile);
|
||||
const template = await app.vault.cachedRead(templateFile as TFile);
|
||||
// console.log(template);
|
||||
return replaceTags(template, mediaTypeModel);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue