Repository navigation
Fix: Fix images of subpages or identically-named pages of a Section overwriting each other - #214
Open
El1as42 wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #212
With
$medialocation = 1(default), the images of all of a notebook's pages are saved in the notebook'smediafolder, named after the page's Section and name (pathFromRootCompat), e.g.mysection-mypage-image1.png. So subpages with the same name (e.g.Exerciseunder 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
mediaNamePrefix, used to rename images:$medialocation = 1: the page's Section and.mdfile path within the Section (filePathRel), which includes the parent pages and the postfix of identically-named pages, e.g.mysection-mypage-mysubpage-image1.png.$medialocation = 2:filePathRelUnderscore, as before, which was already unique.$mdFileNameAndFolderNameMaxLength, sincefilePathRelis truncated like the.mdfile name.Failed to rename imageerror now shows the image's destination path. It showed the result of the previousNew-ItemorMove-Itemcall instead (e.g. themediafolder), so it was impossible to tell which file name failed.Tests: a
New-SectionGroupConversionConfigtest that media file names are unique within each media folder for both$medialocationvalues, 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 ofConvert-OneNotePagenow 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: thewindows-2019runner image was retired, and the PowerShell 6.0 to 7.0 container images are too old foractions/checkout(GLIBC_2.28' not found).🤖 Generated with Claude Code