Skip to content

Commit

Permalink
refactor: Add categories, tags, archives, header, footer and analytic…
Browse files Browse the repository at this point in the history
…s view components rayrfan#224
  • Loading branch information
Ray Fan authored and Ray Fan committed Sep 27, 2018
1 parent 98e8f09 commit 2b5947d
Show file tree
Hide file tree
Showing 19 changed files with 376 additions and 123 deletions.
8 changes: 0 additions & 8 deletions src/Fan.Blog/README.md

This file was deleted.

24 changes: 24 additions & 0 deletions src/Fan.Blog/ViewComponents/BlogArchivesViewComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Fan.Blog.Services;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Fan.Blog.ViewComponents
{
/// <summary>
/// The BlogArchives view component.
/// </summary>
public class BlogArchivesViewComponent : ViewComponent
{
private readonly IBlogService _blogSvc;
public BlogArchivesViewComponent(IBlogService blogService)
{
_blogSvc = blogService;
}

public async Task<IViewComponentResult> InvokeAsync()
{
var years = await _blogSvc.GetArchivesAsync();
return View(years);
}
}
}
25 changes: 25 additions & 0 deletions src/Fan.Blog/ViewComponents/BlogCategoriesViewComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Fan.Blog.Services;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace Fan.Blog.ViewComponents
{
/// <summary>
/// The BlogCategories view component.
/// </summary>
public class BlogCategoriesViewComponent : ViewComponent
{
private readonly IBlogService _blogSvc;
public BlogCategoriesViewComponent(IBlogService blogService)
{
_blogSvc = blogService;
}

public async Task<IViewComponentResult> InvokeAsync()
{
var cats = (await _blogSvc.GetCategoriesAsync()).Where(t => t.Count > 0);
return View(cats);
}
}
}
29 changes: 29 additions & 0 deletions src/Fan.Blog/ViewComponents/BlogTagsViewComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Fan.Blog.Services;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace Fan.Blog.ViewComponents
{
/// <summary>
/// The BlogTags view component.
/// </summary>
public class BlogTagsViewComponent : ViewComponent
{
private readonly IBlogService _blogSvc;
public BlogTagsViewComponent(IBlogService blogService)
{
_blogSvc = blogService;
}

/// <summary>
/// Returns the default view for BlogTags. TODO provide param for things like sorting.
/// </summary>
/// <returns></returns>
public async Task<IViewComponentResult> InvokeAsync()
{
var tags = (await _blogSvc.GetTagsAsync()).Where(t => t.Count > 0);
return View(tags);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@model AnalyticsViewModel

@if (!Model.GoogleAnalyticsTrackingID.IsNullOrEmpty())
{
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="@string.Format("https://www.googletagmanager.com/gtag/js?id={0}", Model.GoogleAnalyticsTrackingID)"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '@Model.GoogleAnalyticsTrackingID');
</script>
}

@Html.Raw(Model.AppInsightsFullScript)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@model Dictionary<int, List<MonthItem>>

<ul class="month-list">
@foreach (var year in Model)
{
<li class="year">
@year.Key
<ul class="months">
@foreach (var item in year.Value)
{
<li>
<a href="@item.Url">@item.Title</a> (@item.Count)
</li>
}
</ul>
</li>
}
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@model IEnumerable<Category>

<ul class="widget-categories">
@foreach (var t in Model)
{
<li>
<a href="@t.RssRelativeLink">
<i class="icon-rss" aria-hidden="true" style="color:orange"></i>
</a>
<a title="@t.Description" href="@t.RelativeLink">@t.Title (@t.Count)</a>
</li>
}
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@model IEnumerable<Tag>

<ul class="widget-tags">
@foreach (var t in Model)
{
<li>
<a class="tag" rel="tag" title="@t.Description" href="@t.RelativeLink" style="background-color:@t.Color;">@t.Title</a>
<span class="tag-multiplier"@t.Count</span>
</li>
}
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@model CoreSettings

<footer class="footer">
<div class="container">
<span class="text-muted pull-left">&copy; @DateTime.Now.Year @Model.Title</span>
<span class="text-muted pull-right">Powered by <a href="https://github.com/FanrayMedia/Fanray"><strong>Fanray</strong></a> <text>v</text>@SysVersion.CurrentVersion</span>
</div>
</footer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@model HeaderViewModel

<div class="d-flex flex-column flex-md-row align-items-center px-md-4 pt-2 pb-0 pt-sm-2 pb-sm-0 py-md-2 py-lg-2 py-xl-2 mb-3 bg-white border-bottom box-shadow">
<h5 class="my-0 mr-md-auto font-weight-normal p-0 px-3 pl-md-0 pl-lg-0">
<a class="brand" href="/">@Model.Title</a> <small class="text-muted d-none d-sm-block" style="font-size:small;font-style:italic">@Model.Tagline</small>
</h5>
<nav class="navbar my-md-0 mr-md-3 mb-sm-0 p-0">
<a class="p-2 text-dark" href="/">Home</a>
@if (Model.IsSignedIn)
{
<a class="p-2 text-dark" href="/admin">Admin</a>
<div class="dropdown">
<a class="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img gravatar-email="@Model.CurrentUser.Email" title="@Model.CurrentUser.DisplayName" class="avatar" />
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/admin/compose"><i class="icon-pencil-square-o" aria-hidden="true"></i> Write</a>
<div class="dropdown-divider"></div>
<form asp-area="" asp-controller="Account" asp-action="Logout" method="post" id="logoutForm">
<button type="submit" class="dropdown-item btn btn-link navbar-btn navbar-link"><i class="icon-power-off" aria-hidden="true"></i> Logout</button>
</form>
</div>
</div>
}
else
{
<a class="p-2 text-dark" href="/login">Login</a>
}
</nav>
</div>
120 changes: 9 additions & 111 deletions src/Fan.Web/Themes/Clarity/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
@inject SignInManager<User> SignInManager

@{
var cats = (await blogService.GetCategoriesAsync()).Where(c => c.Count > 0).ToList();
var tags = (await blogService.GetTagsAsync()).Where(t => t.Count > 0).ToList();
var years = await blogService.GetArchivesAsync();

@{
var coreSettings = await settingService.GetSettingsAsync<CoreSettings>();
var blogSettings = await settingService.GetSettingsAsync<BlogSettings>();
var currentUser = await userManager.GetUserAsync(Context.User);
var title = ViewData["Title"] == null ? coreSettings.Title : $"{ViewData["Title"]} - {coreSettings.Title}";
string description = ViewData["Description"] == null ? coreSettings.Tagline : ViewData["Description"] as string;
var description = ViewData["Description"] == null ? coreSettings.Tagline : ViewData["Description"] as string;
var domain = Context.Request.Host;
var showDisqus = blogSettings.AllowComments &&
blogSettings.CommentProvider == ECommentProvider.Disqus && !blogSettings.DisqusShortname.IsNullOrEmpty();
Expand All @@ -33,125 +26,30 @@
@RenderSection("Canonical", required: false)
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="~/rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="~/wlwmanifest.xml" />
<link rel="stylesheet" href="~/themes/@coreSettings.Theme/css/style.css" asp-append-version="true" />
@await Html.PartialAsync("_Analytics")
<link rel="stylesheet" href="~/themes/clarity/css/style.css" asp-append-version="true" />
<vc:analytics />
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center px-md-4 pt-2 pb-0 pt-sm-2 pb-sm-0 py-md-2 py-lg-2 py-xl-2 mb-3 bg-white border-bottom box-shadow">
<h5 class="my-0 mr-md-auto font-weight-normal p-0 px-3 pl-md-0 pl-lg-0">
<a class="brand" href="/">@coreSettings.Title</a> <small class="text-muted d-none d-sm-block" style="font-size:small;font-style:italic">@coreSettings.Tagline</small>
</h5>
<nav class="navbar my-md-0 mr-md-3 mb-sm-0 p-0">
<a class="p-2 text-dark" href="/">Home</a>
@if (SignInManager.IsSignedIn(User))
{
<a class="p-2 text-dark" href="/admin">Admin</a>
<div class="dropdown">
<a class="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img gravatar-email="@currentUser.Email" title="@currentUser.DisplayName" class="avatar" />
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/admin/compose"><i class="icon-pencil-square-o" aria-hidden="true"></i> Write</a>
<div class="dropdown-divider"></div>
<form asp-area="" asp-controller="Account" asp-action="Logout" method="post" id="logoutForm">
<button type="submit" class="dropdown-item btn btn-link navbar-btn navbar-link"><i class="icon-power-off" aria-hidden="true"></i> Logout</button>
</form>
</div>
</div>
}
else
{
<a class="p-2 text-dark" href="/login">Login</a>
}
</nav>
</div>
<vc:header />
<partial name="_CookieConsentPartial" />
<main role="main" class="container">
<div class="row">
<div class="col-md-9 blog-main">
@RenderBody()
</div>
<aside class="col-md-3">
<div class="widgets">
<div class="widget">
<h4 class="widget-header">RSS</h4>
<div class="widget-content">
<div class="social-icons">
<a href="/feed" style="font-size:28px">
<i class="icon-rss" aria-hidden="true" style="color:orange"></i>
</a>
</div>
</div>
</div>
<div class="widget">
<h4 class="widget-header">Tags</h4>
<div class="widget-content">
<ul class="widget-tags">
@foreach (var t in tags)
{
<li>
<a class="tag" rel="tag" title="@t.Description" href="@t.RelativeLink" style="background-color:@t.Color;">@t.Title</a>
<span class="tag-multiplier"@t.Count</span>
</li>
}
</ul>
</div>
</div>
<div class="widget">
<h4 class="widget-header">Categories</h4>
<div class="widget-content">
<ul class="widget-categories">
@foreach (var t in cats)
{
<li>
<a href="@t.RssRelativeLink">
<i class="icon-rss" aria-hidden="true" style="color:orange"></i>
</a>
<a title="@t.Description" href="@t.RelativeLink">@t.Title (@t.Count)</a>
</li>
}
</ul>
</div>
</div>
<div class="widget">
<h4 class="widget-header">Archives</h4>
<div class="widget-content">
<ul class="month-list">
@foreach (var year in years)
{
<li class="year">
@year.Key
<ul class="months">
@foreach (var item in year.Value)
{
<li>
<a href="@item.Url">@item.Title</a> (@item.Count)
</li>
}
</ul>
</li>
}
</ul>
</div>
</div>
</div>
<partial name="_Sidebar" />
</aside>
</div>
</main>
<footer class="footer">
<div class="container">
<span class="text-muted pull-left">&copy; @DateTime.Now.Year @coreSettings.Title</span>
<span class="text-muted pull-right">Powered by <a href="https://github.com/FanrayMedia/Fanray"><strong>Fanray</strong></a> <text>v</text>@SysVersion.CurrentVersion</span>
</div>
</footer>
<vc:footer />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="~/themes/@coreSettings.Theme/js/syntaxhighlighter.min.js"></script>
@RenderSection("Scripts", required: false)
<script src="~/themes/clarity/js/syntaxhighlighter.min.js"></script>
@if (showDisqus)
{
<script id="dsq-count-scr" src="@string.Format("//{0}.disqus.com/count.js", blogSettings.DisqusShortname)" async></script>
}
</body>
</html>
</html>
30 changes: 30 additions & 0 deletions src/Fan.Web/Themes/Clarity/Views/Shared/_Sidebar.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="widgets">
<div class="widget">
<h4 class="widget-header">RSS</h4>
<div class="widget-content">
<div class="social-icons">
<a href="/feed" style="font-size:28px">
<i class="icon-rss" aria-hidden="true" style="color:orange"></i>
</a>
</div>
</div>
</div>
<div class="widget">
<h4 class="widget-header">Tags</h4>
<div class="widget-content">
@await Component.InvokeAsync("BlogTags")
</div>
</div>
<div class="widget">
<h4 class="widget-header">Categories</h4>
<div class="widget-content">
@await Component.InvokeAsync("BlogCategories")
</div>
</div>
<div class="widget">
<h4 class="widget-header">Archives</h4>
<div class="widget-content">
@await Component.InvokeAsync("BlogArchives")
</div>
</div>
</div>
Loading

0 comments on commit 2b5947d

Please sign in to comment.