Refactors path conversion to simplify logic
Replaces manual conversion of absolute paths to vault-relative paths with a utility method to improve code readability and maintainability across various modules. Removes redundant code and streamlines path handling operations. This refactoring helps ensure consistent path management and reduces potential errors related to path conversion. Relates to obsidian-bot-review
This commit is contained in:
6 files changed
+14
-91
No files matched your search
@@ -271,11 +271,11 @@ export class PathUtils {
|
||||
* const pathUtils = new PathUtils(app);
|
||||
* const vaultPath = '/Users/name/vault';
|
||||
* const absolutePath = '/Users/name/vault/folder/file.md';
|
||||
* const relative = pathUtils.toVaultRelativePath(absolutePath);
|
||||
* const relative = pathUtils.toVaultRelative(absolutePath);
|
||||
* // Returns: 'folder/file.md'
|
||||
* ```
|
||||
*/
|
||||
toVaultRelativePath(absolutePath: string): string {
|
||||
toVaultRelative(absolutePath: string): string {
|
||||
const vaultBasePath = this.getVaultPath();
|
||||
if (!absolutePath.startsWith(vaultBasePath)) {
|
||||
return absolutePath;
|
||||
|
||||
Reference in new issue
Block a user