Skip to content

Commit

Permalink
Author box
Browse files Browse the repository at this point in the history
  • Loading branch information
alanta committed Nov 18, 2020
1 parent 96779eb commit 5b9a19d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 25 deletions.
25 changes: 22 additions & 3 deletions Models/ContentTypes/Author.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Author
{
public string Gravatar => CreateMD5(Email);

private static string CreateMD5(string input)
{
// Use input string to calculate MD5 hash
using (MD5 md5 = MD5.Create())
{
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);

// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
}
}
}
2 changes: 1 addition & 1 deletion Pipelines/Posts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Posts(IDeliveryClient deliveryClient, SiteSettings site)
InputModules = new ModuleList{
new Kontent<Post>(deliveryClient)
.OrderBy(Post.PostDateCodename, SortOrder.Descending)
.WithQuery(new DepthParameter(1), new IncludeTotalCountParameter()),
.WithQuery(new DepthParameter(2), new IncludeTotalCountParameter()),
new SetMetadata(nameof(Post.Tags),
KontentConfig.Get<Post,string[]>(post => post.Tags?.Select(t => t.Codename).ToArray())),
new SetDestination(KontentConfig.Get((Post post) => new NormalizedPath(post.Url))),
Expand Down
2 changes: 1 addition & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"Favicon": "assets/images/logo.png",
"Copyright": "Memoirs",
"lazyimages": false,
"authorbox": false
"authorbox": true
}
}
37 changes: 37 additions & 0 deletions input/Shared/author-box.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@using Kentico.Kontent.ImageTransformation
@using Kentico.Kontent.Statiq.Memoirs.Models
@using MemoirsTheme.Helpers
@model Kentico.Kontent.Statiq.Memoirs.Models.Author
@{
var site = ViewData["SiteMetaData"] as SiteSettings;
}
<!-- Author Box -->
@if( Model != null && site.AuthorBox){
<div class="d-flex authorbox align-items-center">
<div class="col-md-2 mr-4 text-center">
@if (Model?.AvatarImage != null)
{
@Html.Image(Model.AvatarImage, Model.Name, site.LazyImages, 580, 400, ImageFitMode.Crop, new { @class = "img-thumb" })
}
else
{
<img class="author-thumb" src="https://www.gravatar.com/avatar/@Model.Gravatar?s=250&d=mm&r=x" alt="@Model.Name">
}
</div>
<div class="col-md-10">
@foreach (var contact in Model.Contacts.OfType<Contact>())
{
@if (contact.Icon == "web")
{
<a target="_blank" class="text-dark h4" href="@contact.Url">About @Model.Name</a>
}
else
{
<a target="_blank" href="@contact.Url" class="btn-sm"><i class="fab [email protected]"></i></a>
}
}

<span class="author-description d-block mt-2">@Model.Bio</span>
</div>
</div>
}
18 changes: 0 additions & 18 deletions input/Shared/author-box.html

This file was deleted.

2 changes: 1 addition & 1 deletion input/Shared/postbox.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
else
{
@*<img class="author-thumb" src="https://www.gravatar.com/avatar/{{ author.gravatar }}?s=250&d=mm&r=x" alt="{{ author.display_name }}">*@
<img class="author-thumb" src="https://www.gravatar.com/avatar/@author.Gravatar?s=250&d=mm&r=x" alt="@author.Name">
}
</span>
<span class="author-meta">
Expand Down
2 changes: 1 addition & 1 deletion input/post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</div>}

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

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

0 comments on commit 5b9a19d

Please sign in to comment.