ssg: StaticSiteClient: tidy post front matter class and generation logic

This commit is contained in:
Nick Vella 2019-07-02 18:39:41 +10:00
parent d692a2862d
commit 7bcaec39d8
1 changed files with 31 additions and 12 deletions

View File

@ -193,24 +193,43 @@ namespace OpenLiveWriter.BlogClient.Clients
/// </summary> /// </summary>
/// <param name="post">Post to generate front matter for</param> /// <param name="post">Post to generate front matter for</param>
/// <returns></returns> /// <returns></returns>
private PostFrontMatter GetFrontMatterForPost(BlogPost post) => private PostFrontMatter GetFrontMatterForPost(BlogPost post)
new PostFrontMatter()
{ {
title = post.Title, var frontMatter = new PostFrontMatter()
author = post.Author.Name, {
date = post.DatePublished.ToString("yyyy-MM-dd HH:mm:ss"), Title = post.Title,
categories = post.Categories.Select(cat => cat.Name).ToArray(), Categories = post.Categories.Select(cat => cat.Name).ToArray(),
tags = post.Keywords Tags = post.Keywords
}; };
if (post.Author != null) frontMatter.Author = post.Author.Name;
if (post.DatePublished != new DateTime()) frontMatter.Date = post.DatePublished.ToString("yyyy-MM-dd HH:mm:ss");
return frontMatter;
}
private class PostFrontMatter private class PostFrontMatter
{ {
public string title { get; set; } [YamlMember(Alias = "title")]
public string author { get; set; } public string Title { get; set; }
public string date { get; set; }
public string[] categories { get; set; } [YamlMember(Alias = "author")]
public string tags { get; set; } public string Author { get; set; }
[YamlMember(Alias = "date")]
public string Date { get; set; }
[YamlMember(Alias = "layout")]
public string Layout { get; set; } = "post";
[YamlMember(Alias = "categories")]
public string[] Categories { get; set; }
[YamlMember(Alias = "tags")]
public string Tags { get; set; }
public string Serialize() => (new Serializer().Serialize(this));
public static PostFrontMatter Deserialize(string yaml) => (new Deserializer().Deserialize<PostFrontMatter>(yaml));
} }
} }
} }