Skip to content

Commit

Permalink
A fix for the post search, it will be forced to use the correct URL t…
Browse files Browse the repository at this point in the history
…o post with (avoids 404).
  • Loading branch information
poppastring committed Aug 14, 2020
1 parent f1faa04 commit 86e2f7e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/Config/site.Development.config
Expand Up @@ -19,7 +19,7 @@
<Subtitle>This is DasBlog Core!</Subtitle>
<Description>This blog is powered by DasBlog Core built on the awesome legacy of the original DasBlog!</Description>

<!-- Default visual theme, options currently include "fulcrum" and "median" (see "themes" folder)-->
<!-- Default visual theme, options currently include "fulcrum", "journal", "dasblog", and "median" (see "themes" folder)-->
<Theme>darkly</Theme>

<!-- Contact is the address that is posted on your website so that people can contact you.
Expand Down
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/Config/site.config
Expand Up @@ -19,7 +19,7 @@
<Subtitle>This is DasBlog Core!</Subtitle>
<Description>This blog is powered by DasBlog Core built on the awesome legacy of the original DasBlog!</Description>

<!-- Default visual theme, options currently include "fulcrum" and "median" (see "themes" folder)-->
<!-- Default visual theme, options currently include "fulcrum", "journal", "dasblog", and "median" (see "Themes" folder)-->
<Theme>darkly</Theme>

<!-- Contact is the address that is posted on your website so that people can contact you.
Expand Down
9 changes: 7 additions & 2 deletions source/DasBlog.Web.UI/Controllers/BlogPostController.cs
Expand Up @@ -447,7 +447,7 @@ public IActionResult ApproveComment(Guid postid, Guid commentid)
[HttpGet("post/category/{category}")]
public IActionResult GetCategory(string category)
{
if (string.IsNullOrEmpty(category))
if (string.IsNullOrWhiteSpace(category))
{
return RedirectToAction("Index", "Home");
}
Expand All @@ -463,9 +463,14 @@ public IActionResult GetCategory(string category)
}

[AllowAnonymous]
[HttpPost("/post/search", Name=Constants.SearcherRouteName)]
[HttpPost("post/search", Name=Constants.SearcherRouteName)]
public IActionResult Search(string searchText)
{
if (string.IsNullOrWhiteSpace(searchText))
{
return RedirectToAction("Index", "Home");
}

var lpvm = new ListPostsViewModel();
var entries = blogManager.SearchEntries(WebUtility.HtmlEncode(searchText), Request.Headers["Accept-Language"])?.Where(e => e.IsPublic)?.ToList();

Expand Down
3 changes: 2 additions & 1 deletion source/DasBlog.Web.UI/TagHelpers/SearchBoxTagHelper.cs
@@ -1,4 +1,5 @@
using System;
using DasBlog.Services;
using DasBlog.Web.TagHelpers.Layout;
using Microsoft.AspNetCore.Http;

Expand All @@ -7,7 +8,7 @@ namespace DasBlog.Web.TagHelpers
[Obsolete]
public class SearchBoxTagHelper : SiteSearchBoxTagHelper
{
public SearchBoxTagHelper(IHttpContextAccessor accessor) : base(accessor)
public SearchBoxTagHelper(IDasBlogSettings dasBlogSettings, IHttpContextAccessor accessor) : base(dasBlogSettings, accessor)
{
}
}
Expand Down
15 changes: 12 additions & 3 deletions source/DasBlog.Web.UI/TagHelpers/Site/SiteSearchBoxTagHelper.cs
@@ -1,8 +1,10 @@
using DasBlog.Core.Common;
using DasBlog.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Security.Policy;
using System.Threading.Tasks;

namespace DasBlog.Web.TagHelpers.Layout
Expand All @@ -16,11 +18,14 @@ public class SiteSearchBoxTagHelper : TagHelper
public string Action { get; set; }
public string Heading { get; set; } = "Search";
public string ButtonName { get; set; } = "Go";
public string ButtonClass { get; set; } = "btn";

private readonly IUrlHelper urlHelper;
private readonly IDasBlogSettings dasBlogSettings;

public SiteSearchBoxTagHelper(IHttpContextAccessor accessor)
public SiteSearchBoxTagHelper(IDasBlogSettings dasBlogSettings, IHttpContextAccessor accessor)
{
this.dasBlogSettings = dasBlogSettings;
urlHelper = accessor.HttpContext?.Items[typeof(IUrlHelper)] as IUrlHelper;
if (urlHelper == null)
{
Expand All @@ -41,8 +46,12 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
}
else
{
actionUrl = urlHelper.RouteUrl(Constants.SearcherRouteName);
var baseUri = new Uri(dasBlogSettings.SiteConfiguration.Root);
var myUri = new Uri(baseUri, urlHelper.RouteUrl(Constants.SearcherRouteName));

actionUrl = myUri.AbsoluteUri;
}

output.TagName = string.Empty;
output.Content.Clear();
output.Content.AppendHtml($@"
Expand All @@ -53,7 +62,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
<div class='card-body'>
<form method='post' action='{actionUrl}'>
<input type='text' name='searchText' id='{Id}'/>
<input class='btn' type='submit' value='{ButtonName}'/>
<input class='{ButtonClass}' type='submit' value='{ButtonName}'/>
</form>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/Themes/median/_BlogItem.cshtml
Expand Up @@ -7,7 +7,7 @@
<div class="post">
<div class="row post-title">
<div class="col-md-12 mb-6">
<h1><post-title-link post=@Model css="text-dark"></post-title-link></h1>
<h1><post-title-link post=@Model ></post-title-link></h1>
<post-created-date post="@Model" />
</div>
</div>
Expand Down
14 changes: 4 additions & 10 deletions source/DasBlog.Web.UI/Themes/median/_Layout.cshtml
Expand Up @@ -59,18 +59,12 @@
@RenderBody()
</div>



<div class="col-md-12 col-lg-4">
<div class="card-block">
<div class="card-footer todo-list-footer">
<div class="input-group">
<form action="/post/search" method="post">
<input id="searchText" name="searchText" type="text" class="form-control input-md" placeholder="Ask a question..." />
<span class="input-group-btn">
<button class="btn btn-primary btn-md" id="btn-todo" type="submit">Search</button>
</span>
</form>
</div>
</div>
<site-search-box class="todo-list-footer" inner-class="input-group" heading="Search"
button-class="btn btn-primary btn-md" button-name="Go" />
</div>
</div>

Expand Down

0 comments on commit 86e2f7e

Please sign in to comment.