Skip to content

Commit

Permalink
Merge pull request #447 from poppastring/search-page-updates
Browse files Browse the repository at this point in the history
site Search updates

#445
  • Loading branch information
poppastring authored Aug 14, 2020
2 parents f1faa04 + 67e7c94 commit eeb64af
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/Config/site.Development.config
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
12 changes: 2 additions & 10 deletions source/DasBlog.Web.UI/Themes/median/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,8 @@

<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 eeb64af

Please sign in to comment.