From df0b7eb2934a333974b1c68c28ec9e43f7345a1a Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 2 Jan 2022 19:02:58 +0200 Subject: [PATCH] feat(Threading): :sparkles: Custom date format in threading template --- main.js | 21 +++++++++++++++++---- src/BreadcrumbsSettingTab.ts | 19 ++++++++++++++++--- src/constants.ts | 1 + src/interfaces.ts | 1 + src/main.ts | 8 +++----- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index 164fb76f..3f38382b 100644 --- a/main.js +++ b/main.js @@ -21069,6 +21069,7 @@ const DEFAULT_SETTINGS = { alphaSortAsc: true, altLinkFields: [], CSVPaths: "", + dateFormat: "YYYY-MM-DD", debugMode: "WARN", defaultView: true, dendronNoteDelimiter: ".", @@ -25709,9 +25710,8 @@ class BCSettingTab extends require$$0.PluginSettingTab {
  • {{field}}: the field being thread into
  • {{dir}}: the direction being thread into
  • {{current}}: the current note name
  • -
  • {{date}}: the current date
  • - - `)) +
  • {{date}}: the current date (Set the format in the setting below)
  • + `)) .addText((text) => { text.setValue(settings.threadingTemplate); text.inputEl.onblur = async () => { @@ -25719,6 +25719,18 @@ class BCSettingTab extends require$$0.PluginSettingTab { await plugin.saveSettings(); }; }); + new require$$0.Setting(threadingDetails) + .setName("Date Format") + .setDesc("The date format used in the Threading Template (setting above)") + .addMomentFormat((format) => { + format + .setDefaultFormat(DEFAULT_SETTINGS.dateFormat) + .setValue(settings.dateFormat) + .onChange(async (value) => { + settings.dateFormat = value; + await plugin.saveSettings(); + }); + }); const debugDetails = details("Debugging"); new require$$0.Setting(debugDetails) .setName("Debug Mode") @@ -51958,7 +51970,8 @@ class BCPlugin extends require$$0.Plugin { .replace("{{current}}", currFile.basename) .replace("{{field}}", field) .replace("{{dir}}", dir) - .replace("{{date}}", new Date().toLocaleDateString().replaceAll(/[/\\]/g, "")); + //@ts-ignore + .replace("{{date}}", require$$0.moment().format(settings.dateFormat)); let i = 1; while (app.metadataCache.getFirstLinkpathDest(newBasename, "")) { if (i === 1) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index f48a412b..e34c9bb6 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -2,6 +2,7 @@ import log from "loglevel"; import { App, DropdownComponent, + MomentFormatComponent, Notice, PluginSettingTab, Setting, @@ -956,9 +957,8 @@ export class BCSettingTab extends PluginSettingTab {
  • {{field}}: the field being thread into
  • {{dir}}: the direction being thread into
  • {{current}}: the current note name
  • -
  • {{date}}: the current date
  • - - ` +
  • {{date}}: the current date (Set the format in the setting below)
  • + ` ) ) .addText((text) => { @@ -969,6 +969,19 @@ export class BCSettingTab extends PluginSettingTab { }; }); + new Setting(threadingDetails) + .setName("Date Format") + .setDesc("The date format used in the Threading Template (setting above)") + .addMomentFormat((format) => { + format + .setDefaultFormat(DEFAULT_SETTINGS.dateFormat) + .setValue(settings.dateFormat) + .onChange(async (value) => { + settings.dateFormat = value; + await plugin.saveSettings(); + }); + }); + const debugDetails = details("Debugging"); new Setting(debugDetails) diff --git a/src/constants.ts b/src/constants.ts index 7cc64cdb..2c89038e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -140,6 +140,7 @@ export const DEFAULT_SETTINGS: BCSettings = { alphaSortAsc: true, altLinkFields: [], CSVPaths: "", + dateFormat: "YYYY-MM-DD", debugMode: "WARN", defaultView: true, dendronNoteDelimiter: ".", diff --git a/src/interfaces.ts b/src/interfaces.ts index 648ba633..426a04a4 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -19,6 +19,7 @@ export interface BCSettings { defaultView: boolean; dendronNoteDelimiter: string; dendronNoteField: string; + dateFormat: string; downViewWrap: boolean; dotsColour: string; enableAlphaSort: boolean; diff --git a/src/main.ts b/src/main.ts index 63af5d5a..1ce9e936 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { addIcon, EventRef, MarkdownView, - moment_2, + moment, normalizePath, Notice, Plugin, @@ -444,10 +444,8 @@ export default class BCPlugin extends Plugin { .replace("{{current}}", currFile.basename) .replace("{{field}}", field) .replace("{{dir}}", dir) - .replace( - "{{date}}", - new Date().toLocaleDateString().replaceAll(/[/\\]/g, "") - ); + //@ts-ignore + .replace("{{date}}", moment().format(settings.dateFormat)); let i = 1; while (app.metadataCache.getFirstLinkpathDest(newBasename, "")) {