Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions apps/obsidian/src/utils/importNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,14 @@
targetFile,
app,
originalNodePath,
spaceName,
}: {
content: string;
oldPathToNewPath: Map<string, string>;
targetFile: TFile;
app: App;
originalNodePath?: string;
spaceName: string;
}): string => {
if (oldPathToNewPath.size === 0) {
return content;
Expand Down Expand Up @@ -644,7 +646,33 @@
}
}

return match;
// For non-asset wikilinks, rewrite them to point to the import folder
// This ensures files created by clicking these links are placed in the correct location
const importBasePath = `import/${sanitizeFileName(spaceName)}`;

// Resolve the link path relative to the original note's directory
let resolvedLinkPath = linkPath;

Check warning on line 654 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L654

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
   654:11  warning  Unsafe assignment of an `any` value                                     @typescript-eslint/no-unsafe-assignment
if (originalNodePath && (linkPath.startsWith("../") || linkPath.startsWith("./"))) {

Check warning on line 655 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L655

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
   655:32  warning  Unsafe call of an `any` typed value                                     @typescript-eslint/no-unsafe-call

Check warning on line 655 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L655

Unsafe member access .startsWith on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
   655:41  warning  Unsafe member access .startsWith on an `any` value                      @typescript-eslint/no-unsafe-member-access

Check warning on line 655 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L655

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
   655:62  warning  Unsafe call of an `any` typed value                                     @typescript-eslint/no-unsafe-call

Check warning on line 655 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L655

Unsafe member access .startsWith on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
   655:71  warning  Unsafe member access .startsWith on an `any` value                      @typescript-eslint/no-unsafe-member-access
// Link is relative to the source note
const originalNoteDir = originalNodePath.includes("/")
? originalNodePath.replace(/\/[^/]*$/, "")
: "";
resolvedLinkPath = resolvePathRelativeToBase(originalNoteDir, linkPath);

Check warning on line 660 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L660

Unsafe argument of type `any` assigned to a parameter of type `string` @typescript-eslint/no-unsafe-argument
Raw output
   660:71  warning  Unsafe argument of type `any` assigned to a parameter of type `string`  @typescript-eslint/no-unsafe-argument
}

// Remove .md extension if present for cleaner paths
const cleanedPath = resolvedLinkPath.replace(/\.md$/, "");

Check warning on line 664 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L664

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
   664:13  warning  Unsafe assignment of an `any` value                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 664 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L664

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
   664:27  warning  Unsafe call of an `any` typed value                                     @typescript-eslint/no-unsafe-call

Check warning on line 664 in apps/obsidian/src/utils/importNodes.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/src/utils/importNodes.ts#L664

Unsafe member access .replace on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
   664:44  warning  Unsafe member access .replace on an `any` value                         @typescript-eslint/no-unsafe-member-access

// Construct the target path in the import folder
const targetPathInImport = `${importBasePath}/${cleanedPath}`;

// Get relative path from current note to the target
const relativePath = getRelativeLinkPath(targetPathInImport);

if (alias) {
return `[[${relativePath}|${alias}]]`;
}
return `[[${relativePath}]]`;
},
);

Expand Down Expand Up @@ -1250,21 +1278,21 @@
originalNodePath,
});

// Update markdown content with new asset paths if assets were imported
if (assetImportResult.pathMapping.size > 0) {
const currentContent = await plugin.app.vault.read(processedFile);
const updatedContent = updateMarkdownAssetLinks({
content: currentContent,
oldPathToNewPath: assetImportResult.pathMapping,
targetFile: processedFile,
app: plugin.app,
originalNodePath,
});

// Only update if content changed
if (updatedContent !== currentContent) {
await plugin.app.vault.modify(processedFile, updatedContent);
}
// Update markdown content to translate all wikilinks to relative paths
// This includes both asset links and non-asset wikilinks
const currentContent = await plugin.app.vault.read(processedFile);
const updatedContent = updateMarkdownAssetLinks({
content: currentContent,
oldPathToNewPath: assetImportResult.pathMapping,
targetFile: processedFile,
app: plugin.app,
originalNodePath,
spaceName,
});

// Only update if content changed
if (updatedContent !== currentContent) {
await plugin.app.vault.modify(processedFile, updatedContent);
}

// Log asset import errors if any
Expand Down
Loading