Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference correct periodicity when note template is missing #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ export default class PeriodicNotesPlugin extends Plugin {
const config = this.calendarSetManager.getActiveConfig(granularity);
const format = this.calendarSetManager.getFormat(granularity);
const filename = date.format(format);
const templateContents = await getTemplateContents(this.app, config.templatePath);
const templateContents = await getTemplateContents(
this.app,
config.templatePath,
granularity
);
const renderedContents = applyTemplateTransformations(
filename,
granularity,
Expand Down
11 changes: 7 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export async function applyPeriodicTemplateToFile(
const format = getFormat(calendarSet, metadata.granularity);
const templateContents = await getTemplateContents(
app,
calendarSet[metadata.granularity]?.templatePath
calendarSet[metadata.granularity]?.templatePath,
metadata.granularity
);
const renderedContents = applyTemplateTransformations(
file.basename,
Expand All @@ -222,7 +223,8 @@ export async function applyPeriodicTemplateToFile(

export async function getTemplateContents(
app: App,
templatePath: string | undefined
templatePath: string | undefined,
granularity: Granularity
): Promise<string> {
const { metadataCache, vault } = app;
const normalizedTemplatePath = normalizePath(templatePath ?? "");
Expand All @@ -234,11 +236,12 @@ export async function getTemplateContents(
const templateFile = metadataCache.getFirstLinkpathDest(normalizedTemplatePath, "");
return templateFile ? vault.cachedRead(templateFile) : "";
} catch (err) {
const periodicity = granularity === "day" ? "daily" : `${granularity}ly`;
console.error(
`Failed to read the daily note template '${normalizedTemplatePath}'`,
`Failed to read the ${periodicity} note template '${normalizedTemplatePath}'`,
err
);
new Notice("Failed to read the daily note template");
new Notice(`Failed to read the ${periodicity} note template`);
return "";
}
}
Expand Down