Skip to content

Refactor FindHeroImage to return URL and alt attributes - #727

Merged
poppastring merged 1 commit into
mainfrom
default-image-alt
Aug 17, 2025
Merged

poppastring merged 1 commit into
mainfrom
default-image-alt

Conversation

@poppastring

Copy link
Copy Markdown
Owner

Refactor FindHeroImage to return URL and alt attributes

Refactored the FindHeroImage method in StringExtensions.cs to return a tuple (string url, string alt) instead of a single string, enabling extraction of both src and alt attributes from hero images. Updated regex logic to handle flexible attribute orders in <img> tags.

Enhanced unit tests in StringExtensionTest.cs to validate the new tuple-based implementation and added test cases for various scenarios, including missing alt attributes and fallback behavior.

Updated ProfilePost.cs to map ImageUrl and ImageAlt using the new tuple result. Added a new ImageAlt property in PostViewModel.cs to store the alt attribute of hero images.

These changes improve flexibility, robustness, and test coverage for handling hero images in blog content.

Refactored the `FindHeroImage` method in `StringExtensions.cs` to return a tuple `(string url, string alt)` instead of a single string, enabling extraction of both `src` and `alt` attributes from hero images. Updated regex logic to handle flexible attribute orders in `<img>` tags.

Enhanced unit tests in `StringExtensionTest.cs` to validate the new tuple-based implementation and added test cases for various scenarios, including missing `alt` attributes and fallback behavior.

Updated `ProfilePost.cs` to map `ImageUrl` and `ImageAlt` using the new tuple result. Added a new `ImageAlt` property in `PostViewModel.cs` to store the `alt` attribute of hero images.

These changes improve flexibility, robustness, and test coverage for handling hero images in blog content.
@poppastring
poppastring merged commit d5d15c0 into main Aug 17, 2025
@poppastring
poppastring deleted the default-image-alt branch August 17, 2025 22:51
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.

1 participant