case insensitive url on post

This commit is contained in:
Tommy Parnell
2022-08-26 13:28:41 -04:00
parent e065871145
commit 2cff53f5d3
4 changed files with 49 additions and 2 deletions

38
fly.toml Normal file
View File

@@ -0,0 +1,38 @@
# fly.toml file generated for tp-blog-2 on 2022-08-26T12:21:08-04:00
app = "tp-blog-2"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 80
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

View File

@@ -73,10 +73,16 @@ namespace TerribleDev.Blog.Web.Controllers
{
return this.RedirectPermanent($"/{postUrl}");
}
// case sensitive lookup
if(postCache.UrlToPost.TryGetValue(postUrl, out var currentPost))
{
return View("Post", model: new PostViewModel() { Post = currentPost });
}
// case insensitive lookup on post
if(postCache.CaseInsensitiveUrlToPost.TryGetValue(postUrl, out var caseInsensitivePost))
{
return View("Post", model: new PostViewModel() { Post = caseInsensitivePost });
}
if(postCache.LandingPagesUrl.TryGetValue(postUrl, out var landingPage))
{
return View("Post", model: new PostViewModel() { Post = landingPage });

View File

@@ -18,6 +18,7 @@ namespace TerribleDev.Blog.Web.Factories
var orderedPosts = rawPosts.OrderByDescending(a => a.PublishDate);
var posts = new List<IPost>(orderedPosts);
var urlToPosts = new Dictionary<string, IPost>();
var caseInsensitiveUrlToPost = new Dictionary<string, IPost>(StringComparer.OrdinalIgnoreCase);
var tagsToPost = new Dictionary<string, IList<Post>>();
var postsByPage = new Dictionary<int, IList<Post>>();
var syndicationPosts = new List<SyndicationItem>();
@@ -30,6 +31,7 @@ namespace TerribleDev.Blog.Web.Factories
{
var castedPost = post as Post;
urlToPosts.Add(post.UrlWithoutPath, castedPost);
caseInsensitiveUrlToPost.Add(post.UrlWithoutPath.ToLower(), castedPost);
syndicationPosts.Add(castedPost.ToSyndicationItem());
blogPostsLD.Add(post.Content.JsonLD);
foreach (var tag in castedPost.ToNormalizedTagList())
@@ -122,8 +124,8 @@ namespace TerribleDev.Blog.Web.Factories
BlogLD = ld,
SiteLD = website,
BlogLDString = ld.ToHtmlEscapedString().Replace("https://schema.org", "https://schema.org/true"),
SiteLDString = website.ToHtmlEscapedString().Replace("https://schema.org", "https://schema.org/true")
SiteLDString = website.ToHtmlEscapedString().Replace("https://schema.org", "https://schema.org/true"),
CaseInsensitiveUrlToPost = caseInsensitiveUrlToPost
};
}
}

View File

@@ -8,6 +8,7 @@ namespace TerribleDev.Blog.Web.Models
public IList<IPost> PostsAsLists { get; set;}
public IDictionary<string, IList<Post>> TagsToPosts { get; set; }
public IDictionary<string, IPost> UrlToPost { get; set; }
public IDictionary<string, IPost> CaseInsensitiveUrlToPost { get; set; }
public IDictionary<int, IList<Post>> PostsByPage { get; set; }
public IList<SyndicationItem> PostsAsSyndication { get; set; }