Skip to content

Commit

Permalink
404 Page + helper for links
Browse files Browse the repository at this point in the history
  • Loading branch information
alanta committed Nov 19, 2020
1 parent c2380c4 commit c1716b1
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 47 deletions.
7 changes: 7 additions & 0 deletions Helpers/HtmlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Statiq.Common;
using System.Collections.Generic;
using System.Linq;
using IHtmlContent = Microsoft.AspNetCore.Html.IHtmlContent;
Expand All @@ -11,6 +12,12 @@ namespace MemoirsTheme.Helpers
{
public static class HtmlHelpers
{
public static string GetLink(this IHtmlHelper html, string relativeUri, bool includeHost = false)
{
var context = html.ViewData["StatiqExecutionContext"] as IExecutionContext;
return context.GetLink(relativeUri, includeHost);
}

public static IHtmlContent Image(this IHtmlHelper html, IEnumerable<IAsset> assets, string? description = null, bool lazy = false,
int? width = null, int? height = null, ImageFitMode? fit = null, object? htmlAttributes = null)
{
Expand Down
1 change: 1 addition & 0 deletions Models/SiteSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class SiteSettings{
public bool ImageShadow { get; set; }
public string Copyright { get; set; }
public bool AuthorBox { get; set; }
public string DisqussId { get; set; }
}
}
2 changes: 1 addition & 1 deletion Pipelines/DownloadImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DownloadImages : Pipeline
{
public DownloadImages()
{
Dependencies.AddRange(nameof(Posts), nameof(Home), nameof(Pages));
Dependencies.AddRange(nameof(Posts), nameof(Home), nameof(Pages), nameof(StaticPages));
PostProcessModules = new ModuleList(
// pull documents from other pipelines
new ReplaceDocuments(Dependencies.ToArray()),
Expand Down
22 changes: 13 additions & 9 deletions Pipelines/Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
using Statiq.Core;
using Statiq.Razor;
using Statiq.SearchIndex;
using System.Linq;

namespace Kentico.Kontent.Statiq.Lumen.Pipelines
{
public class Pages : Pipeline
{
public Pages(IDeliveryClient deliveryClient, SiteSettings site)
{
InputModules = new ModuleList{
InputModules = new ModuleList
{
new Kontent<Page>(deliveryClient)
.OrderBy(Post.TitleCodename, SortOrder.Descending)
.WithQuery(new DepthParameter(2), new IncludeTotalCountParameter()),
new SetDestination(KontentConfig.Get((Page page) => new NormalizedPath(page.Url))),
new SetMetadata(SearchIndex.SearchItemKey, Config.FromDocument((doc,ctx)=>
new SetDestination(KontentConfig.Get((Page page) => new NormalizedPath(page.Url))),
new SetMetadata(SearchIndex.SearchItemKey, Config.FromDocument((doc, ctx) =>
{
var page = doc.AsKontent<Page>();
return new LunrIndexDocItem(doc, page.Title, page.Body)
Expand All @@ -31,17 +31,21 @@ public Pages(IDeliveryClient deliveryClient, SiteSettings site)
})),
};

ProcessModules = new ModuleList {
new MergeContent(new ReadFiles(patterns: "Page.cshtml") ),
ProcessModules = new ModuleList
{
new MergeContent(new ReadFiles(patterns: "Page.cshtml")),
new RenderRazor()
.WithViewData("SiteMetadata", site )
.WithViewData("SiteMetadata", site)
.WithModel(KontentConfig.As<Page>()),
new KontentImageProcessor()
};

OutputModules = new ModuleList {
OutputModules = new ModuleList
{
new WriteFiles(),
};
}
}
}
}


30 changes: 30 additions & 0 deletions Pipelines/StaticPages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Kentico.Kontent.Statiq.Memoirs.Models;
using Kontent.Statiq;
using Statiq.Common;
using Statiq.Core;
using Statiq.Razor;

namespace Kentico.Kontent.Statiq.Lumen.Pipelines
{
public class StaticPages : Pipeline
{
public StaticPages(SiteSettings site)
{
InputModules = new ModuleList
{
new ReadFiles(patterns: "404.cshtml"),
new SetDestination( Config.FromDocument( (doc,ctx) => new NormalizedPath(doc.Source.FileNameWithoutExtension+".html")))
};

ProcessModules = new ModuleList {
new RenderRazor()
.WithViewData("SiteMetadata", site ),
new KontentImageProcessor()
};

OutputModules = new ModuleList {
new WriteFiles(),
};
}
}
}
7 changes: 1 addition & 6 deletions input/404.html → input/404.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
---
layout: default
title: 404
permalink: /404.html
---
<style>
.newsletter, .footer {
display:none;
Expand All @@ -11,5 +6,5 @@
<div class="text-center">
<h1 class="mt-5"><span class="badge badge-dark font-weight-normal">404</span></h1>
<h1 class="display-1 mt-4 mb-4"> Page not found!</h1>
<p>Please use the search bar from the bottom left or visit our <a href="{{site.baseurl}}/">homepage</a>!</p>
<p>Please use the search bar from the bottom left or visit our <a href="@Html.GetLink("/")">homepage</a>!</p>
</div>
32 changes: 15 additions & 17 deletions input/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="icon" href="@IExecutionContext.Current.GetLink("/assets/images/logo.png")">
<link rel="icon" href="@Html.GetLink("/assets/images/logo.png")">

<title>@ViewBag.Title | @site.Name</title>

@RenderSection("seo", required: false)

<link href="@IExecutionContext.Current.GetLink("/assets/css/prism.css")" rel="stylesheet">
<link href="@Html.GetLink("/assets/css/prism.css")" rel="stylesheet">

<link href="@IExecutionContext.Current.GetLink("/assets/css/theme.css")" rel="stylesheet">
<link href="@Html.GetLink("/assets/css/theme.css")" rel="stylesheet">

<script src="@IExecutionContext.Current.GetLink("/assets/js/jquery.min.js")"></script>
<script src="@Html.GetLink("/assets/js/jquery.min.js")"></script>

</head>

Expand Down Expand Up @@ -56,10 +56,10 @@
<nav id="menu">
<ul>
<h3>Navigation</h3>
<li><a href="@IExecutionContext.Current.GetLink("/")">Home</a></li>
<li><a href="@IExecutionContext.Current.GetLink("/about")">About <span class="badge badge-primary">Memoirs Jekyll Theme</span></a></li>
<li><a href="@Html.GetLink("/")">Home</a></li>
<li><a href="@Html.GetLink("/about")">About <span class="badge badge-primary">Memoirs Jekyll Theme</span></a></li>
<li><a target="_blank" href="https://bootstrapstarter.com/bootstrap-templates/jekyll-theme-memoirs/">Get Memoirs</a></li>
<li><a href="@IExecutionContext.Current.GetLink("/contact")">Contact</a></li>
<li><a href="@Html.GetLink("/contact")">Contact</a></li>
</ul>
</nav>
<partial name="Shared/search-lunr"/>
Expand All @@ -74,8 +74,8 @@
<!-- Site Logo/Name
================================================== -->

<a class="navbar-brand" href="@IExecutionContext.Current.GetLink("/")">
<img src="@IExecutionContext.Current.GetLink(site.Logo)" alt="@site.Name">
<a class="navbar-brand" href="@Html.GetLink("/")">
<img src="@Html.GetLink(site.Logo)" alt="@site.Name">
</a>


Expand All @@ -97,7 +97,7 @@
<!-- Newsletter
================================================== -->
<div class="newsletter text-center">
<span class="h4"><img src="@IExecutionContext.Current.GetLink(site.Logo)" class="newsletter-logo" alt="{{site.title}}"> &nbsp; Never miss a <b>story</b> from us, subscribe to our newsletter</span>
<span class="h4"><img src="@Html.GetLink(site.Logo)" class="newsletter-logo" alt="{{site.title}}"> &nbsp; Never miss a <b>story</b> from us, subscribe to our newsletter</span>
<form action="{{site.mailchimp-list}}" method="post" name="mc-embedded-subscribe-form" class="wj-contact-form validate" target="_blank" novalidate>
<div class="mc-field-group d-inline-flex">
<input type="email" placeholder="Your e-mail" name="EMAIL" class="required email" id="mce-EMAIL" autocomplete="on" required>
Expand All @@ -118,7 +118,7 @@
Copyright © @DateTime.Today.Year @site.Copyright
</div>
<div class="col-md-6 col-sm-12 text-center text-lg-right">
<a target="_blank" href="https://www.wowthemes.net/memoirs-free-jekyll-theme/">Memoirs Statiq Kontent Theme</a> by WowThemes.net and Alanta
<a target="_blank" href="https://github.com/alanta/Memoirs-Theme">Memoirs Statiq Kontent Theme</a> by WowThemes.net and Alanta
</div>
</div>
</div>
Expand All @@ -130,18 +130,16 @@
<!-- Scripts (if you need bootstrap.js, please add it yourself. I didn't use it for performance reasons, it was not needed in this theme)
================================================== -->

<script src="@IExecutionContext.Current.GetLink("/assets/js/prism.js")"></script>
<script src="@Html.GetLink("/assets/js/prism.js")"></script>

<script src="@IExecutionContext.Current.GetLink("/assets/js/theme.js")"></script>
<script src="@Html.GetLink("/assets/js/theme.js")"></script>

@if (site.LazyImages)
{
<script src="@IExecutionContext.Current.GetLink("/assets/js/lazyload.js")"></script>
<script src="@Html.GetLink("/assets/js/lazyload.js")"></script>
}

@if (ViewBag.Layout == "post")
{
<script id="dsq-count-scr" src="//{{site.disqus}}.disqus.com/count.js"></script>}
@RenderSection("footerScripts", false);

</body>
</html>
3 changes: 2 additions & 1 deletion input/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using MemoirsTheme.Helpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
35 changes: 22 additions & 13 deletions input/post.cshtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@using Kentico.Kontent.Statiq.Memoirs.Models
@model Kentico.Kontent.Statiq.Memoirs.Models.Post
@{
@{
var site = ViewData["SiteMetaData"] as SiteSettings;
var author = Model.Author.OfType<Author>().FirstOrDefault();
ViewData["Author"] = author;
}
ViewData["Author"] = author; }
<div class="entry-header">
<!-- Post Title -->
<h1 class="posttitle">@Model.Title</h1>
Expand All @@ -14,11 +14,10 @@
<div>
@if (author.AvatarImage?.Any() ?? false)
{
<img class="author-thumb" src="@author.AvatarImage.First().Url?w=250&h=250" alt="@author.Name"> }
else
{
<img class="author-thumb" src="https://www.gravatar.com/avatar/{{ author.gravatar }}?s=250&d=mm&r=x" alt="@author.Name">
}
<img class="author-thumb" src="@author.AvatarImage.First().Url?w=250&h=250" alt="@author.Name"> }
else
{
<img class="author-thumb" src="https://www.gravatar.com/avatar/@author.Gravatar?s=250&d=mm&r=x" alt="@author.Name">}
</div>
<div>
Written by <span class="text-dark">@author.Name</span> on
Expand All @@ -40,17 +39,17 @@
@if (Model.Rating.HasValue)
{
<div class="rating mt-4 mb-4 d-flex align-items-center">
<strong class="mr-1">Rating:</strong> <partial name="Shared/star_rating" model="Model.Rating.Value"/>
<strong class="mr-1">Rating:</strong> <partial name="Shared/star_rating" model="Model.Rating.Value" />
</div>}

<!-- Author Box if enabled from _config.yml -->
<partial name="Shared/author-box" model="author"/>
<partial name="Shared/author-box" model="author" />

<!-- Comments if not disabled with comments: false -->
{% include comments.html %}

<!-- Share -->
<partial name="Shared/share" model="Model"/>
<partial name="Shared/share" model="Model" />

<!-- Related Post -->
{% include related-posts.html %}
Expand All @@ -72,11 +71,21 @@ https://search.google.com/structured-data/testing-tool/u/0/
"type": "Person",
"name": "@author.Name"
},
"datePublished": "@Model.PostDate.Value.ToString("yyyy-MM-dd")",
"datePublished": "@Model.PostDate?.ToString("yyyy-MM-dd")",
"reviewRating": {
"type": "Rating",
"ratingValue": "@Model.Rating",
"bestRating": "5"
}
}
</script>}
</script>}
@section footerScripts{
@if (Model.Comments())
{
if (string.IsNullOrWhiteSpace(site.DisqussId))
{
throw new InvalidOperationException("Please configure the DisqussId in the site setting before enabling comments.");
}
<script id="dsq-count-scr" src="//@(site.DisqussId).disqus.com/count.js"></script>
}
}

0 comments on commit c1716b1

Please sign in to comment.