HRINT-4835-1 - missing /blog prefix#140
Merged
Merged
Conversation
9dff1b3 to
b228b1f
Compare
There was a problem hiding this comment.
Pull request overview
Adds render-time rewriting of <img src="..."> URLs in post HTML so legacy posts that reference Images/... (or older ayende.com/Blog/images/... URLs) are served correctly under the /blog/Images/... path without rewriting stored RavenDB data.
Changes:
- Introduce
ImageUrlRewriterthat parses HTML and rewrites<img src>values to/blog/Images/...for recognized legacy patterns. - Apply the rewrite during AutoMapper mapping for both post details and post summaries.
- Add xUnit coverage validating rewrite behavior for legacy/relative/absolute/external image URLs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| RaccoonBlog.Web/Infrastructure/AutoMapper/Profiles/Resolvers/ImageUrlRewriter.cs | Adds HTML parsing + <img src> rewriting logic to normalize legacy image URLs to /blog/Images/.... |
| RaccoonBlog.Web/Infrastructure/AutoMapper/Profiles/PostViewModelMapperProfile.cs | Applies image URL rewriting when mapping Post.Body for the post details view model. |
| RaccoonBlog.Web/Infrastructure/AutoMapper/Profiles/PostsViewModelMapperProfile.cs | Applies image URL rewriting when mapping Post.Body for post summary view models. |
| RaccoonBlog.IntegrationTests/ImageUrlRewriterTests.cs | Adds tests for the new rewrite behavior across several URL formats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
21
to
+23
| .ForMember(x => x.Title, o => o.MapFrom(m => WebUtility.HtmlDecode(m.Title))) | ||
| .ForMember(x => x.Author, o => o.Ignore()) | ||
| .ForMember(x => x.Body, o => o.MapFrom(m => new HtmlString(ImageUrlRewriter.RewriteImageUrls(m.Body)))) |
Author
There was a problem hiding this comment.
I don't think it makes much sense because we have if (string.IsNullOrEmpty(html))
Comment on lines
22
to
25
| .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt)) | ||
| .ForMember(x=>x.Title, o => o.MapFrom(m => System.Net.WebUtility.HtmlDecode(m.Title))) | ||
| .ForMember(x => x.Body, o => o.MapFrom(m => m.Body)) | ||
| .ForMember(x => x.Body, o => o.MapFrom(m => new HtmlString(ImageUrlRewriter.RewriteImageUrls(m.Body)))) | ||
| .ForMember(x => x.IsSerie, o => o.MapFrom(m => m.Title.Contains(":"))) |
f267002 to
786d185
Compare
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.
Post: https://staging.ayende.com/blog/364/confirmed-microsoft-is-cleaning-windows
In RavenDB:
<img src="Images/ms-cleaning-windows.jpg" />At render time, AutoMapper calls ImageUrlRewriter.RewriteImageUrls(), which rewrites the src:
"Images/ms-cleaning-windows.jpg" → "/blog/Images/ms-cleaning-windows.jpg"
The browser loads /blog/Images/ms-cleaning-windows.jpg → ImagesController → RavenDB → image.
I decided to fix this at render time to avoid modifying old data.