private static string GetPostAuthor(GhostData ghostData, GhostPost post) { return(ghostData.data.users.FirstOrDefault(u => u.id == post.created_by).name); }
private void ConvertPosts() { foreach (BlogMLPost post in BlogToConvert.Posts) { Console.WriteLine(post.Title); int postauthorId = AssignAllToOneUser ? OneUserId : GetNewUserIdForPostAuthor(post.Authors[0]); var newPost = new GhostPost { id = ghostDoc.data.posts.Count + 1, title = post.Title, slug = post.Title.AsSlug(GhostConstants.maxSlugLength), html = post.Content.Text, page = (post.PostType == BlogPostTypes.Article), status = post.IsPublished ? GhostPostStatus.published : GhostPostStatus.draft, locale = new CultureInfo("en-GB"), visibility = GhostVisibility.@public, author_id = postauthorId, created_at = post.DateCreated, created_by = postauthorId, updated_at = post.DateModified, updated_by = postauthorId, published_at = post.DateCreated, published_by = postauthorId }; ghostDoc.data.posts.Add(newPost); foreach (BlogMLCategoryReference catref in post.Categories) { ghostDoc.data.posts_tags.Add( new GhostPostHasTag { post_id = newPost.id, tag_id = ghostDoc.data.tags .Where(tag => tag.BlogMLid == catref.Ref) .FirstOrDefault().id, sort_order = 0 } ); } if (AssignAllToOneUser) { ghostDoc.data.posts_authors.Add( new GhostPostHasAuthor { post_id = newPost.id, author_id = OneUserId, sort_order = 0 } ); } else { foreach (BlogMLAuthorReference author in post.Authors) { ghostDoc.data.posts_authors.Add( new GhostPostHasAuthor { post_id = newPost.id, author_id = GetNewUserIdForPostAuthor(author), sort_order = 0 } ); } } } }
private static IEnumerable <string> GetPostCategories(GhostData ghostData, GhostPost post) { var postCategoryIds = ghostData.data.posts_tags.Where(t => t.post_id == post.id).Select(c => c.tag_id).ToList(); return(postCategoryIds.Select(id => ghostData.data.tags.FirstOrDefault(t => t.id == id).name).ToArray()); }