private void AddBlogPosts(IContent archiveNode, BlogMLDocument blogMlDoc, string tagGroup)
        {
            const int pageSize  = 1000;
            var       pageIndex = 0;

            IContent[] posts;
            do
            {
                long total;
                posts = _applicationContext.Services.ContentService.GetPagedChildren(archiveNode.Id, pageIndex, pageSize, out total, "createDate").ToArray();

                foreach (var child in posts)
                {
                    string content = "";
                    if (child.ContentType.Alias.InvariantEquals("ArticulateRichText"))
                    {
                        //TODO: this would also need to export all macros
                        content = child.GetValue <string>("richText");
                    }
                    else if (child.ContentType.Alias.InvariantEquals("ArticulateMarkdown"))
                    {
                        content = child.GetValue <string>("markdown");
                        var markdown = new MarkdownDeep.Markdown();
                        content = markdown.Transform(content);
                    }

                    var blogMlPost = new BlogMLPost()
                    {
                        Id             = child.Key.ToString(),
                        Name           = new BlogMLTextConstruct(child.Name),
                        Title          = new BlogMLTextConstruct(child.Name),
                        ApprovalStatus = BlogMLApprovalStatus.Approved,
                        PostType       = BlogMLPostType.Normal,
                        CreatedOn      = child.CreateDate,
                        LastModifiedOn = child.UpdateDate,
                        Content        = new BlogMLTextConstruct(content, BlogMLContentType.Html),
                        Excerpt        = new BlogMLTextConstruct(child.GetValue <string>("excerpt")),
                        Url            = new Uri(_umbracoContext.UrlProvider.GetUrl(child.Id), UriKind.RelativeOrAbsolute)
                    };

                    var author = blogMlDoc.Authors.FirstOrDefault(x => x.Title != null && x.Title.Content.InvariantEquals(child.GetValue <string>("author")));
                    if (author != null)
                    {
                        blogMlPost.Authors.Add(author.Id);
                    }

                    var categories = _applicationContext.Services.TagService.GetTagsForEntity(child.Id, tagGroup);
                    foreach (var category in categories)
                    {
                        blogMlPost.Categories.Add(category.Id.ToString());
                    }

                    //TODO: Tags isn't natively supported

                    blogMlDoc.AddPost(blogMlPost);
                }

                pageIndex++;
            } while (posts.Length == pageSize);
        }
예제 #2
0
        private void AddBlogPosts(IContent archiveNode, BlogMLDocument blogMlDoc, string categoryGroup, string tagGroup)
        {
            const int pageSize  = 1000;
            var       pageIndex = 0;

            IContent[] posts;
            do
            {
                posts = _contentService.GetPagedChildren(archiveNode.Id, pageIndex, pageSize, out long _, ordering: Ordering.By("createDate")).ToArray();

                foreach (var child in posts)
                {
                    string content = "";
                    if (child.ContentType.Alias.InvariantEquals("ArticulateRichText"))
                    {
                        //TODO: this would also need to export all macros
                        content = child.GetValue <string>("richText");
                    }
                    else if (child.ContentType.Alias.InvariantEquals("ArticulateMarkdown"))
                    {
                        var md = new Markdown();
                        content = md.Transform(child.GetValue <string>("markdown"));
                    }

                    var postUrl         = new Uri(_umbracoContextAccessor.UmbracoContext.UrlProvider.GetUrl(child.Id), UriKind.RelativeOrAbsolute);
                    var postAbsoluteUrl = new Uri(_umbracoContextAccessor.UmbracoContext.UrlProvider.GetUrl(child.Id, UrlProviderMode.Absolute), UriKind.Absolute);
                    var blogMlPost      = new BlogMLPost()
                    {
                        Id             = child.Key.ToString(),
                        Name           = new BlogMLTextConstruct(child.Name),
                        Title          = new BlogMLTextConstruct(child.Name),
                        ApprovalStatus = BlogMLApprovalStatus.Approved,
                        PostType       = BlogMLPostType.Normal,
                        CreatedOn      = child.CreateDate,
                        LastModifiedOn = child.UpdateDate,
                        Content        = new BlogMLTextConstruct(content, BlogMLContentType.Html),
                        Excerpt        = new BlogMLTextConstruct(child.GetValue <string>("excerpt")),
                        Url            = postUrl
                    };

                    var author = blogMlDoc.Authors.FirstOrDefault(x => x.Title != null && x.Title.Content.InvariantEquals(child.GetValue <string>("author")));
                    if (author != null)
                    {
                        blogMlPost.Authors.Add(author.Id);
                    }

                    var categories = _tagService.GetTagsForEntity(child.Id, categoryGroup);

                    foreach (var category in categories)
                    {
                        blogMlPost.Categories.Add(category.Id.ToString());
                    }

                    var tags = _tagService.GetTagsForEntity(child.Id, tagGroup).Select(t => t.Text).ToList();
                    if (tags?.Any() == true)
                    {
                        blogMlPost.AddExtension(
                            new Syndication.BlogML.TagsSyndicationExtension()
                        {
                            Context = { Tags = new Collection <string>(tags) }
                        });
                    }

                    //add the image attached if there is one
                    if (child.HasProperty("postImage"))
                    {
                        try
                        {
                            var val  = child.GetValue <string>("postImage");
                            var json = JsonConvert.DeserializeObject <JObject>(val);
                            var src  = json.Value <string>("src");

                            var mime = ImageMimeType(src);

                            if (!mime.IsNullOrWhiteSpace())
                            {
                                var imageUrl = new Uri(postAbsoluteUrl.GetLeftPart(UriPartial.Authority) + src.EnsureStartsWith('/'), UriKind.Absolute);
                                blogMlPost.Attachments.Add(new BlogMLAttachment
                                {
                                    Content     = string.Empty, //this is used for embedded resources
                                    Url         = imageUrl,
                                    ExternalUri = imageUrl,
                                    IsEmbedded  = false,
                                    MimeType    = mime
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error <BlogMlExporter>(ex, "Could not add the file to the blogML post attachments");
                        }
                    }



                    blogMlDoc.AddPost(blogMlPost);
                }

                pageIndex++;
            } while (posts.Length == pageSize);
        }