Skip to content

Commit

Permalink
Fixes #9. Add URI to vault and note to the calendar event location fi…
Browse files Browse the repository at this point in the history
…eld.
  • Loading branch information
andrewbrereton committed Nov 11, 2023
1 parent 838736d commit ad2bd14
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/IcalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class IcalService {

event += '' +
'SUMMARY:' + task.getSummary() + '\r\n' +
'LOCATION:ALTREP="' + task.getLocation() + '":' + task.getLocation() + '\r\n' +
'END:VEVENT\r\n';

return event;
Expand Down
13 changes: 10 additions & 3 deletions src/Model/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ export class Task {
public status: TaskStatus;
dates: TaskDate[];
public summary: string;
fileUri: string;

constructor(
status: TaskStatus,
dates: TaskDate[],
summary: string
summary: string,
fileUri: string
) {
this.status = status;
this.dates = dates;
this.summary = summary;
this.fileUri = fileUri;
}

public getId(): string {
Expand Down Expand Up @@ -54,9 +57,13 @@ export class Task {

return `${emoji} ${summary}`;
}

public getLocation(): string {
return this.fileUri;
}
}

export function createTaskFromLine(line: string): Task|null {
export function createTaskFromLine(line: string, fileUri: string): Task|null {
const taskRegExp = /(\*|-)\s*(?<taskStatus>\[.?])\s*(?<summary>.*)\s*/gi;
const dateRegExp = /\b(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{1,2})\b/gi;

Expand All @@ -79,5 +86,5 @@ export function createTaskFromLine(line: string): Task|null {
const taskDates = getTaskDatesFromMarkdown(line);
const summary = getSummaryFromMarkdown(taskMatch?.groups?.summary ?? '');

return new Task(taskStatus, taskDates, summary);
return new Task(taskStatus, taskDates, summary, fileUri);
}
2 changes: 1 addition & 1 deletion src/Model/TaskDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function getTaskDatesFromMarkdown(markdown: string): TaskDate[] {
}

export function getSummaryFromMarkdown(markdown: string): string {
const recurringRegExp = /🔁.*\s+[➕|⏳|🛫|📅|✅]?/gi;
const recurringRegExp = /🔁(.*?)(?=\s(?:➕|⏳|🛫|📅|✅)|\s\d{4}-\d{2}-\d{2}|$)/gi;
const emojiDateRegExp = /\s*➕|⏳|🛫|📅|✅\s?\d{4}-\d{2}-\d{1,2}\s*/gi;
const dateRegExp = /\s*\d{4}-\d{2}-\d{1,2}/gi;

Expand Down
3 changes: 2 additions & 1 deletion src/TaskFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export class TaskFinder {
async findTasks(file: TFile, listItemsCache: ListItemCache[]): Promise<Task[]> {
const fileCachedContent: string = await this.vault.cachedRead(file);
const lines: string[] = fileCachedContent.split('\n');
const fileUri: string = 'obsidian://open?vault=' + file.vault.getName() + '&file=' + file.path;

const tasks: Task[] = listItemsCache
// Get the position of each list item
.map((listItemCache: ListItemCache) => listItemCache.position.start.line)
// Get the line
.map((idx) => lines[idx])
// Create a Task from the line
.map((line: string) => createTaskFromLine(line))
.map((line: string) => createTaskFromLine(line, fileUri))
// Filter out the nulls
.filter((task: Task | null) => task !== null) as Task[]
;
Expand Down

0 comments on commit ad2bd14

Please sign in to comment.