Daily note title format setting (Localized/ISO/Long/US/EU); filenames stay ISO (#40)

This commit is contained in:
Yuri Karamian
2026-06-10 20:44:29 +02:00
parent 08abbe25ef
commit 67d5ae87c3
6 changed files with 43 additions and 5 deletions
+3 -1
View File
@@ -300,7 +300,7 @@ pub fn create_note(
pub fn create_daily_note(state: State<'_, AppState>, date: Option<String>) -> Result<NoteEntry, String> { pub fn create_daily_note(state: State<'_, AppState>, date: Option<String>) -> Result<NoteEntry, String> {
let config = state.config.lock().map_err(|e| e.to_string())?; let config = state.config.lock().map_err(|e| e.to_string())?;
let vault_path = config.active_vault.as_ref().ok_or("No active vault")?; let vault_path = config.active_vault.as_ref().ok_or("No active vault")?;
let entry = operations::create_daily_note(vault_path, date.as_deref())?; let entry = operations::create_daily_note(vault_path, date.as_deref(), &config.daily_title_format)?;
if let Ok(search_guard) = state.search_index.lock() { if let Ok(search_guard) = state.search_index.lock() {
if let Some(ref search) = *search_guard { if let Some(ref search) = *search_guard {
@@ -1068,6 +1068,7 @@ pub fn set_general_settings(
compact_notes: bool, compact_notes: bool,
time_format: String, time_format: String,
week_start: String, week_start: String,
daily_title_format: String,
gpu_acceleration: bool, gpu_acceleration: bool,
autostart: bool, autostart: bool,
pdf_preview: bool, pdf_preview: bool,
@@ -1088,6 +1089,7 @@ pub fn set_general_settings(
config.restore_last_session = restore_last_session; config.restore_last_session = restore_last_session;
config.time_format = time_format; config.time_format = time_format;
config.week_start = week_start; config.week_start = week_start;
config.daily_title_format = daily_title_format;
config.gpu_acceleration = gpu_acceleration; config.gpu_acceleration = gpu_acceleration;
config.autostart = autostart; config.autostart = autostart;
config.pdf_preview = pdf_preview; config.pdf_preview = pdf_preview;
+7
View File
@@ -79,6 +79,8 @@ pub struct AppConfig {
pub time_format: String, pub time_format: String,
#[serde(default = "default_week_start")] #[serde(default = "default_week_start")]
pub week_start: String, pub week_start: String,
#[serde(default = "default_daily_title_format")]
pub daily_title_format: String,
#[serde(default)] #[serde(default)]
pub gpu_acceleration: bool, pub gpu_acceleration: bool,
#[serde(default)] #[serde(default)]
@@ -178,6 +180,10 @@ fn default_week_start() -> String {
"monday".to_string() "monday".to_string()
} }
fn default_daily_title_format() -> String {
"localized".to_string()
}
fn default_max_versions() -> u32 { fn default_max_versions() -> u32 {
20 20
} }
@@ -201,6 +207,7 @@ impl Default for AppConfig {
show_note_dates: true, show_note_dates: true,
time_format: "relative".to_string(), time_format: "relative".to_string(),
week_start: "monday".to_string(), week_start: "monday".to_string(),
daily_title_format: "localized".to_string(),
gpu_acceleration: true, gpu_acceleration: true,
autostart: false, autostart: false,
pdf_preview: false, pdf_preview: false,
+14 -2
View File
@@ -520,15 +520,27 @@ fn get_system_locale() -> Locale {
} }
} }
pub fn create_daily_note(vault_path: &str, date: Option<&str>) -> Result<NoteEntry, String> { pub fn create_daily_note(
vault_path: &str,
date: Option<&str>,
format: &str,
) -> Result<NoteEntry, String> {
let target_date = match date { let target_date = match date {
Some(d) => chrono::NaiveDate::parse_from_str(d, "%Y-%m-%d") Some(d) => chrono::NaiveDate::parse_from_str(d, "%Y-%m-%d")
.map_err(|e| format!("Invalid date: {}", e))?, .map_err(|e| format!("Invalid date: {}", e))?,
None => Local::now().date_naive(), None => Local::now().date_naive(),
}; };
let date_str = target_date.format("%Y-%m-%d").to_string(); let date_str = target_date.format("%Y-%m-%d").to_string();
let title = match format {
"iso" => target_date.format("%Y-%m-%d").to_string(),
"long" => target_date.format("%B %-d, %Y").to_string(),
"us" => target_date.format("%m/%d/%Y").to_string(),
"eu" => target_date.format("%d/%m/%Y").to_string(),
_ => {
let locale = get_system_locale(); let locale = get_system_locale();
let title = target_date.format_localized("%B %d, %Y", locale).to_string(); target_date.format_localized("%B %d, %Y", locale).to_string()
}
};
let dir = Path::new(vault_path).join("Daily"); let dir = Path::new(vault_path).join("Daily");
fs::create_dir_all(&dir).map_err(|e| e.to_string())?; fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
+2
View File
@@ -216,6 +216,7 @@ export async function setGeneralSettings(
compactNotes: boolean, compactNotes: boolean,
timeFormat: string, timeFormat: string,
weekStart: string, weekStart: string,
dailyTitleFormat: string,
gpuAcceleration: boolean, gpuAcceleration: boolean,
autostart: boolean, autostart: boolean,
pdfPreview: boolean, pdfPreview: boolean,
@@ -234,6 +235,7 @@ export async function setGeneralSettings(
compactNotes, compactNotes,
timeFormat, timeFormat,
weekStart, weekStart,
dailyTitleFormat,
gpuAcceleration, gpuAcceleration,
autostart, autostart,
pdfPreview, pdfPreview,
+15 -1
View File
@@ -461,6 +461,7 @@
let restoreLastSession = $state($appConfig?.restore_last_session ?? false); let restoreLastSession = $state($appConfig?.restore_last_session ?? false);
let timeFormat = $state($appConfig?.time_format ?? 'relative'); let timeFormat = $state($appConfig?.time_format ?? 'relative');
let weekStart = $state($appConfig?.week_start ?? 'monday'); let weekStart = $state($appConfig?.week_start ?? 'monday');
let dailyTitleFormat = $state($appConfig?.daily_title_format ?? 'localized');
let gpuAcceleration = $state($appConfig?.gpu_acceleration ?? true); let gpuAcceleration = $state($appConfig?.gpu_acceleration ?? true);
let autostart = $state($appConfig?.autostart ?? false); let autostart = $state($appConfig?.autostart ?? false);
@@ -519,6 +520,7 @@
$appConfig.restore_last_session = restoreLastSession; $appConfig.restore_last_session = restoreLastSession;
$appConfig.time_format = timeFormat; $appConfig.time_format = timeFormat;
$appConfig.week_start = weekStart; $appConfig.week_start = weekStart;
$appConfig.daily_title_format = dailyTitleFormat;
$appConfig.gpu_acceleration = gpuAcceleration; $appConfig.gpu_acceleration = gpuAcceleration;
$appConfig.autostart = autostart; $appConfig.autostart = autostart;
$appConfig.pdf_preview = pdfPreview; $appConfig.pdf_preview = pdfPreview;
@@ -531,7 +533,7 @@
$appConfig.close_to_tray = closeToTray; $appConfig.close_to_tray = closeToTray;
$appConfig.enable_wiki_links = enableWikiLinks; $appConfig.enable_wiki_links = enableWikiLinks;
} }
setGeneralSettings(compactNotes, timeFormat, weekStart, gpuAcceleration, autostart, pdfPreview, pdfHeight, titleMode, hideTitleInBody, showLineNumbers, defaultViewMode, showTrayIcon, closeToTray, enableWikiLinks, showNoteDates, restoreLastSession) setGeneralSettings(compactNotes, timeFormat, weekStart, dailyTitleFormat, gpuAcceleration, autostart, pdfPreview, pdfHeight, titleMode, hideTitleInBody, showLineNumbers, defaultViewMode, showTrayIcon, closeToTray, enableWikiLinks, showNoteDates, restoreLastSession)
.catch((e) => console.error('Failed to save general settings:', e)); .catch((e) => console.error('Failed to save general settings:', e));
} }
@@ -656,6 +658,7 @@
restoreLastSession = $appConfig.restore_last_session ?? false; restoreLastSession = $appConfig.restore_last_session ?? false;
timeFormat = $appConfig.time_format ?? 'relative'; timeFormat = $appConfig.time_format ?? 'relative';
weekStart = $appConfig.week_start ?? 'monday'; weekStart = $appConfig.week_start ?? 'monday';
dailyTitleFormat = $appConfig.daily_title_format ?? 'localized';
gpuAcceleration = $appConfig.gpu_acceleration ?? true; gpuAcceleration = $appConfig.gpu_acceleration ?? true;
autostart = $appConfig.autostart ?? false; autostart = $appConfig.autostart ?? false;
pdfPreview = $appConfig.pdf_preview ?? false; pdfPreview = $appConfig.pdf_preview ?? false;
@@ -801,6 +804,17 @@
</div> </div>
</div> </div>
<div class="settings-section">
<h3>Daily note title format</h3>
<div class="setting-options">
<button class="option-btn" class:active={dailyTitleFormat === 'localized'} onclick={() => { dailyTitleFormat = 'localized'; saveGeneralSettings(); }}>Localized</button>
<button class="option-btn" class:active={dailyTitleFormat === 'iso'} onclick={() => { dailyTitleFormat = 'iso'; saveGeneralSettings(); }}>2026-06-10</button>
<button class="option-btn" class:active={dailyTitleFormat === 'long'} onclick={() => { dailyTitleFormat = 'long'; saveGeneralSettings(); }}>June 10, 2026</button>
<button class="option-btn" class:active={dailyTitleFormat === 'us'} onclick={() => { dailyTitleFormat = 'us'; saveGeneralSettings(); }}>06/10/2026</button>
<button class="option-btn" class:active={dailyTitleFormat === 'eu'} onclick={() => { dailyTitleFormat = 'eu'; saveGeneralSettings(); }}>10/06/2026</button>
</div>
</div>
{#if isMobile} {#if isMobile}
<div class="settings-section"> <div class="settings-section">
<h3>Vault</h3> <h3>Vault</h3>
+1
View File
@@ -59,6 +59,7 @@ export interface AppConfig {
show_note_dates: boolean; show_note_dates: boolean;
time_format: string; time_format: string;
week_start: string; week_start: string;
daily_title_format: string;
gpu_acceleration: boolean; gpu_acceleration: boolean;
autostart: boolean; autostart: boolean;
pdf_preview: boolean; pdf_preview: boolean;