obsidian-daily-notes-interface
Advanced tools
Comparing version 0.6.1 to 0.7.0
161
dist/main.js
@@ -17,11 +17,13 @@ 'use strict'; | ||
function getDailyNoteSettings() { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e, _f; | ||
try { | ||
var settings = | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
((_b = (_a = window.app.internalPlugins.getPluginById("daily-notes")) === null || _a === void 0 ? void 0 : _a.instance) === null || _b === void 0 ? void 0 : _b.options) || {}; | ||
var _g = window.app, internalPlugins = _g.internalPlugins, plugins = _g.plugins; | ||
var dailyNoteSettings = (_b = (_a = internalPlugins.getPluginById("daily-notes")) === null || _a === void 0 ? void 0 : _a.instance) === null || _b === void 0 ? void 0 : _b.options; | ||
var periodicNotesSettings = (_d = (_c = plugins.getPlugin("periodic-notes")) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.daily; | ||
var settings = periodicNotesSettings || dailyNoteSettings || {}; | ||
return { | ||
format: settings.format || DEFAULT_DAILY_NOTE_FORMAT, | ||
folder: ((_c = settings.folder) === null || _c === void 0 ? void 0 : _c.trim()) || "", | ||
template: ((_d = settings.template) === null || _d === void 0 ? void 0 : _d.trim()) || "", | ||
folder: ((_e = settings.folder) === null || _e === void 0 ? void 0 : _e.trim()) || "", | ||
template: ((_f = settings.template) === null || _f === void 0 ? void 0 : _f.trim()) || "", | ||
}; | ||
@@ -38,11 +40,20 @@ } | ||
function getWeeklyNoteSettings() { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
try { | ||
var settings = | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
((_a = window.app.plugins.getPlugin("calendar")) === null || _a === void 0 ? void 0 : _a.options) || {}; | ||
var pluginManager = window.app.plugins; | ||
var calendarSettings = (_a = pluginManager.getPlugin("calendar")) === null || _a === void 0 ? void 0 : _a.options; | ||
var periodicNotesSettings = (_c = (_b = pluginManager.getPlugin("periodic-notes")) === null || _b === void 0 ? void 0 : _b.settings) === null || _c === void 0 ? void 0 : _c.weekly; | ||
if (periodicNotesSettings) { | ||
return { | ||
format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT, | ||
folder: ((_d = periodicNotesSettings.folder) === null || _d === void 0 ? void 0 : _d.trim()) || "", | ||
template: ((_e = periodicNotesSettings.template) === null || _e === void 0 ? void 0 : _e.trim()) || "", | ||
}; | ||
} | ||
var settings = calendarSettings || {}; | ||
return { | ||
format: settings.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT, | ||
folder: ((_b = settings.weeklyNoteFolder) === null || _b === void 0 ? void 0 : _b.trim()) || "", | ||
template: ((_c = settings.weeklyNoteTemplate) === null || _c === void 0 ? void 0 : _c.trim()) || "", | ||
folder: ((_f = settings.weeklyNoteFolder) === null || _f === void 0 ? void 0 : _f.trim()) || "", | ||
template: ((_g = settings.weeklyNoteTemplate) === null || _g === void 0 ? void 0 : _g.trim()) || "", | ||
}; | ||
@@ -55,15 +66,15 @@ } | ||
/** | ||
* Read the user settings for the `monthly-notes` plugin | ||
* Read the user settings for the `periodic-notes` plugin | ||
* to keep behavior of creating a new note in-sync. | ||
*/ | ||
function getMonthlyNoteSettings() { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
try { | ||
var settings = | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
((_a = window.app.plugins.getPlugin("monthly-notes")) === null || _a === void 0 ? void 0 : _a.options) || {}; | ||
((_b = (_a = window.app.plugins.getPlugin("periodic-notes")) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.monthly) || {}; | ||
return { | ||
format: settings.format || DEFAULT_MONTHLY_NOTE_FORMAT, | ||
folder: ((_b = settings.folder) === null || _b === void 0 ? void 0 : _b.trim()) || "", | ||
template: ((_c = settings.template) === null || _c === void 0 ? void 0 : _c.trim()) || "", | ||
folder: ((_c = settings.folder) === null || _c === void 0 ? void 0 : _c.trim()) || "", | ||
template: ((_d = settings.template) === null || _d === void 0 ? void 0 : _d.trim()) || "", | ||
}; | ||
@@ -158,3 +169,3 @@ } | ||
}; | ||
var format = getSettings[granularity]().format; | ||
var format = getSettings[granularity]().format.split("/").pop(); | ||
var noteDate = window.moment(file.basename, format, true); | ||
@@ -164,7 +175,43 @@ return noteDate.isValid() ? noteDate : null; | ||
function ensureFolderExists(path$1) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var dirs, dir; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
dirs = path$1.split("/"); | ||
dirs.pop(); // remove basename | ||
dir = ""; | ||
_a.label = 1; | ||
case 1: | ||
if (!dirs.length) return [3 /*break*/, 4]; | ||
dir = path.join(dir, dirs.shift()).replace(/\\/g, "/"); | ||
if (!!window.app.vault.getAbstractFileByPath(dir)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, window.app.vault.createFolder(dir)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: return [3 /*break*/, 1]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
function getNotePath(directory, filename) { | ||
if (!filename.endsWith(".md")) { | ||
filename += ".md"; | ||
} | ||
return obsidian.normalizePath(path.join(directory, filename)); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var path$1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!filename.endsWith(".md")) { | ||
filename += ".md"; | ||
} | ||
path$1 = obsidian.normalizePath(path.join(directory, filename)); | ||
return [4 /*yield*/, ensureFolderExists(path$1)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, path$1]; | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -230,6 +277,8 @@ function getTemplateContents(template) { | ||
filename = date.format(format); | ||
normalizedPath = getNotePath(folder, filename); | ||
_b.label = 2; | ||
return [4 /*yield*/, getNotePath(folder, filename)]; | ||
case 2: | ||
_b.trys.push([2, 4, , 5]); | ||
normalizedPath = _b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, vault.create(normalizedPath, templateContents | ||
@@ -242,11 +291,11 @@ .replace(/{{\s*(date|time)\s*:(.*?)}}/gi, function (_, _timeOrDate, momentFormat) { | ||
.replace(/{{\s*title\s*}}/gi, filename))]; | ||
case 3: | ||
case 4: | ||
createdFile = _b.sent(); | ||
return [2 /*return*/, createdFile]; | ||
case 4: | ||
case 5: | ||
err_1 = _b.sent(); | ||
console.error("Failed to create file: '" + normalizedPath + "'", err_1); | ||
new obsidian.Notice("Unable to create new file."); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
return [3 /*break*/, 6]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
@@ -324,6 +373,8 @@ }); | ||
filename = date.format(format); | ||
normalizedPath = getNotePath(folder, filename); | ||
_b.label = 2; | ||
return [4 /*yield*/, getNotePath(folder, filename)]; | ||
case 2: | ||
_b.trys.push([2, 4, , 5]); | ||
normalizedPath = _b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, vault.create(normalizedPath, templateContents | ||
@@ -338,11 +389,11 @@ .replace(/{{\s*(date|time)\s*:(.*?)}}/gi, function (_, _timeOrDate, momentFormat) { | ||
}))]; | ||
case 3: | ||
case 4: | ||
createdFile = _b.sent(); | ||
return [2 /*return*/, createdFile]; | ||
case 4: | ||
case 5: | ||
err_1 = _b.sent(); | ||
console.error("Failed to create file: '" + normalizedPath + "'", err_1); | ||
new obsidian.Notice("Unable to create new file."); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
return [3 /*break*/, 6]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
@@ -384,3 +435,3 @@ }); | ||
/** | ||
* This function mimics the behavior of the monthly-notes plugin | ||
* This function mimics the behavior of the daily-notes plugin | ||
* so it will replace {{date}}, {{title}}, and {{time}} with the | ||
@@ -403,6 +454,8 @@ * formatted timestamp. | ||
filename = date.format(format); | ||
normalizedPath = getNotePath(folder, filename); | ||
_b.label = 2; | ||
return [4 /*yield*/, getNotePath(folder, filename)]; | ||
case 2: | ||
_b.trys.push([2, 4, , 5]); | ||
normalizedPath = _b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, vault.create(normalizedPath, templateContents | ||
@@ -412,12 +465,14 @@ .replace(/{{\s*(date|time)\s*:(.*?)}}/gi, function (_, _timeOrDate, momentFormat) { | ||
}) | ||
.replace(/{{\s*date\s*}}/gi, filename) | ||
.replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) | ||
.replace(/{{\s*title\s*}}/gi, filename))]; | ||
case 3: | ||
case 4: | ||
createdFile = _b.sent(); | ||
return [2 /*return*/, createdFile]; | ||
case 4: | ||
case 5: | ||
err_1 = _b.sent(); | ||
console.error("Failed to create file: '" + normalizedPath + "'", err_1); | ||
new obsidian.Notice("Unable to create new file."); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
return [3 /*break*/, 6]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
@@ -452,10 +507,16 @@ }); | ||
function appHasDailyNotesPluginLoaded() { | ||
var _a, _b; | ||
var app = window.app; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var dailyNotesPlugin = app.internalPlugins.plugins["daily-notes"]; | ||
return dailyNotesPlugin && dailyNotesPlugin.enabled; | ||
if (dailyNotesPlugin && dailyNotesPlugin.enabled) { | ||
return true; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var periodicNotes = app.plugins.getPlugin("periodic-notes"); | ||
return periodicNotes && ((_b = (_a = periodicNotes.settings) === null || _a === void 0 ? void 0 : _a.daily) === null || _b === void 0 ? void 0 : _b.enabled); | ||
} | ||
/** | ||
* XXX: Currently "Weekly Notes" live in the calendar plugin. | ||
* For now, check for either Calendar plugin and Weekly Notes plugin plugin | ||
* XXX: "Weekly Notes" live in either the Calendar plugin or the periodic-notes plugin. | ||
* Check both until the weekly notes feature is removed from the Calendar plugin. | ||
*/ | ||
@@ -466,3 +527,8 @@ function appHasWeeklyNotesPluginLoaded() { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return (_b = (_a = app.plugins.plugins["calendar"]) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false; | ||
if (app.plugins.getPlugin("calendar")) { | ||
return true; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var periodicNotes = app.plugins.getPlugin("periodic-notes"); | ||
return periodicNotes && ((_b = (_a = periodicNotes.settings) === null || _a === void 0 ? void 0 : _a.weekly) === null || _b === void 0 ? void 0 : _b.enabled); | ||
} | ||
@@ -473,3 +539,4 @@ function appHasMonthlyNotesPluginLoaded() { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return (_b = (_a = app.plugins.plugins["monthly-notes"]) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false; | ||
var periodicNotes = app.plugins.getPlugin("periodic-notes"); | ||
return periodicNotes && ((_b = (_a = periodicNotes.settings) === null || _a === void 0 ? void 0 : _a.monthly) === null || _b === void 0 ? void 0 : _b.enabled); | ||
} | ||
@@ -476,0 +543,0 @@ |
{ | ||
"name": "obsidian-daily-notes-interface", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Interface for creating daily notes in Obsidian", | ||
@@ -5,0 +5,0 @@ "author": "liamcain", |
@@ -10,3 +10,6 @@ import * as moment from "moment-timezone"; | ||
function setConfig(config: dailyNotesInterface.IPeriodicNoteSettings): void { | ||
// eslint-disable-next-line | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(<any>window.app).plugins.plugins["periodic-notes"]._loaded = false; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(<any>window.app).internalPlugins.plugins[ | ||
@@ -13,0 +16,0 @@ "daily-notes" |
@@ -9,5 +9,10 @@ import * as moment from "moment-timezone"; | ||
moment.tz.setDefault("America/New_York"); | ||
function setConfig(config: dailyNotesInterface.IPeriodicNoteSettings): void { | ||
// eslint-disable-next-line | ||
(<any>window.app).plugins.plugins["monthly-notes"].options = config; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const plugin = (<any>window.app).plugins.plugins["periodic-notes"]; | ||
plugin._loaded = true; | ||
plugin.settings.monthly = { ...plugin.settings.monthly, ...config }; | ||
} | ||
@@ -20,3 +25,2 @@ | ||
window.moment = moment; | ||
moment.tz.setDefault("America/New_York"); | ||
}); | ||
@@ -68,5 +72,7 @@ | ||
test("returns true when monthly notes plugin is enabled", () => { | ||
// eslint-disable-next-line | ||
(<any>window.app).plugins.plugins["monthly-notes"].enabled = true; | ||
test("returns true when periodic-notes plugin is enabled", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const periodicNotes = (<any>window.app).plugins.plugins["periodic-notes"]; | ||
periodicNotes._loaded = true; | ||
periodicNotes.settings.monthly.enabled = true; | ||
@@ -76,8 +82,21 @@ expect(dailyNotesInterface.appHasMonthlyNotesPluginLoaded()).toEqual(true); | ||
test("returns true when monthly notes plugin is enabled", () => { | ||
// eslint-disable-next-line | ||
(<any>window.app).plugins.plugins["monthly-notes"].enabled = false; | ||
test("returns false when periodic-notes plugin is enabled and weekly is disabled", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const periodicNotes = (<any>window.app).plugins.plugins["periodic-notes"]; | ||
periodicNotes._loaded = true; | ||
periodicNotes.settings.monthly.enabled = false; | ||
expect(dailyNotesInterface.appHasMonthlyNotesPluginLoaded()).toEqual(false); | ||
}); | ||
test("returns false when periodic-notes plugin is disabled", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const periodicNotes = (<any>window.app).plugins.plugins["periodic-notes"]; | ||
periodicNotes._loaded = false; | ||
periodicNotes.settings.monthly.enabled = false; | ||
expect(dailyNotesInterface.appHasMonthlyNotesPluginLoaded()).toEqual(false); | ||
}); | ||
}); | ||
@@ -145,2 +164,4 @@ | ||
beforeEach(() => { | ||
window.app = getMockApp(); | ||
window.moment = moment; | ||
window.existingFiles = {}; | ||
@@ -172,3 +193,2 @@ }); | ||
format: "YYYY-ww", | ||
template: "template", | ||
}); | ||
@@ -188,2 +208,4 @@ | ||
beforeEach(() => { | ||
window.app = getMockApp(); | ||
window.moment = moment; | ||
window.existingFiles = {}; | ||
@@ -190,0 +212,0 @@ }); |
@@ -11,4 +11,10 @@ import * as moment from "moment-timezone"; | ||
function setConfig(config: dailyNotesInterface.IPeriodicNoteSettings): void { | ||
// eslint-disable-next-line | ||
(window.app as any).plugins.plugins["calendar"].options = { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(<any>window.app).plugins.plugins["periodic-notes"]._loaded = false; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const plugin = (<any>window.app).plugins.plugins["calendar"]; | ||
plugin._loaded = true; | ||
plugin.options = { | ||
weeklyNoteFolder: config.folder, | ||
@@ -111,3 +117,3 @@ weeklyNoteFormat: config.format, | ||
// eslint-disable-next-line | ||
(<any>window.app).plugins.plugins["calendar"].enabled = true; | ||
(<any>window.app).plugins.plugins["calendar"]._loaded = true; | ||
@@ -117,5 +123,7 @@ expect(dailyNotesInterface.appHasWeeklyNotesPluginLoaded()).toEqual(true); | ||
test("returns true when weekly notes plugin is enabled", () => { | ||
test("returns false when weekly notes plugin is disabled", () => { | ||
// eslint-disable-next-line | ||
(<any>window.app).plugins.plugins["calendar"].enabled = false; | ||
(<any>window.app).plugins.plugins["periodic-notes"]._loaded = false; | ||
// eslint-disable-next-line | ||
(<any>window.app).plugins.plugins["calendar"]._loaded = false; | ||
@@ -122,0 +130,0 @@ expect(dailyNotesInterface.appHasWeeklyNotesPluginLoaded()).toEqual(false); |
@@ -26,3 +26,3 @@ import type { Moment } from "moment"; | ||
const filename = date.format(format); | ||
const normalizedPath = getNotePath(folder, filename); | ||
const normalizedPath = await getNotePath(folder, filename); | ||
@@ -29,0 +29,0 @@ try { |
@@ -15,13 +15,26 @@ import type moment from "moment"; | ||
const dailyNotesPlugin = (<any>app).internalPlugins.plugins["daily-notes"]; | ||
return dailyNotesPlugin && dailyNotesPlugin.enabled; | ||
if (dailyNotesPlugin && dailyNotesPlugin.enabled) { | ||
return true; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const periodicNotes = (<any>app).plugins.getPlugin("periodic-notes"); | ||
return periodicNotes && periodicNotes.settings?.daily?.enabled; | ||
} | ||
/** | ||
* XXX: Currently "Weekly Notes" live in the calendar plugin. | ||
* For now, check for either Calendar plugin and Weekly Notes plugin plugin | ||
* XXX: "Weekly Notes" live in either the Calendar plugin or the periodic-notes plugin. | ||
* Check both until the weekly notes feature is removed from the Calendar plugin. | ||
*/ | ||
export function appHasWeeklyNotesPluginLoaded(): boolean { | ||
const { app } = window; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return (<any>app).plugins.plugins["calendar"]?.enabled ?? false; | ||
if ((<any>app).plugins.getPlugin("calendar")) { | ||
return true; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const periodicNotes = (<any>app).plugins.getPlugin("periodic-notes"); | ||
return periodicNotes && periodicNotes.settings?.weekly?.enabled; | ||
} | ||
@@ -32,3 +45,4 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return (<any>app).plugins.plugins["monthly-notes"]?.enabled ?? false; | ||
const periodicNotes = (<any>app).plugins.getPlugin("periodic-notes"); | ||
return periodicNotes && periodicNotes.settings?.monthly?.enabled; | ||
} | ||
@@ -49,5 +63,3 @@ | ||
export { createDailyNote, getDailyNote, getAllDailyNotes } from "./daily"; | ||
export { createWeeklyNote, getAllWeeklyNotes, getWeeklyNote } from "./weekly"; | ||
export { | ||
@@ -54,0 +66,0 @@ createMonthlyNote, |
@@ -11,3 +11,3 @@ import type { Moment } from "moment"; | ||
/** | ||
* This function mimics the behavior of the monthly-notes plugin | ||
* This function mimics the behavior of the daily-notes plugin | ||
* so it will replace {{date}}, {{title}}, and {{time}} with the | ||
@@ -23,3 +23,3 @@ * formatted timestamp. | ||
const filename = date.format(format); | ||
const normalizedPath = getNotePath(folder, filename); | ||
const normalizedPath = await getNotePath(folder, filename); | ||
@@ -36,2 +36,4 @@ try { | ||
) | ||
.replace(/{{\s*date\s*}}/gi, filename) | ||
.replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm")) | ||
.replace(/{{\s*title\s*}}/gi, filename) | ||
@@ -38,0 +40,0 @@ ); |
@@ -34,5 +34,5 @@ import type { Moment } from "moment"; | ||
const { format } = getSettings[granularity](); | ||
const format = getSettings[granularity]().format.split("/").pop(); | ||
const noteDate = window.moment(file.basename, format, true); | ||
return noteDate.isValid() ? noteDate : null; | ||
} |
@@ -14,6 +14,11 @@ import { | ||
try { | ||
const settings = | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(<any>window.app).internalPlugins.getPluginById("daily-notes")?.instance | ||
?.options || {}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const { internalPlugins, plugins } = <any>window.app; | ||
const dailyNoteSettings = internalPlugins.getPluginById("daily-notes") | ||
?.instance?.options; | ||
const periodicNotesSettings = plugins.getPlugin("periodic-notes")?.settings | ||
?.daily; | ||
const settings = periodicNotesSettings || dailyNoteSettings || {}; | ||
return { | ||
@@ -35,5 +40,18 @@ format: settings.format || DEFAULT_DAILY_NOTE_FORMAT, | ||
try { | ||
const settings = | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(<any>window.app).plugins.getPlugin("calendar")?.options || {}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const pluginManager = (<any>window.app).plugins; | ||
const calendarSettings = pluginManager.getPlugin("calendar")?.options; | ||
const periodicNotesSettings = pluginManager.getPlugin("periodic-notes") | ||
?.settings?.weekly; | ||
if (periodicNotesSettings) { | ||
return { | ||
format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT, | ||
folder: periodicNotesSettings.folder?.trim() || "", | ||
template: periodicNotesSettings.template?.trim() || "", | ||
}; | ||
} | ||
const settings = calendarSettings || {}; | ||
return { | ||
@@ -50,3 +68,3 @@ format: settings.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT, | ||
/** | ||
* Read the user settings for the `monthly-notes` plugin | ||
* Read the user settings for the `periodic-notes` plugin | ||
* to keep behavior of creating a new note in-sync. | ||
@@ -58,3 +76,5 @@ */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(<any>window.app).plugins.getPlugin("monthly-notes")?.options || {}; | ||
(<any>window.app).plugins.getPlugin("periodic-notes")?.settings | ||
?.monthly || {}; | ||
return { | ||
@@ -61,0 +81,0 @@ format: settings.format || DEFAULT_MONTHLY_NOTE_FORMAT, |
@@ -33,3 +33,4 @@ import { App, TAbstractFile, TFile, TFolder } from "obsidian"; | ||
_loaded: boolean; | ||
options: Record<string, unknown>; | ||
settings?: Record<string, unknown>; | ||
options?: Record<string, unknown>; | ||
} | ||
@@ -49,8 +50,27 @@ | ||
calendar: { | ||
_loaded: true, | ||
options: {}, | ||
_loaded: false, | ||
}, | ||
"monthly-notes": { | ||
_loaded: false, | ||
options: {}, | ||
"periodic-notes": { | ||
settings: { | ||
daily: { | ||
enabled: false, | ||
format: "", | ||
template: "", | ||
folder: "", | ||
}, | ||
weekly: { | ||
enabled: false, | ||
format: "", | ||
template: "", | ||
folder: "", | ||
}, | ||
monthly: { | ||
enabled: false, | ||
format: "", | ||
template: "", | ||
folder: "", | ||
}, | ||
}, | ||
_loaded: true, | ||
}, | ||
@@ -60,3 +80,6 @@ }; | ||
plugins: pluginList, | ||
getPlugin: (pluginId: string) => pluginList[pluginId], | ||
getPlugin: (pluginId: string) => { | ||
const plugin = pluginList[pluginId]; | ||
return plugin._loaded && plugin; | ||
}, | ||
}; | ||
@@ -63,0 +86,0 @@ |
import { normalizePath, App, Notice } from "obsidian"; | ||
import { join } from "path"; | ||
export function getNotePath(directory: string, filename: string): string { | ||
async function ensureFolderExists(path: string): Promise<void> { | ||
const dirs = path.split("/"); | ||
dirs.pop(); // remove basename | ||
let dir = ""; | ||
while (dirs.length) { | ||
dir = join(dir, dirs.shift()).replace(/\\/g, "/"); | ||
if (!window.app.vault.getAbstractFileByPath(dir)) { | ||
await window.app.vault.createFolder(dir); | ||
} | ||
} | ||
} | ||
export async function getNotePath( | ||
directory: string, | ||
filename: string | ||
): Promise<string> { | ||
if (!filename.endsWith(".md")) { | ||
filename += ".md"; | ||
} | ||
return normalizePath(join(directory, filename)); | ||
const path = normalizePath(join(directory, filename)); | ||
await ensureFolderExists(path); | ||
return path; | ||
} | ||
@@ -10,0 +31,0 @@ |
@@ -40,3 +40,3 @@ import type { Moment } from "moment"; | ||
const filename = date.format(format); | ||
const normalizedPath = getNotePath(folder, filename); | ||
const normalizedPath = await getNotePath(folder, filename); | ||
@@ -43,0 +43,0 @@ try { |
76779
1927