Skip to content

Commit

Permalink
Added the ability to customize timestamp format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan J.A. Murphy committed Oct 21, 2021
1 parent 9af1009 commit fa50c21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
29 changes: 25 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Notice, Plugin, PluginSettingTab, Setting, moment, MarkdownView, Platform } from 'obsidian';
import { App, Notice, Plugin, PluginSettingTab, Setting, moment, MarkdownView } from 'obsidian';
import { createDailyNote, getAllDailyNotes, getDailyNote } from 'obsidian-daily-notes-interface';

interface LumberjackSettings {
Expand All @@ -8,6 +8,7 @@ interface LumberjackSettings {
inboxFilePath: string;
newDraftFilenameTemplate: string;
targetHeader: string;
timestampFormat: string;
}

const DEFAULT_SETTINGS: LumberjackSettings = {
Expand All @@ -16,7 +17,8 @@ const DEFAULT_SETTINGS: LumberjackSettings = {
alwaysOpenInNewLeaf: false,
inboxFilePath: "Inbox",
newDraftFilenameTemplate: "YYYYMMDDHHmmss",
targetHeader: "Journal"
targetHeader: "Journal",
timestampFormat: "HH:mm"
}

const editModeState = {
Expand Down Expand Up @@ -91,7 +93,7 @@ export default class LumberjackPlugin extends Plugin {
// set up the timestamp string, if the user is using it
let tampTime: string;
if (this.settings.useTimestamp) {
tampTime = moment().format("HH:mm") + " ";
tampTime = moment().format(this.settings.timestampFormat) + " ";
} else {
tampTime = "";
}
Expand Down Expand Up @@ -302,12 +304,17 @@ class LumberjackSettingsTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Timestamp')
.setDesc('If enabled, the log command will prefix newly added lines with a timestamp.')
.setDesc('If enabled, the log command will prefix newly added lines with a timestamp. (Changing this setting reloads the plugin.)')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.useTimestamp)
.onChange(async (value) => {
this.plugin.settings.useTimestamp = value;
await this.plugin.saveSettings();
if (value) {
this.containerEl.appendChild(timestampFormatSetting.settingEl);
} else {
timestampFormatSetting.settingEl.remove();
}
}));

new Setting(containerEl)
Expand Down Expand Up @@ -341,5 +348,19 @@ class LumberjackSettingsTab extends PluginSettingTab {
this.plugin.settings.newDraftFilenameTemplate = value;
await this.plugin.saveSettings();
}));
let timestampFormatSetting = new Setting(containerEl)
.setName('Timestamp format')
.setDesc('Set the format for timestamp prefixes. Follows Moment.js formatting, same as Obsidian\'s core daily notes.')
.addText(text => text
.setValue(this.plugin.settings.timestampFormat)
.setPlaceholder(this.plugin.settings.timestampFormat)
.onChange(async (value) => {
this.plugin.settings.timestampFormat = value;
await this.plugin.saveSettings();
}))

if (!this.plugin.settings.useTimestamp) {
timestampFormatSetting.settingEl.remove();
}
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "lumberjack-obsidian",
"name": "Lumberjack 🪓 🪵",
"version": "1.1.7",
"version": "1.2.0",
"minAppVersion": "0.12.0",
"description": "Log your thoughts! Lumberjack adds URL commands to help you axe inefficiency and get right to writing.",
"author": "ryanjamurphy",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Lumberjack 🪓🪵",
"version": "1.1.7",
"version": "1.2.0",
"description": "Log your thoughts! Lumberjack adds URL commands to help you axe inefficiency and get right to writing.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit fa50c21

Please sign in to comment.