Skip to content

Commit

Permalink
feat: add filename to "format_note_with_url"
Browse files Browse the repository at this point in the history
This changes the way the function adds the link to obsidian. Now the file name is added after "Obsidian". e.g. "Obsidian - Tests".
  • Loading branch information
envico801 committed Mar 22, 2024
1 parent feb3db2 commit 7820e7f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,30 @@ export class FormatConverter {
}

format_note_with_url(note: AnkiConnectNote, url: string, field: string): void {
note.fields[field] += '<br><a href="' + url + '" class="obsidian-link">Obsidian</a>'
let mdFilename: string = ""

// We separate the string by "&file=".
const splitUrl: string[] = url.split("&file=");

// Check if the split resulted in two parts
if (splitUrl.length === 2) {
// Extract the part after "&file="
const encodedPathWithExtension: string = splitUrl[1]; // Extracted part containing path with extension
const decodedPathWithExtension: string = decodeURIComponent(encodedPathWithExtension);

// Split the filename from its directory path
const pathSegments: string[] = decodedPathWithExtension.split('/');
const filenameWithExtension: string | undefined = pathSegments.pop()?.trim();

// Check if the filename with extension is not empty
if (filenameWithExtension) {
// Split the filename from its extension
const filenameSegments: string[] = filenameWithExtension.split('.');
mdFilename = filenameSegments[0]?.trim();
}
}

note.fields[field] += '<br><a href="' + url + `" class="obsidian-link">Obsidian${mdFilename ? " - " + mdFilename : ""}</a>`;
}

format_note_with_frozen_fields(note: AnkiConnectNote, frozen_fields_dict: Record<string, Record<string, string>>): void {
Expand Down

0 comments on commit 7820e7f

Please sign in to comment.