Esempio n. 1
0
 public async Task <BlogPostDocument> ProcessPostAsync(string Name)
 {
     return(new BlogPostDocument()
     {
         Html = await HttpClient.GetStringAsync($"/Blog/Site/{Name}.html"),
         Yaml = YamlTools
                .DeserializeYaml(await HttpClient.GetStringAsync($"Blog/Site/{Name}.yml"))
     });
 }
Esempio n. 2
0
        public IEnumerable <BlogPostDocument> CompileMarkdown(string Root)
        {
            var PostDirectory = Path.Combine(Root, "Posts");

            //Grab Markdown files
            var Paths = Directory.GetFiles(PostDirectory, "*.md");

            if (Paths.Length == 0)
            {
                Console.WriteLine($"No posts found in {PostDirectory}!");

                Environment.Exit(0);
            }

            List <BlogPostDocument> Docs = new List <BlogPostDocument>();

            using (StringWriter stringWriter = new StringWriter())
            {
                HtmlRenderer htmlRenderer = new HtmlRenderer(stringWriter);
                MarkdownPipeline.Setup(htmlRenderer);

                foreach (var Path in Paths)
                {
                    var markdown = File.ReadAllText(Path);

                    MarkdownDocument Document = Markdown.Parse(markdown, MarkdownPipeline);

                    //Get yaml metadata
                    var yamlBlock = Document.Descendants <YamlFrontMatterBlock>().FirstOrDefault();

                    if (yamlBlock == null)
                    {
                        throw new Exception($"File with path {Path} has no Yaml metadata!");
                    }

                    string yaml = markdown.Substring(yamlBlock.Span.Start, yamlBlock.Span.Length);

                    YamlMetadata yamlMetadata = YamlTools.DeserializeYaml(yaml);

                    htmlRenderer.Render(Document);
                    stringWriter.Flush();

                    string FileName = Path.Substring(Path.LastIndexOf('\\') + 1);
                    FileName = FileName.Remove(FileName.LastIndexOf('.'));

                    yamlMetadata.FileName = FileName;

                    Docs.Add(new BlogPostDocument {
                        Yaml = yamlMetadata, Markdown = stringWriter.ToString()
                    });
                }
            }

            return(Docs);
        }
Esempio n. 3
0
 public async Task <YamlMetadata> ProcessPostMetadataAsync(string Name)
 {
     return(YamlTools
            .DeserializeYaml(await HttpClient.GetStringAsync($"/Blog/Site/{Name}.yml")));
 }