Skip to content

Fix: Fix images of subpages or identically-named pages of a Section overwriting each other - #214

Open
El1as42 wants to merge 2 commits into
theohbrothers:masterfrom
El1as42:fix/fix-images-of-subpages-or-identically-named-pages-of-a-section-overwriting-each-other
Open

El1as42 wants to merge 2 commits into
theohbrothers:masterfrom
El1as42:fix/fix-images-of-subpages-or-identically-named-pages-of-a-section-overwriting-each-other

Conversation

@El1as42

@El1as42 El1as42 commented Oct 13, 2026 •

Copy link
Copy Markdown

Fixes #212

With $medialocation = 1 (default), the images of all of a notebook's pages are saved in the notebook's media folder, named after the page's Section and name (pathFromRootCompat), e.g. mysection-mypage-image1.png. So subpages with the same name (e.g. Exercise under two different pages) and identically-named pages of a Section got the same image names, and one page's images overwrote the other's. Both pages then showed the same images. I found this by checking a converted notebook for images referenced by more than one note: 12 images were.

Changes

  • New page configuration key mediaNamePrefix, used to rename images:
    • With $medialocation = 1: the page's Section and .md file path within the Section (filePathRel), which includes the parent pages and the postfix of identically-named pages, e.g. mysection-mypage-mysubpage-image1.png.
    • With $medialocation = 2: filePathRelUnderscore, as before, which was already unique.
  • Image names of first level pages that are not identically-named are unchanged, except for page names longer than $mdFileNameAndFolderNameMaxLength, since filePathRel is truncated like the .md file name.
  • Separate commit: the Failed to rename image error now shows the image's destination path. It showed the result of the previous New-Item or Move-Item call instead (e.g. the media folder), so it was impossible to tell which file name failed.

Tests: a New-SectionGroupConversionConfig test that media file names are unique within each media folder for both $medialocation values, for the fake hierarchy with subpages and the one with identically-named pages, and that the names of first level pages are unchanged. It fails without the fix. The image renaming test of Convert-OneNotePage now also checks the new name, and the test for a failed renaming checks the destination path in the error. Unit tests pass on Windows PowerShell 5.1 and PowerShell 7.0. In this repo's CI (run on my fork), all jobs that can currently run pass: Windows PowerShell 5.1 (windows-2022) and PowerShell 7.1 to 7.4. The other jobs currently fail for any PR, before checkout: the windows-2019 runner image was retired, and the PowerShell 6.0 to 7.0 container images are too old for actions/checkout (GLIBC_2.28' not found).

🤖 Generated with Claude Code

…verwriting each other

With `$medialocation = 1` (default), the images of all of a notebook's pages are saved in the notebook's `media` folder, named after the page's Section and name, e.g. `mysection-mypage-image1.png`. So subpages with the same name (e.g. `Exercise` under two different pages) and identically-named pages of a Section got the same image names, and the images of one page overwrote the images of the other. Both pages then showed the same images.

Now image names include the page's parent pages and the postfix of identically-named pages, i.e. the `.md` file's path within the notebook, e.g. `mysection-mypage-mysubpage-image1.png`. Image names of first level pages that are not identically-named are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The error showed the result of the previous `New-Item` or `Move-Item` call (e.g. the `media` folder) instead of the image's destination path, making it impossible to tell which file name failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Images of subpages with the same name or identically-named pages of a Section overwrite each other

1 participant