Skip to content

Commit

Permalink
Page titles and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alanta committed Nov 19, 2020
1 parent c1716b1 commit 2b84845
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 23 deletions.
6 changes: 6 additions & 0 deletions Helpers/HtmlHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.ImageTransformation;
using Kentico.Kontent.Statiq.Memoirs.Models;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
Expand All @@ -18,6 +19,11 @@ public static string GetLink(this IHtmlHelper html, string relativeUri, bool inc
return context.GetLink(relativeUri, includeHost);
}

public static SiteSettings Site(this IHtmlHelper html)
{
return html.ViewData["SiteMetaData"] as SiteSettings;
}

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
2 changes: 1 addition & 1 deletion Models/SiteSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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; }
public string DisqusId { get; set; }
}
}
1 change: 1 addition & 0 deletions Pipelines/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Home(SiteSettings site)
new SetDestination(Config.FromDocument((doc, ctx) => Filename(doc))),
new MergeContent(new ReadFiles(patterns: "Index.cshtml")),
new RenderRazor()
.WithViewData("Title", "Home")
.WithViewData("SiteMetaData", site)
.WithModel(Config.FromDocument((document, context) => new PagedContent<Post>(document, PagingUrl))),
new KontentImageProcessor()
Expand Down
1 change: 1 addition & 0 deletions Pipelines/Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Pages(IDeliveryClient deliveryClient, SiteSettings site)
{
new MergeContent(new ReadFiles(patterns: "Page.cshtml")),
new RenderRazor()
.WithViewData("Title", KontentConfig.Get<Page,string>( p => p.Title ))
.WithViewData("SiteMetadata", site)
.WithModel(KontentConfig.As<Page>()),
new KontentImageProcessor()
Expand Down
1 change: 1 addition & 0 deletions Pipelines/Posts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public Posts(IDeliveryClient deliveryClient, SiteSettings site)
ProcessModules = new ModuleList {
new MergeContent(new ReadFiles(patterns: "Post.cshtml") ),
new RenderRazor()
.WithViewData("Title", KontentConfig.Get<Post,string>( p => p.Title ))
.WithViewData("Author", KontentConfig.Get<Post,Author>( p => p.Author.OfType<Author>().FirstOrDefault() ))
.WithViewData("SiteMetadata", site )
.WithModel(KontentConfig.As<Post>()),
Expand Down
3 changes: 3 additions & 0 deletions input/404.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@{
ViewData["Title"] = "Not found";
}
<style>
.newsletter, .footer {
display:none;
Expand Down
5 changes: 2 additions & 3 deletions input/Shared/_featured-image.cshtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@using Kentico.Kontent.Delivery.Abstractions
@using Kentico.Kontent.Statiq.Memoirs.Models
@model IEnumerable<Kentico.Kontent.Delivery.Abstractions.IAsset>
@{
bool lazyImages = (ViewBag.SiteSettings as SiteSettings)?.LazyImages ?? false;
bool imageShadow = (ViewBag.SiteSettings as SiteSettings)?.ImageShadow ?? false;
bool lazyImages = Html.Site().LazyImages;
bool imageShadow = Html.Site().ImageShadow;
IAsset image = Model?.FirstOrDefault();
}
@if (image != null)
Expand Down
15 changes: 15 additions & 0 deletions input/Shared/comments.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@using Kentico.Kontent.Statiq.Memoirs.Models
@model Kentico.Kontent.Statiq.Memoirs.Models.IPageMetadata
<!-- Comments
================================================== -->
@if (Model.Comments() && !string.IsNullOrWhiteSpace(Html.Site().DisqusId))
{
<div class="comments">
<button class="btn btn-dark show-comments">Load Comments</button>
<div id="comments">
<h4 class="mb-4">Comments</h4>
<partial name="disqus" />
<div class="clearfix"></div>
</div>
</div>
}
12 changes: 0 additions & 12 deletions input/Shared/comments.html

This file was deleted.

2 changes: 1 addition & 1 deletion input/Shared/disqus.html → input/Shared/disqus.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section class="disqus">
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '{{site.disqus}}';
var disqus_shortname = '@(Html.Site().DisqusId)';
var disqus_developer = 0;
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
Expand Down
1 change: 0 additions & 1 deletion input/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using Kentico.Kontent.Statiq.Memoirs.Models
@using Statiq.Common
@{ var site = ViewBag.SiteMetadata as SiteSettings;
var author = ViewBag.Author as Author;
var name = author?.Name ?? "John Doe";
Expand Down
10 changes: 5 additions & 5 deletions input/post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else
</div>
<div>
Written by <span class="text-dark">@author.Name</span> on
<span class="post-date"><time class="post-date" datetime="@Model.PostDate?.ToString("dd-MM-yyyy")">@Html.DisplayFor(m => m.PostDate)</time></span>
<span class="post-date"><time class="post-date" datetime="@Model.PostDate?.ToString("dd-MM-yyyy")">@Model.PostDate?.ToString("d MMMM yyyy")</time></span>
</div>
</div>}
</div>
Expand All @@ -46,7 +46,7 @@ else
<partial name="Shared/author-box" model="author" />

<!-- Comments if not disabled with comments: false -->
{% include comments.html %}
<partial name="comments" model="Model"/>

<!-- Share -->
<partial name="Shared/share" model="Model" />
Expand Down Expand Up @@ -82,10 +82,10 @@ https://search.google.com/structured-data/testing-tool/u/0/
@section footerScripts{
@if (Model.Comments())
{
if (string.IsNullOrWhiteSpace(site.DisqussId))
if (string.IsNullOrWhiteSpace(site.DisqusId))
{
throw new InvalidOperationException("Please configure the DisqussId in the site setting before enabling comments.");
throw new InvalidOperationException("Please configure the DisqusId in the site setting before enabling comments.");
}
<script id="dsq-count-scr" src="//@(site.DisqussId).disqus.com/count.js"></script>
<script id="dsq-count-scr" src="//@(site.DisqusId).disqus.com/count.js"></script>
}
}

0 comments on commit 2b84845

Please sign in to comment.