Get the link from normalized link

Obsidian’s Behavior :
When Obsidian encounters a link like [[CLUSTERS/tto-cluster/qqq/tt|tt]], Obsidian simplifies the link to [[tt|tt]] because the full path is unnecessary for resolving the file.

Problem :
The simplified link loses the context of the full path, making it ambiguous if multiple files with the same name exist in different folders.
How to ensure that a normalized link like [[tt|tt]] always refers to the specific file [[CLUSTERS/tto-cluster/qqq/tt|tt]]

Use this method to fetch the TFile for a specific linkpath (the tt in your example: getFirstLinkpathDest - Developer Documentation

What is sourcePath parameter ?

getFirstLinkpathDest(“[[yyy|yyy]]”, “[[yyy|yyy]]”) // null
getFirstLinkpathDest(“[[yyy|yyy]]”, “”) // null
getFirstLinkpathDest(“yyy|yyy”, “”) // null
getFirstLinkpathDest(“yyy”, “”) // null

Sourcepath is the current folder for example:
getFirstLinkpathDest('tt', 'CLUSTERS/tto-cluster/qq')

1 Like

I think it’s a bit inaccurate. I think sourcePath has to include the note file

  • folder1/note1.md
  • folder1/note2.md
  • folder2/note1.md
  • folder2/note2.md
getFirstLinkpathDest('note1.md'); // folder1/note1.md
getFirstLinkpathDest('note1.md', 'folder1'); // folder1/note1.md
getFirstLinkpathDest('note1.md', 'folder2'); // folder1/note1.md
getFirstLinkpathDest('note1.md', 'folder1/note2.md'); // folder1/note1.md

// finally we see the difference
getFirstLinkpathDest('note1.md', 'folder2/note2.md'); // folder2/note1.md
1 Like

Answering your original question

The most likely, you have Shortest path when possible, that’s why your links are being shortened

Change the setting accordingly and your links won’t lose context

1 Like

One way to ensure the full path is preserved is by using the full link format whenever possible, like [[CLUSTERS/tto-cluster/qqq/tt|tt]]. You could also try adding unique identifiers or tags to help distinguish files with the same name in different folders. It might be a bit more manual, but it avoids ambiguity.

1 Like