Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(string?postTitle)
        {
            if (postTitle == null)
            {
                return(NotFound());
            }

            var filePath = $"Content/Blogs/{postTitle}.md";

            if (!System.IO.File.Exists(filePath))
            {
                return(RedirectToPage("Error404"));
            }

            var markdownFile = await System.IO.File.ReadAllTextAsync(filePath);

            var post = new MarkDownDocBuilder <BlogPost>(markdownFile)
                       .WithYamlData()
                       .WithContent()
                       .Build();

            Blog = post.YamlData;

            if (Blog == null)
            {
                return(RedirectToPage("Error404"));
            }

            Blog.Content = post.Document;

            return(Page());
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <BlogPost> > GetBlogPostsAsync()
        {
            var files = Directory.GetFiles("Content/Blogs", "*.md");

            var blogList = new List <BlogPost>();

            // loop through all of the markdown files in the blogs folder and add to
            foreach (var file in files)
            {
                var markdownFile = await File.ReadAllTextAsync(file);

                var docBuilder = new MarkDownDocBuilder <BlogPost>(markdownFile)
                                 .WithYamlData()
                                 .Build();

                if (docBuilder.YamlData is not null)
                {
                    blogList.Add(docBuilder.YamlData);
                }
            }

            return(blogList);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync()
        {
            var filePath = $"Content/Personal/AboutMe.md";

            if (!System.IO.File.Exists(filePath))
            {
                return(RedirectToPage("Error404"));
            }

            var markdownFile = await System.IO.File.ReadAllTextAsync(filePath);

            var post = new MarkDownDocBuilder <string>(markdownFile)
                       .WithContent()
                       .Build();

            AboutContent = post.Document;

            if (AboutContent == null)
            {
                return(RedirectToPage("Error404"));
            }

            return(Page());
        }