Пример #1
0
        private Post PostFromMarkdown(string markdown)
        {
            var rx = new Regex(@"^---(?<metadata>.*)---(?<content>.*)$",
                               RegexOptions.Singleline);
            Match ts = rx.Match(markdown);

            var metadata           = ts.Groups["metadata"].Value.Trim();
            var content            = ts.Groups["content"].Value.Trim();
            var result             = _markdownConverter.Convert(content);
            var metadataDictionary = GetMetadataDictionary(metadata);


            var publishDate = !string.IsNullOrEmpty(metadataDictionary.GetValueOrDefault("date"))
                ? DateTime.Parse(metadataDictionary.GetValueOrDefault("date"))
                : DateTime.Now;

            return(new Post
            {
                Content = result,
                Tags = metadataDictionary.GetValueOrDefault("tags").Split(" "),
                Title = metadataDictionary.GetValueOrDefault("title"),
                Excerpt = metadataDictionary.GetValueOrDefault("excerpt"),
                Slug = metadataDictionary.GetValueOrDefault("slug"),
                Image = metadataDictionary.GetValueOrDefault("image"),
                PublishDate = publishDate
            });
        }
Пример #2
0
        public Post Get(string path)
        {
            var markdownBody = gitRepository.Get(path);

            var htmlBody = converter.Convert(markdownBody);

            return(new Post {
                Body = htmlBody
            });
        }
    public object Execute(IFileSystemObject input)
    {
        var fileContents = markdownFileParser.ReadFile(input.FullPath);

        var htmlFile = markdownConverter.Convert(fileContents);

        htmlFile.HtmlContent = templateFiller.FillSiteTemplate(htmlFile.HtmlContent);

        var inputRoot = fileSystem.Path.GetFullPath(options.PathToMarkdownFiles);

        var fileRelativeInputRoot = fileSystem.Path.GetRelativePath(inputRoot, input.FullPath);
        var outputFilePath        = fileSystem.Path.Combine(options.OutputLocation, fileRelativeInputRoot).Replace(".md", ".html");

        fileWriter.Write(outputFilePath, htmlFile.HtmlContent);

        return(null);
    }