/// <summary> /// Returns recent posts /// </summary> /// <param name="blogId"></param> /// <param name="maxPosts"></param> /// <param name="includeCategories"></param> /// <param name="now">If null, then includes future posts. If non-null, then only includes posts before the *UTC* 'now' time.</param> /// <returns></returns> public BlogPost[] GetRecentPosts(string blogId, int maxPosts, bool includeCategories, DateTime?now) => StaticSitePost.GetAllPosts(Config, true) .Select(post => post.BlogPost) .Where(post => post != null && (now == null || post.DatePublished < now)) .OrderByDescending(post => post.DatePublished) .Take(maxPosts) .ToArray();
public bool EditPost(string blogId, BlogPost post, INewCategoryContext newCategoryContext, bool publish, out string etag, out XmlDocument remotePost) { if (!publish && !Options.SupportsPostAsDraft) { Trace.Fail("Static site does not support drafts, cannot post."); throw new BlogClientPostAsDraftUnsupportedException(); } remotePost = null; etag = ""; // Create a StaticSitePost on the provided post var ssgPost = new StaticSitePost(Config, post, !publish); if (ssgPost.FilePathById == null) { // If we are publishing and there exists a draft with this ID, delete it. if (publish) { var filePath = new StaticSitePost(Config, post, true).FilePathById; if (filePath != null) { File.Delete(filePath); } } // Existing post could not be found to edit, call NewPost instead; NewPost(blogId, post, newCategoryContext, publish, out etag, out remotePost); return(true); } // Set slug to existing slug on post ssgPost.Slug = post.Slug; return(DoEditItem(ssgPost)); }
public void DeletePost(string blogId, string postId, bool publish) { var post = StaticSitePost.GetPostById(Config, postId); if (post == null) { throw new BlogClientException( Res.Get(StringId.SSGErrorPostDoesNotExistTitle), Res.Get(StringId.SSGErrorPostDoesNotExistText)); } DoDeleteItem(post); }
public BlogPostCategory[] GetCategories(string blogId) => StaticSitePost.GetAllPosts(Config, false) .SelectMany(post => post.BlogPost.Categories.Select(cat => cat.Name)) .Distinct() .Select(cat => new BlogPostCategory(cat)) .ToArray();
/// <summary> /// Attempt to get a post with the specified id (note: may return null /// if the post could not be found on the remote server) /// </summary> public BlogPost GetPost(string blogId, string postId) => StaticSitePost.GetPostById(Config, postId).BlogPost;