Skip to content

Commit

Permalink
Template: Fix template path error when no .md extension
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jul 15, 2021
1 parent eb5d966 commit 8d18699
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Quickly add new pages or content to your vault.
You can also do a [manual installation](docs/ManualInstallation.md).

## What's new?
### 0.3.6 - 0.3.8
### 0.3.6 - 0.3.9
- Added setting to create the 'Insert After' line if it isn't found.
- (HOTFIX) Escape regular expression special characters in Insert After when searching for it
- (HOTFIX) Insert _after_ frontmatter
- (HOTFIX) Escape regular expression special characters in Insert After when searching for it.
- (HOTFIX) Insert _after_ frontmatter.
- (HOTFIX) Fix template choice file name gives error when there is no ``.md`` extension on the path.

### 0.3.5
- You can now execute [inline JavaScript](docs/InlineScripts.md) in templates or captures.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quickadd",
"name": "QuickAdd",
"version": "0.3.8",
"version": "0.3.9",
"minAppVersion": "0.12.5",
"description": "Quickly add new pages or content to your vault.",
"author": "Christian B. B. Houmann",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quickadd",
"version": "0.3.8",
"version": "0.3.9",
"description": "Quickly add new pages or content to your vault.",
"main": "main.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions src/engine/TemplateEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {App, TAbstractFile, TFile} from "obsidian";
import type QuickAdd from "../main";
import {getTemplater, replaceTemplaterTemplatesInCreatedFile} from "../utility";
import GenericSuggester from "../gui/GenericSuggester/genericSuggester";
import {FILE_NUMBER_REGEX} from "../constants";
import {FILE_NUMBER_REGEX, MARKDOWN_FILE_EXTENSION_REGEX} from "../constants";
import {log} from "../logger/logManager";
import type {IChoiceExecutor} from "../IChoiceExecutor";

Expand Down Expand Up @@ -120,7 +120,11 @@ export abstract class TemplateEngine extends QuickAddEngine {
}

protected async getTemplateContent(templatePath: string): Promise<string> {
const templateFile: TAbstractFile = this.app.vault.getAbstractFileByPath(templatePath);
let correctTemplatePath: string = templatePath;
if (!MARKDOWN_FILE_EXTENSION_REGEX.test(templatePath))
correctTemplatePath += ".md";

const templateFile: TAbstractFile = this.app.vault.getAbstractFileByPath(correctTemplatePath);
if (!(templateFile instanceof TFile)) return;

return await this.app.vault.cachedRead(templateFile);
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"0.2.16": "0.12.4",
"0.3.8": "0.12.5"
"0.3.9": "0.12.5"
}

0 comments on commit 8d18699

Please sign in to comment.