public List <Post> GetPosts(string basePath)
        {
            var postList     = new List <Post>();
            var deserializer = new PostDeserializer();
            var files        = Directory.GetFiles(basePath, "*.yml").ToList();

            files.ForEach(file =>
            {
                var fileContent = GetFileContent(file);
                try
                {
                    var instance     = deserializer.Serialize(fileContent);
                    instance.PostUrl = UrlGenerator.UrlFriendly(Path.GetFileNameWithoutExtension(file));
                    postList.Add(instance);
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch (Exception)
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
            });
            return(postList);
        }
Esempio n. 2
0
        public static List <TagModel> GetBlogTags()
        {
            ILocator postLocator = new PostLocator();
            var      posts       = postLocator.GetPosts(PathProvider.GetPostsPath());
            var      allTags     = posts.SelectMany(p => p.Tags).ToList().Distinct();

            return(allTags.Select(t => new TagModel {
                TagText = t, TagSlug = string.Format("{0}/tag/{1}", Constants.BlogBasePath, UrlGenerator.UrlFriendly(t))
            }).ToList());
        }