ssg: StaticSitePage, StaticSiteClient: ResolveParent impl, resolve page parent on GetPage

This commit is contained in:
Nick Vella 2019-07-20 00:43:21 +10:00
parent 923acc40ad
commit 9ee13c5a59
2 changed files with 27 additions and 2 deletions

View File

@ -224,8 +224,12 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
}
public BlogPost GetPage(string blogId, string pageId) =>
StaticSitePage.GetPageById(Config, pageId).BlogPost;
public BlogPost GetPage(string blogId, string pageId)
{
var page = StaticSitePage.GetPageById(Config, pageId);
page.ResolveParent();
return page.BlogPost;
}
public PageInfo[] GetPageList(string blogId) =>
StaticSitePage.GetAllPages(Config).Select(page => page.PageInfo).ToArray();

View File

@ -84,6 +84,27 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
GetFileNameForProvidedSlug(slug));
}
public StaticSitePage ResolveParent()
{
if(!BlogPost.PageParent.IsEmpty)
{
// Attempt to locate and load parent
var parent = GetPageById(SiteConfig, BlogPost.PageParent.Id);
if (parent == null)
{
// Parent not found, set PageParent to empty
BlogPost.PageParent = PostIdAndNameField.Empty;
}
else
{
// Populate Name field
BlogPost.PageParent = new PostIdAndNameField(parent.Id, parent.BlogPost.Title);
}
return parent;
}
return null;
}
/// <summary>
/// Load published page from a specified file path
/// </summary>