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 {
|
renderSuggestion(file: TFile, el: HTMLElement): void {
|
||||||
el.setText(file.name);
|
el.setText(file.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectSuggestion(file: TFile): void {
|
selectSuggestion(file: TFile): void {
|
||||||
this.inputEl.value = file.name;
|
this.inputEl.value = file.path;
|
||||||
this.inputEl.trigger('input');
|
this.inputEl.trigger('input');
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,22 +69,28 @@ export class MediaTypeManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTemplate(mediaTypeModel: MediaTypeModel, app: App): Promise<string> {
|
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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const templateFile: TFile = app.vault
|
let templateFile = app.vault.getAbstractFileByPath(templateFilePath);
|
||||||
|
|
||||||
|
// 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()
|
.getFiles()
|
||||||
.filter((f: TFile) => f.name === templateFileName)
|
.filter((f: TFile) => f.name === templateFilePath)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if (!templateFile) {
|
if (!templateFile) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const template = await app.vault.cachedRead(templateFile);
|
const template = await app.vault.cachedRead(templateFile as TFile);
|
||||||
// console.log(template);
|
// console.log(template);
|
||||||
return replaceTags(template, mediaTypeModel);
|
return replaceTags(template, mediaTypeModel);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue