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

Device Name #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 29 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import type moment from "moment";

const DEFAULT_SETTINGS: ChangelogSettings = {
deviceName: undefined,
numberOfFilesToShow: 10,
changelogFilePath: "",
watchVaultChange: false,
Expand Down Expand Up @@ -83,12 +84,23 @@ export default class Changelog extends Plugin {
.sort((a, b) => (a.stat.mtime < b.stat.mtime ? 1 : -1))
.slice(0, this.settings.numberOfFilesToShow);
let changelogContent = ``;
let deviceNameSnippet = undefined;

if(this.settings.deviceName)
{
deviceNameSnippet = `- *${this.settings.deviceName}* on`;
}
else
{
deviceNameSnippet = "- "
}

for (let recentlyEditedFile of recentlyEditedFiles) {
// TODO: make date format configurable (and validate it)
const humanTime = window
.moment(recentlyEditedFile.stat.mtime)
.format("YYYY-MM-DD [at] HH[h]mm");
changelogContent += `- ${humanTime} · [[${recentlyEditedFile.basename}]]\n`;
changelogContent += `${deviceNameSnippet} ${humanTime} · [[${recentlyEditedFile.basename}]]\n`;
}
return changelogContent;
}
Expand Down Expand Up @@ -116,6 +128,7 @@ export default class Changelog extends Plugin {
}

interface ChangelogSettings {
deviceName: string;
changelogFilePath: string;
numberOfFilesToShow: number;
watchVaultChange: boolean;
Expand Down Expand Up @@ -149,6 +162,21 @@ class ChangelogSettingsTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Device name")
.setDesc(
"Give this device a unique name to record it against items in the change log"
)
.addText((text) => {
text
.setPlaceholder("Example: Work Laptop")
.setValue(settings.deviceName)
.onChange((value) => {
settings.deviceName = value;
this.plugin.saveSettings();
});
})

new Setting(containerEl)
.setName("Number of recent files in changelog")
.setDesc("Number of most recently edited files to show in the changelog")
Expand Down