Skip to content

fix: robust UUID trimming and safer markdown/csv link conversion - #37

Open
DragonBaiMo wants to merge 1 commit into
connertennery:mainfrom
DragonBaiMo:fix/notion-uuid-trim-and-link-convert
Open

fix: robust UUID trimming and safer markdown/csv link conversion#37
DragonBaiMo wants to merge 1 commit into
connertennery:mainfrom
DragonBaiMo:fix/notion-uuid-trim-and-link-convert

Conversation

@DragonBaiMo

Copy link
Copy Markdown

Summary

This PR improves Notion export path/name cleanup and link conversion so imported Obsidian vaults are more stable and readable.

What changed

  • Replace "truncate by last space" with UUID-suffix-aware trimming (/[\s-]?[0-9a-f]{32}$/i) for files and directories.
  • Keep original media filenames (png/jpg/jpeg/gif/webp/svg/mp4/mov/m4a/mp3/wav/pdf), only trim text-like files.
  • Avoid accidental random suffixes by skipping rename when destination equals source.
  • Improve relative link conversion: decode path, normalize separators, strip Notion UUID suffix, preserve .csv extension in wiki links.
  • Improve notion.so link conversion by removing trailing UUID before slug-to-title transformation.

Why

When converting large exports (especially with Chinese names), the previous logic could over-truncate names or create random suffixes, and generated links could still point to UUID-suffixed names. This made Obsidian navigation inconsistent.

Validation

  • Ran converter against a real-world export bundle and verified:
    • filenames are cleaned by UUID suffix rather than last-space truncation,
    • media files keep original names,
    • generated wiki links are cleaner and more resolvable in Obsidian.

Copilot AI review requested due to automatic review settings March 3, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines Notion export cleanup by trimming only Notion’s UUID suffix from file/folder names and improving link conversion so imported Obsidian vaults resolve more consistently.

Changes:

  • Introduces a UUID-suffix-aware trimming regex and updates file/dir truncation to use it.
  • Preserves media filenames while trimming text-like files, and attempts to skip no-op renames.
  • Improves relative path and notion.so link conversion by decoding/normalizing paths and stripping UUID suffixes (with .csv handling added in wiki links).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.js
Comment on lines 415 to 419
let dest = truncateDirName(dir);
if (dest === dir) {
continue;
}
while (fs.existsSync(dest)) {

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

truncateDirName() returns a resolved (absolute) path, but dir is often a relative path (built via npath.format without resolve). When no trimming occurs, dest points to the same directory but dest !== dir, so the continue won’t trigger and fs.existsSync(dest) will be true, causing the loop to append a random suffix and rename directories unnecessarily (especially when exportPath is relative). Consider comparing normalized absolute paths (e.g., const src = npath.resolve(dir)), skipping when dest === src, and ensuring the collision loop treats dest === src as non-colliding.

Suggested change
let dest = truncateDirName(dir);
if (dest === dir) {
continue;
}
while (fs.existsSync(dest)) {
const src = npath.resolve(dir);
let dest = truncateDirName(dir);
// If truncateDirName did not effectively change the directory name,
// skip renaming to avoid unnecessary collisions and renames.
if (dest === src || dest === dir) {
continue;
}
while (fs.existsSync(dest) && dest !== src) {

Copilot uses AI. Check for mistakes.
Comment thread main.js
Comment on lines +361 to +369
// Preserve media file names. Only trim Notion UUID suffix on markdown/csv and other text files.
if (!/\.(png|jpg|jpeg|gif|webp|svg|mp4|mov|m4a|mp3|wav|pdf)$/i.test(file)) {
let trunc = truncateFileName(file);
vlog(3, `Renaming file ${file} -> ${trunc}`);
fs.renameSync(file, trunc);
file = trunc;
files[i] = trunc;
if (trunc !== file) {
vlog(3, `Renaming file ${file} -> ${trunc}`);
fs.renameSync(file, trunc);
file = trunc;
files[i] = trunc;
}

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

truncateFileName() returns an absolute path (npath.resolve(...)), while file may be relative. That makes if (trunc !== file) almost always true even when the basename didn’t change, so the code will still attempt a rename and rewrite files[i] to an absolute path. To make the “skip rename when destination equals source” logic work reliably, compare trunc against npath.resolve(file) (or stop resolving inside truncateFileName).

Copilot uses AI. Check for mistakes.
Comment thread main.js
Comment on lines +290 to +293
if (ext.toLowerCase() === '.csv') {
return `[[${cleanStem}.csv]]`;
}
return `[[${cleanStem}]]`;

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertRelativePath() can return an empty wiki link if the filename stem is only the UUID (or becomes empty after trimming). cleanStem isn’t given the same fallback used in truncateFileName/convertNotionLinks, so this can produce [[]] (or [[.csv]]). Consider falling back to the original stem when cleanStem is empty.

Suggested change
if (ext.toLowerCase() === '.csv') {
return `[[${cleanStem}.csv]]`;
}
return `[[${cleanStem}]]`;
const safeStem = cleanStem || stem;
if (ext.toLowerCase() === '.csv') {
return `[[${safeStem}.csv]]`;
}
return `[[${safeStem}]]`;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants