-
-
Notifications
You must be signed in to change notification settings - Fork 18
Save the best possible img from custom layout to standard (BL-16086) #7806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5228,6 +5228,18 @@ public string GetCoverImagePathAndElt(out SafeXmlElement coverImgElt) | |
| if (outsideFrontCover == null) | ||
| return null; | ||
|
|
||
| coverImgElt = GetCoverImageElt(outsideFrontCover); | ||
| if (coverImgElt == null) | ||
| return null; | ||
|
|
||
| return GetImagePath(coverImgElt); | ||
| } | ||
|
Comment on lines
+5231
to
+5236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Behavioral change: candidate selection no longer checks file existence on disk The old Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| internal static SafeXmlElement GetCoverImageElt(SafeXmlElement outsideFrontCover) | ||
| { | ||
| if (outsideFrontCover == null) | ||
| return null; | ||
|
|
||
| // Prefer the designated cover image if it is present and not placeholder. | ||
| var designatedCoverImage = outsideFrontCover | ||
| .SafeSelectNodes( | ||
|
|
@@ -5237,21 +5249,20 @@ public string GetCoverImagePathAndElt(out SafeXmlElement coverImgElt) | |
| .FirstOrDefault(); | ||
|
|
||
| SafeXmlElement bestPlaceholderElt = null; | ||
| string bestPlaceholderPath = null; | ||
| string bestPlaceholderSource = null; | ||
|
|
||
| if (designatedCoverImage != null) | ||
| { | ||
| var designatedPath = GetImagePath(designatedCoverImage); | ||
| if (designatedPath != null) | ||
| var designatedSource = GetImageSourceForCoverSelection(designatedCoverImage); | ||
| if (!string.IsNullOrWhiteSpace(designatedSource)) | ||
| { | ||
| if (!ImageUtils.IsPlaceholderImageFilename(designatedPath)) | ||
| if (!ImageUtils.IsPlaceholderImageFilename(designatedSource)) | ||
| { | ||
| coverImgElt = designatedCoverImage; | ||
| return designatedPath; | ||
| return designatedCoverImage; | ||
| } | ||
|
|
||
| bestPlaceholderElt = designatedCoverImage; | ||
| bestPlaceholderPath = designatedPath; | ||
| bestPlaceholderSource = designatedSource; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -5271,25 +5282,32 @@ var candidate in outsideFrontCover | |
| if (candidate == designatedCoverImage) | ||
| continue; | ||
|
|
||
| var candidatePath = GetImagePath(candidate); | ||
| if (candidatePath == null) | ||
| var candidateSource = GetImageSourceForCoverSelection(candidate); | ||
| if (string.IsNullOrWhiteSpace(candidateSource)) | ||
| continue; | ||
|
|
||
| if (!ImageUtils.IsPlaceholderImageFilename(candidatePath)) | ||
| if (!ImageUtils.IsPlaceholderImageFilename(candidateSource)) | ||
| { | ||
| coverImgElt = candidate; | ||
| return candidatePath; | ||
| return candidate; | ||
| } | ||
|
|
||
| if (bestPlaceholderPath == null) | ||
| if (bestPlaceholderSource == null) | ||
| { | ||
| bestPlaceholderElt = candidate; | ||
| bestPlaceholderPath = candidatePath; | ||
| bestPlaceholderSource = candidateSource; | ||
| } | ||
| } | ||
|
|
||
| coverImgElt = bestPlaceholderElt; | ||
| return bestPlaceholderPath; | ||
| return bestPlaceholderElt; | ||
| } | ||
|
|
||
| private static string GetImageSourceForCoverSelection(SafeXmlElement imageElement) | ||
| { | ||
| var imageUrl = HtmlDom.GetImageElementUrl(imageElement); | ||
| if (!string.IsNullOrWhiteSpace(imageUrl.PathOnly.NotEncoded)) | ||
| return imageUrl.PathOnly.NotEncoded; | ||
|
|
||
| return imageUrl.UrlEncoded; | ||
| } | ||
|
|
||
| private string GetImagePath(SafeXmlElement imageElement) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Behavioral regression:
GetCoverImageEltselects elements based on whether the HTML source attribute is non-empty, but does not verify the referenced file exists on disk. The old inline code usedGetImagePath()which checked file existence, so it would skip candidates with broken file references and fall through to other valid candidates. Now, if the best candidate's file is missing,GetCoverImagePathAndEltreturns null instead of trying the next candidate.Consider either (a) having
GetCoverImageEltaccept a file-existence predicate to skip broken references, or (b) adding a fallback loop inGetCoverImagePathAndEltthat retries with the next-best candidate whenGetImagePathreturns null.Prompt for AI agents