예제 #1
0
 /// <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();
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
 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();
예제 #5
0
 /// <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;