From 43a2b7b5fc1e248b37dfca78024f9be2c870e5f4 Mon Sep 17 00:00:00 2001 From: Kageetai Date: Mon, 30 Oct 2023 17:36:15 +0100 Subject: [PATCH] fix: small fix for settings convert script and note preview slicing --- README.md | 1 + src/components/NotePreview.tsx | 16 ++++++---------- src/main.ts | 5 ++++- src/settingsTab.ts | 13 +++++++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 752d507..6dd0429 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Time spans to review, can be defined via three values: `number`, `unit` and `rec given unit to look back to, either once or recurring. **Default (as configured via UI elements):** + ```js [ { number: 1, unit: Unit.month, recurring: false }, diff --git a/src/components/NotePreview.tsx b/src/components/NotePreview.tsx index 242c358..47646f6 100644 --- a/src/components/NotePreview.tsx +++ b/src/components/NotePreview.tsx @@ -17,20 +17,16 @@ const NotePreview = ({ note }: Props) => { useEffect(() => { const read = async () => { - let content = await app.vault.cachedRead(note); - - if (content.startsWith("---")) { - // remove frontmatter - const index = content.indexOf("---", 3); - content = content.slice(index + 3, index + previewLength + 3); - } else { - content = content.slice(0, previewLength); - } + const content = await app.vault.cachedRead(note); + const hasFrontMatter = content.startsWith("---"); + const frontMatterEnd = content.indexOf("---", 3) + 3; + const sliceEnd = frontMatterEnd + previewLength; + const slicedContent = content.slice(0, sliceEnd) + " ..."; ref.current && MarkdownRenderer.render( app, - content + " ...", + hasFrontMatter ? slicedContent : content, ref.current, note.path, view, diff --git a/src/main.ts b/src/main.ts index d5e0487..f9a036a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -64,7 +64,10 @@ export default class JournalReviewPlugin extends Plugin { async loadSettings() { const loadedData = await this.loadData(); // check if v1 settings are loaded and convert them to v2 - if (loadedData?.timeSpans?.[0].hasOwnProperty("length")) { + if ( + loadedData?.timeSpans?.length && + loadedData.timeSpans[0].hasOwnProperty("length") + ) { loadedData.timeSpans = loadedData.timeSpans.map( ([number, unit]: [number, string]) => ({ number, diff --git a/src/settingsTab.ts b/src/settingsTab.ts index 934225a..a036385 100644 --- a/src/settingsTab.ts +++ b/src/settingsTab.ts @@ -97,10 +97,14 @@ export class SettingsTab extends PluginSettingTab { ); new Setting(container.createEl("li")).addButton((button) => - button.setButtonText("Add Time Span").onClick(() => { - this.plugin.settings.timeSpans.push(defaultTimeSpans[0]); - this.display(); - }), + button + .setCta() + .setButtonText("Add Time Span") + .onClick(() => { + this.plugin.settings.timeSpans.push(defaultTimeSpans[0]); + this.plugin.saveSettings(); + this.display(); + }), ); new Setting(containerEl) @@ -136,6 +140,7 @@ export class SettingsTab extends PluginSettingTab { .setName("Preview Length") .setDesc("Length of the preview text to show for each note") .addSlider((slider) => { + console.log("slider", this.plugin.settings.previewLength); slider .setValue(this.plugin.settings.previewLength) .setDynamicTooltip()