public void WhenParsingValidEntry_AssertPublishedDate()
        {
            BlogPostParser parser = new BlogPostParser(_config);
            BlogPostEntry  result = parser.ParseFromMarkdown(ValidPost);

            Assert.Equal(new DateTime(2017, 1, 16, 0, 0, 0), result.ReleaseDate);
        }
        public void WhenParsingValidEntry_AssertTitle()
        {
            BlogPostParser parser = new BlogPostParser(_config);
            BlogPostEntry  result = parser.ParseFromMarkdown(ValidPost);

            Assert.Equal("Starting This Blog", result.Title);
        }
        public void WhenParsingValidEntry_AssertFirstParagraph()
        {
            _config.SiteContentUrl.Returns("https://MyLink.com");

            BlogPostParser parser = new BlogPostParser(_config);
            BlogPostEntry  result = parser.ParseFromMarkdown(ValidPost);

            Assert.Equal("Everything else goes here and should be found", result.FirstParagraph);
        }
        public void WhenParsingValidEntry_AssertContent()
        {
            _config.SiteContentUrl.Returns("https://MyLink.com");

            BlogPostParser parser = new BlogPostParser(_config);
            BlogPostEntry  result = parser.ParseFromMarkdown(ValidPost);

            Assert.Equal("### The Post!!!" + Environment.NewLine +
                         "Everything else goes here and should be found" + Environment.NewLine
                         + "https://MyLink.com/a/b/c.html" + Environment.NewLine
                         + "https://MyLink.com/1/2/3.html"
                         , result.Post);
        }
Exemple #5
0
        public static ImmutableList <BlogPostInfo> LoadAllBlogPostInfo(string contentPath, BlogPostParser parser)
        {
            string blogPostsFolderPath = contentPath + "/BlogPosts";

            string[] blogPostFiles = Directory.GetFiles(blogPostsFolderPath, "*.md", SearchOption.TopDirectoryOnly);
            return(blogPostFiles.Select(x =>
            {
                string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(x);
                string postContent = File.ReadAllText(x);
                BlogPostEntry blogEntry = parser.ParseFromMarkdown(postContent);
                return new BlogPostInfo(fileNameWithoutExtension, blogEntry);
            })
                   .ToImmutableList());
        }
        public void WhenParsingValidEntry_AssertTags()
        {
            BlogPostParser parser = new BlogPostParser(_config);
            BlogPostEntry  result = parser.ParseFromMarkdown(ValidPost);

            Assert.Equal(7, result.Tags.Count);
            Assert.Contains("Wyam", result.Tags);
            Assert.Contains("Azure App Service", result.Tags);
            Assert.Contains("VSTS", result.Tags);
            Assert.Contains("Cake", result.Tags);
            Assert.Contains("NuGet", result.Tags);
            Assert.Contains("Continuous Integration", result.Tags);
            Assert.Contains("Continuous Deployment", result.Tags);
        }
        public BlogPostEntryTests()
        {
            _subject = new BlogPostEntry()
            {
                Title = "Title",
                Slug  = "slug",
                Body  = new Document(),
                Sys   = new SystemProperties
                {
                    CreatedAt = new DateTime(2021, 1, 1)
                }
            };

            _htmlConverter = Mock.Of <IHtmlConverter>(m =>
                                                      m.ConvertDocumentToHtmlAsync(It.IsAny <Document>()) == Task.FromResult("<p>Hello</p>"));
        }
Exemple #8
0
        static async Task Main(string[] args)
        {
            Options parsedArgs = null;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(opts => parsedArgs = opts)
            .WithNotParsed((errs) =>
            {
                Console.WriteLine(errs);
                return;
            });

            HardCodedConfig config = new HardCodedConfig();
            BlogPostParser  parser = new BlogPostParser(config);

            var contentPath = parsedArgs.AppRootPath + "/ProgrammerAl.Site.Content";

            ImmutableList <BlogPostInfo> allPosts = LoadAllBlogPostInfo(contentPath, parser);

            ImmutableList <BlogPostInfo> parsedBlogEntries = allPosts
                                                             .OrderBy(x => x.FileNameWithoutExtension)//All blog posts start with a number. So the higher the number, the newer the post
                                                             .ToImmutableList();

            int blogPostNumber = 1;

            BlogPostSummary[] allBlogPostSummaries = parsedBlogEntries.Select(x => new BlogPostSummary
            {
                Title          = x.Entry.Title,
                PostedDate     = x.Entry.ReleaseDate,
                FirstParagraph = x.Entry.FirstParagraph,
                PostNumber     = blogPostNumber++,
                TitleLink      = x.FileNameWithoutExtension,
            }).ToArray();

            BlogPostSummary[] mostRecentBlogPosts = allBlogPostSummaries
                                                    .OrderByDescending(x => x.PostNumber)
                                                    .Take(FrontPageBlogsDisplayed)
                                                    .ToArray();

            RecentData recentData = new RecentData {
                RecentBlogPosts = mostRecentBlogPosts
            };

            WriteOutFileAsJson(recentData, contentPath, RecentDataFile);
            WriteOutFileAsJson(allBlogPostSummaries, contentPath, BlogPostsFile);

            //Load up the static templating engine
            var fullPathToTemplates = Path.Combine(Environment.CurrentDirectory, "StaticTemplates");
            var engine = new RazorLightEngineBuilder()
                         .UseFilesystemProject(fullPathToTemplates)
                         .UseMemoryCachingProvider()
                         .Build();

            string outputfolderPath = Path.Combine(contentPath, "BlogPosts");

            if (!Directory.Exists(outputfolderPath))
            {
                Directory.CreateDirectory(outputfolderPath);
            }

            //Create static html files for each blog post entry
            foreach (BlogPostInfo blogEntry in parsedBlogEntries)
            {
                var htmlContent           = Markdig.Markdown.ToHtml(blogEntry.Entry.Post);
                var blogPostEntryWithHtml = new BlogPostEntry(blogEntry.Entry.Title, blogEntry.Entry.ReleaseDate, blogEntry.Entry.Tags, htmlContent, blogEntry.Entry.FirstParagraph);

                string staticHtml = await engine.CompileRenderAsync <BlogPostEntry>("BlogPost.cshtml", blogPostEntryWithHtml);

                string outputFilePath = Path.Combine(outputfolderPath, blogEntry.FileNameWithoutExtension) + ".html";
                File.WriteAllText(outputFilePath, staticHtml);
            }

            var sitemapFilePath = parsedArgs.AppRootPath + "/ProgrammerAl.Site/ProgrammerAl.Site/wwwroot/sitemap.xml";
            var sitemapText     = GenerateSitemapFile("https://www.programmeral.com/", allPosts);

            File.WriteAllText(sitemapFilePath, sitemapText);
        }
 public BlogPostInfo(string fileNameWithoutExtension, BlogPostEntry entry)
 {
     FileNameWithoutExtension = fileNameWithoutExtension;
     Entry = entry;
 }