Skip to content

Commit

Permalink
Quotes & Spoilers
Browse files Browse the repository at this point in the history
+ fix for code snippets
  • Loading branch information
alanta committed Nov 20, 2020
1 parent 0e05b1f commit dcd64bd
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 45 deletions.
4 changes: 3 additions & 1 deletion Models/ContentTypes/CustomTypeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class CustomTypeProvider : ITypeProvider
{typeof(GithubGist), "github_gist"},
{typeof(Home), "home"},
{typeof(Page), "page"},
{typeof(Post), "post"}
{typeof(Post), "post"},
{typeof(Quote), "quote"},
{typeof(Spoiler), "spoiler"}
};

public Type GetType(string contentType)
Expand Down
23 changes: 23 additions & 0 deletions Models/ContentTypes/Quote.Generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This code was generated by a kontent-generators-net tool
// (see https://github.com/Kentico/kontent-generators-net).
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// For further modifications of the class, create a separate file with the partial class.

using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Quote
{
public const string Codename = "quote";
public const string AttributionCodename = "attribution";
public const string ContentCodename = "content";

public string Attribution { get; set; }
public string Content { get; set; }
public IContentItemSystemAttributes System { get; set; }
}
}
10 changes: 10 additions & 0 deletions Models/ContentTypes/Quote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Quote
{
}
}
21 changes: 21 additions & 0 deletions Models/ContentTypes/Spoiler.Generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This code was generated by a kontent-generators-net tool
// (see https://github.com/Kentico/kontent-generators-net).
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// For further modifications of the class, create a separate file with the partial class.

using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Spoiler
{
public const string Codename = "spoiler";
public const string ContentCodename = "content";

public string Content { get; set; }
public IContentItemSystemAttributes System { get; set; }
}
}
10 changes: 10 additions & 0 deletions Models/ContentTypes/Spoiler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Spoiler
{
}
}
2 changes: 2 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ await Bootstrapper
services.AddSingleton<ITypeProvider, CustomTypeProvider>();
services.AddDeliveryInlineContentItemsResolver(new CodeSnippetResolver());
services.AddDeliveryInlineContentItemsResolver(new GitHubGistResolver());
services.AddDeliveryInlineContentItemsResolver(new SpoilerResolver());
services.AddDeliveryInlineContentItemsResolver(new QuoteResolver());
services.AddDeliveryClient((IConfiguration)settings);
})
.AddHostingCommands()
Expand Down
3 changes: 2 additions & 1 deletion Resolvers/CodeSnippetResolver.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.Statiq.Memoirs.Models;
using System.Linq;
using System.Web;

namespace MemoirsTheme.Resolvers
{
public class CodeSnippetResolver : IInlineContentItemsResolver<CodeSnippet>
{
public string Resolve(CodeSnippet data)
{
return $"<pre><code class=\"language-{data.Language.First().Codename}\">{data.Code}</code></pre>";
return $"<pre><code class=\"language-{data.Language.First().Codename}\">{HttpUtility.HtmlEncode(data.Code)}</code></pre>";
}
}
}
36 changes: 36 additions & 0 deletions Resolvers/QuoteResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.Statiq.Memoirs.Models;
using System;

namespace MemoirsTheme.Resolvers
{
public class QuoteResolver : IInlineContentItemsResolver<Quote>
{
public string Resolve(Quote data)
{
string attribution = "";
if (!string.IsNullOrWhiteSpace(data.Attribution))
{
attribution = $" ⸺ <cite>{data.Attribution}</cite>";
}

return $"<blockquote><p>&ldquo;{ TrimParagraph(data.Content)}&rdquo;{attribution}</p></blockquote>";
}

private static string TrimParagraph(string content)
{
var result = content.Trim();
if (content.StartsWith("<p>", StringComparison.OrdinalIgnoreCase))
{
result = result.Substring(3);
}
if (content.EndsWith("</p>", StringComparison.OrdinalIgnoreCase))
{
result = result.Substring(0, result.Length-4);
}

return result;
}

}
}
13 changes: 13 additions & 0 deletions Resolvers/SpoilerResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.Statiq.Memoirs.Models;

namespace MemoirsTheme.Resolvers
{
public class SpoilerResolver : IInlineContentItemsResolver<Spoiler>
{
public string Resolve(Spoiler data)
{
return $"<div class=\"spoiler\">{data.Content}</div>";
}
}
}
13 changes: 0 additions & 13 deletions input/_pages/about.md

This file was deleted.

5 changes: 0 additions & 5 deletions input/_pages/categories.md

This file was deleted.

20 changes: 0 additions & 20 deletions input/_pages/contact.md

This file was deleted.

5 changes: 0 additions & 5 deletions input/_pages/tags.md

This file was deleted.

0 comments on commit dcd64bd

Please sign in to comment.