Cake.Web.Core.Content.Blog.BlogReader.Parse C# (CSharp) Метод

Parse() публичный Метод

public Parse ( DirectoryPath path ) : BlogIndex
path DirectoryPath
Результат BlogIndex
        public BlogIndex Parse(DirectoryPath path)
        {
            var directory = _fileSystem.GetDirectory(path);
            if (!directory.Exists)
            {
                return new BlogIndex(Enumerable.Empty<BlogPost>());
            }

            var posts = new List<BlogPost>();
            var files = directory.GetFiles("*", SearchScope.Current);
            foreach (var file in files)
            {
                var filename = BlogFilename.Parse(file.Path);
                if (filename != null)
                {
                    // Read the file.
                    var content = _parser.Parse(file.Path);
                    if (!content.FrontMatter.ContainsKey("content-type"))
                    {
                        content.FrontMatter.Add("content-type", "markdown");
                    }

                    // Process the content.
                    var body = _processor.PreProcess(content.Body);
                    body = _converter.ConvertToHtml(content, body);
                    body = _processor.PostProcess(body) ?? body;

                    // Get the excerpts.
                    var excerpts = _converter.ConvertToHtml(content, content.Excerpt);

                    // Rewrite the feed body.
                    // This is kind of a hack, but we need to make sure that all links are absolute.
                    var feedBody = RewriteRelativeLinks(body);

                    var author = content.GetFrontMatter("author");

                    // Add the blog post.
                    posts.Add(new BlogPost(filename.Slug,
                        content.GetFrontMatter("title"), body, feedBody, excerpts, filename.PostedAt,
                        GetCategories(content), author == null ? "Cake Team" : author));
                }
            }

            // Hack. Don't judge me... :)
            var maxDate = posts.Max(x => x.PostedAt);
            var lastPost = posts.FirstOrDefault(x => x.PostedAt == maxDate);
            if (lastPost != null)
            {
                lastPost.IsLatest = true;
            }

            return new BlogIndex(posts);
        }