more nav
This commit is contained in:
@@ -28,7 +28,7 @@ namespace TerribleDev.Blog.Web.Controllers
|
||||
});
|
||||
|
||||
[Route("/")]
|
||||
[Route("/page/{pageNumber}")]
|
||||
[Route("/page/{pageNumber?}" )]
|
||||
public IActionResult Index(int pageNumber = 1)
|
||||
{
|
||||
if(!postsByPage.TryGetValue(pageNumber, out var result))
|
||||
|
||||
@@ -7,6 +7,7 @@ using TerribleDev.Blog.Web.Models;
|
||||
using YamlDotNet.Serialization;
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using TerribleDev.Blog.Web.Extensions;
|
||||
using Markdig;
|
||||
|
||||
namespace TerribleDev.Blog.Web
|
||||
{
|
||||
@@ -36,10 +37,14 @@ namespace TerribleDev.Blog.Web
|
||||
{
|
||||
var splitFile = postText.Split("---");
|
||||
var ymlRaw = splitFile[0];
|
||||
var postContent = Markdig.Markdown.ToHtml(string.Join("", splitFile.Skip(1)));
|
||||
var markdownText = string.Join("", splitFile.Skip(1));
|
||||
var pipeline = new MarkdownPipelineBuilder().UseEmojiAndSmiley().Build();
|
||||
var postContent = Markdown.ToHtml(markdownText, pipeline);
|
||||
var postContentPlain = Markdown.ToPlainText(markdownText, pipeline);
|
||||
var postSettings = ParseYaml(ymlRaw);
|
||||
var resolvedUrl = !string.IsNullOrWhiteSpace(postSettings.permalink) ? postSettings.permalink : fileName.Split('.')[0].Replace(' ', '-').WithoutSpecialCharacters();
|
||||
var summary = postContent.Split("<!-- more -->")[0];
|
||||
var postSummaryPlain = postContentPlain.Split("<!-- more -->")[0];
|
||||
return new Post()
|
||||
{
|
||||
PublishDate = postSettings.date,
|
||||
@@ -47,7 +52,9 @@ namespace TerribleDev.Blog.Web
|
||||
Title = postSettings.title,
|
||||
Url = resolvedUrl,
|
||||
Content = new HtmlString(postContent),
|
||||
Summary = new HtmlString(summary)
|
||||
Summary = new HtmlString(summary),
|
||||
SummaryPlain = postSummaryPlain,
|
||||
ContentPlain = postContentPlain
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace TerribleDev.Blog.Web.Models
|
||||
HtmlString Summary { get; set; }
|
||||
DateTimeOffset PublishDate { get; set; }
|
||||
HtmlString Content { get; set; }
|
||||
string ContentPlain { get; set; }
|
||||
string SummaryPlain { get; set; }
|
||||
IEnumerable<string> tags { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace TerribleDev.Blog.Web.Models
|
||||
public DateTimeOffset PublishDate { get; set; }
|
||||
public HtmlString Content { get; set; }
|
||||
public HtmlString Summary { get; set; }
|
||||
public string ContentPlain { get; set; }
|
||||
public string SummaryPlain { get; set; }
|
||||
public IEnumerable<string> tags { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
41
src/TerribleDev.Blog.Web/Taghelpers/Mobile.cs
Normal file
41
src/TerribleDev.Blog.Web/Taghelpers/Mobile.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TerribleDev.Blog.Web.Taghelpers
|
||||
{
|
||||
[HtmlTargetElement("desktopOnly", TagStructure = TagStructure.NormalOrSelfClosing)]
|
||||
public class DesktopTagHelper : TagHelper
|
||||
{
|
||||
static Regex MobileCheck = new Regex(@"(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
|
||||
static ConcurrentDictionary<string, bool> CachedChecks = new ConcurrentDictionary<string, bool>();
|
||||
public string UserAgent { get; set; }
|
||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
output.TagName = null;
|
||||
if (string.IsNullOrEmpty(UserAgent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var shouldRender = true;
|
||||
if(CachedChecks.TryGetValue(UserAgent, out var cacheResult))
|
||||
{
|
||||
shouldRender = cacheResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
var isMobile = MobileCheck.IsMatch(UserAgent);
|
||||
shouldRender = !isMobile;
|
||||
CachedChecks.TryAdd(UserAgent, !isMobile);
|
||||
}
|
||||
if(!shouldRender)
|
||||
{
|
||||
output.SuppressOutput();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
<nav class="navBar">
|
||||
<p>
|
||||
yo dawg
|
||||
</p> <p>
|
||||
yo dawg
|
||||
</p> <p>
|
||||
yo dawg
|
||||
</p> <p>
|
||||
yo dawg
|
||||
</p> <p>
|
||||
yo dawg
|
||||
</p>
|
||||
<img src="~/content/tommyAvatar3.jpg" class="round" />
|
||||
<span>Tommy "Terrible Dev" Parnell</span>
|
||||
<ul class="sidebarBtns">
|
||||
<li><a href="/" class="link-unstyled">Home</a></li>
|
||||
<li><a href="/all-tags" class="link-unstyled">Tags</a></li>
|
||||
<li><a href="/about" class="link-unstyled">About</a></li>
|
||||
<li><a href="https://github.com/terribledev" target="_blank" class="link-unstyled">Github</a></li>
|
||||
<li><a href="https://twitter.com/terribledev" target="_blank" class="link-unstyled">Twitter</a></li>
|
||||
<li><a href="mailto:tommy@terribledev.io" class="link-unstyled">Email</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
@@ -9,4 +9,8 @@
|
||||
@Model.Content
|
||||
<a href="/" class="btn">< Home</a>
|
||||
</article>
|
||||
</cache>
|
||||
</cache>
|
||||
|
||||
@section Head {
|
||||
<meta name="description" content="@Model.SummaryPlain" />
|
||||
}
|
||||
|
||||
@@ -11,16 +11,18 @@
|
||||
@RenderSection("Head", false)
|
||||
<title>@ViewData["Title"] - The Ramblings of TerribleDev</title>
|
||||
<environment names="Development">
|
||||
<link asp-append-version="true" rel="stylesheet" href="~/css/site.css" />
|
||||
<link asp-append-version="true" rel="stylesheet" href="~/css/site.css" async />
|
||||
</environment>
|
||||
<environment names="Production">
|
||||
<link asp-append-version="true" rel="stylesheet" href="~/css/site.min.css" />
|
||||
<link asp-append-version="true" rel="stylesheet" href="~/css/site.min.css" async/>
|
||||
</environment>
|
||||
</head>
|
||||
<body>
|
||||
@if (ViewData["RenderNav"] != null)
|
||||
{
|
||||
<partial name="Nav" />
|
||||
<desktopOnly user-agent="@this.Context.Request.Headers["User-Agent"]">
|
||||
<partial name="Nav" />
|
||||
</desktopOnly>
|
||||
}
|
||||
@if (ViewData["NoWrap"] != null)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@using TerribleDev.Blog.Web
|
||||
@using TerribleDev.Blog.Web.Models
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@addTagHelper *, TerribleDev.Blog.Web
|
||||
BIN
src/TerribleDev.Blog.Web/wwwroot/content/tommyAvatar2.jpg
Normal file
BIN
src/TerribleDev.Blog.Web/wwwroot/content/tommyAvatar2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
BIN
src/TerribleDev.Blog.Web/wwwroot/content/tommyAvatar3.jpg
Normal file
BIN
src/TerribleDev.Blog.Web/wwwroot/content/tommyAvatar3.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -43,6 +43,7 @@ body {
|
||||
margin: 0 auto;
|
||||
padding-right: 1.2em;
|
||||
padding-left: 1.2em;
|
||||
padding-bottom: 1.2em;
|
||||
}
|
||||
|
||||
.main-content-wrap img {
|
||||
@@ -51,10 +52,10 @@ body {
|
||||
max-width: 100%;
|
||||
margin-bottom: 1.2rem
|
||||
}
|
||||
|
||||
#main {
|
||||
width: calc(100% - 250px);
|
||||
float: right;
|
||||
|
||||
}
|
||||
|
||||
.headline {
|
||||
@@ -85,9 +86,9 @@ a {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #9c9c9c;
|
||||
}
|
||||
a:visited {
|
||||
color: #9c9c9c;
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: auto;
|
||||
@@ -98,7 +99,7 @@ a:visited {
|
||||
cursor: pointer;
|
||||
color: #5d686f !important;
|
||||
border: 1px solid #9eabb3;
|
||||
padding: .25em .8em;
|
||||
padding: .3em .2em;
|
||||
text-decoration: none !important;
|
||||
font-size: 1.1rem;
|
||||
text-transform: uppercase;
|
||||
@@ -137,6 +138,7 @@ a:visited {
|
||||
.navBar {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#main {
|
||||
width: initial;
|
||||
float: initial;
|
||||
@@ -161,6 +163,27 @@ a:visited {
|
||||
position: fixed;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
background-color: red;
|
||||
background: #4A4A4A;
|
||||
color: white;
|
||||
width: 250px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.navBar > * {
|
||||
max-width: 100%;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebarBtns {
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.sidebarBtns > li {
|
||||
margin-bottom: 1.5rem;
|
||||
padding-left: 23px;
|
||||
}
|
||||
|
||||
.round {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user