Skip to content

Commit

Permalink
fix: small fix for settings convert script and note preview slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kageetai committed Oct 30, 2023
1 parent 31b941a commit 43a2b7b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
16 changes: 6 additions & 10 deletions src/components/NotePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions src/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 43a2b7b

Please sign in to comment.