Skip to content

Commit c531c8d

Browse files
committed
Modify timeblocks exported calendar title
1 parent d076635 commit c531c8d

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

docs/releases/unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l
3434

3535
## Added
3636

37+
- Added a dedicated "Timeblock Event Title Template" setting so synced timeblock event names can differ from task event names
3738
- Added a dedicated Google Calendar integration setting to enable or disable timeblock synchronization independently from task synchronization

src/services/TimeblockCalendarSyncService.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ export class TimeblockCalendarSyncService {
9696
return lines.length > 0 ? lines.join("\n") : undefined;
9797
}
9898

99+
/**
100+
* Apply the shared Google Calendar event title template to a timeblock.
101+
* Supports task placeholders for compatibility and adds timeblock-specific fields.
102+
*/
103+
private applyTitleTemplate(timeblock: TimeBlock, date: string): string {
104+
const settings = this.plugin.settings.googleCalendarExport;
105+
const template =
106+
settings.timeblockEventTitleTemplate || settings.eventTitleTemplate || "{{title}}";
107+
const fallbackTitle = timeblock.title || "Timeblock";
108+
109+
const rendered = template
110+
.replace(/\{\{title\}\}/g, fallbackTitle)
111+
.replace(/\{\{status\}\}/g, "")
112+
.replace(/\{\{priority\}\}/g, "")
113+
.replace(/\{\{due\}\}/g, "")
114+
.replace(/\{\{scheduled\}\}/g, "")
115+
.replace(/\{\{date\}\}/g, date)
116+
.replace(/\{\{startTime\}\}/g, timeblock.startTime || "")
117+
.replace(/\{\{endTime\}\}/g, timeblock.endTime || "")
118+
.trim();
119+
120+
return rendered || fallbackTitle;
121+
}
122+
99123
private toCalendarEvent(timeblock: TimeBlock, date: string): {
100124
summary: string;
101125
description?: string;
@@ -114,7 +138,7 @@ export class TimeblockCalendarSyncService {
114138
end: { dateTime: string; timeZone: string };
115139
colorId?: string;
116140
} = {
117-
summary: timeblock.title || "Timeblock",
141+
summary: this.applyTitleTemplate(timeblock, date),
118142
start: { dateTime: startDateTime, timeZone: timezone },
119143
end: { dateTime: endDateTime, timeZone: timezone },
120144
};

src/settings/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const DEFAULT_GOOGLE_CALENDAR_EXPORT: GoogleCalendarExportSettings = {
198198
syncOnTaskComplete: true,
199199
syncOnTaskDelete: true,
200200
eventTitleTemplate: "{{title}}", // Simple title by default
201+
timeblockEventTitleTemplate: "{{title}}", // Timeblock title by default
201202
includeDescription: true,
202203
eventColorId: null, // Use calendar default color
203204
syncTrigger: "scheduled", // Default to scheduled date

src/settings/tabs/integrationsTab.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,20 @@ export function renderIntegrationsTab(
974974
})
975975
);
976976

977+
// Timeblock event title template
978+
group.addSetting((setting) =>
979+
configureTextSetting(setting, {
980+
name: "Timeblock Event Title Template",
981+
desc: "Template for synced timeblock event titles (used when Sync timeblocks is enabled). Supports {{title}}, {{date}}, {{startTime}}, {{endTime}}.",
982+
placeholder: "{{title}}",
983+
getValue: () => plugin.settings.googleCalendarExport.timeblockEventTitleTemplate,
984+
setValue: async (value: string) => {
985+
plugin.settings.googleCalendarExport.timeblockEventTitleTemplate = value || "{{title}}";
986+
save();
987+
},
988+
})
989+
);
990+
977991
// Include description
978992
group.addSetting(
979993
(setting) =>

src/types/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ export interface GoogleCalendarExportSettings {
335335
syncOnTaskComplete: boolean; // Update event when task is completed
336336
syncOnTaskDelete: boolean; // Delete event when task is deleted
337337
eventTitleTemplate: string; // Template for event title (e.g., "{{title}}" or "[TaskNotes] {{title}}")
338+
timeblockEventTitleTemplate: string; // Template for timeblock event title
338339
includeDescription: boolean; // Include task details in event description
339340
eventColorId: string | null; // Optional: Google Calendar color ID for TaskNotes events (null = calendar default)
340341
syncTrigger: "scheduled" | "due" | "both"; // Which date triggers event creation

0 commit comments

Comments
 (0)