ssg: StaticSiteClient: tidy post front matter class and generation logic
This commit is contained in:
parent
d692a2862d
commit
7bcaec39d8
|
@ -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()
|
{
|
||||||
|
var frontMatter = new PostFrontMatter()
|
||||||
{
|
{
|
||||||
title = post.Title,
|
Title = post.Title,
|
||||||
author = post.Author.Name,
|
Categories = post.Categories.Select(cat => cat.Name).ToArray(),
|
||||||
date = post.DatePublished.ToString("yyyy-MM-dd HH:mm:ss"),
|
Tags = post.Keywords
|
||||||
categories = post.Categories.Select(cat => cat.Name).ToArray(),
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue