public void SerializeYamlFromMetaTest() { var yaml = @"--- title: Using .NET Core Tools to Create Reusable and Shareable Tools & Apps featuredImageUrl: https://jekyll.west-wind.com/assets/2020-08-05-Using-NET-Core-Tools-to-Create-Reusable-and-Shareable-Tools-&-Apps/banner.png abstract: Dotnet Tools offer a simple way to create, publish and consume what are essentially .NET Core applications that can be published and shared using the existing NuGet infrastructure for packaging and distribution. It's y quick and easy to build tools that you can share either publicly or privately. In this article I make a case for why you might use or build a Dotnet Tool and show how create, build, publish and consume Dotnet tools as well as showing some examples of useful tools I've build and published. keywords: Dotnet Tool categories: .NET Core, ASP.NET Core weblogName: West Wind Web Log postId: 1900072 permalink: https://weblog.west-wind.com/posts/2020/Aug/05/Using-NET-Core-Tools-to-Create-Reusable-and-Shareable-Tools-Apps postDate: 2020-08-05T00:14:17.5009200-10:00 extraValue1: This value is an extra value extraValue2: ""This is:more than I frank's money bargained for"" customFields: mt_githuburl: key: mt_githuburl value: https://github.com/RickStrahl/BlogPosts/blob/master/2020-08/DotnetTools/DotnetTools.md ---"; var meta = WeblogPostMetadata.ParseFromYaml(yaml); Assert.IsNotNull(meta); Console.WriteLine(JsonSerializationUtils.Serialize(meta, false, true)); yaml = meta.SerializeToYaml(meta, true); Assert.IsNotNull(yaml); Assert.IsTrue(yaml.Contains("title: ")); Console.WriteLine(yaml); }
public LocalJekyllPublisher(WeblogPostMetadata postMetadata, WeblogInfo weblogInfo, string documentFilename) { PostMetadata = postMetadata; WeblogInfo = weblogInfo; DocumentFilename = documentFilename; }
public void GetPostYaml() { var weblogInfo = new WeblogInfo() { Name = "West Wind Web Log", ApiUrl = "https://weblog.west-wind.com/metaweblog.ashx", BlogId = "1", }; var post = new Post(); var meta = WeblogPostMetadata.GetPostYamlConfigFromMarkdown(STR_postWithMetaData, post); Console.WriteLine(meta.Title); Console.WriteLine(meta.Abstract); Console.WriteLine(meta.CustomFields.Count); }
public void SetConfigInMarkdown() { var meta = new WeblogPostMetadata() { Abstract = "THis is an abstract", Keywords = "Security,SSL,IIS", RawMarkdownBody = MarkdownWithoutPostId, PostId = "2", WeblogName = "Rick Strahl's Web Log" }; var addin = new WeblogAddin.WebLogAddin(); string markdown = addin.SetConfigInMarkdown(meta); Console.WriteLine(markdown); Assert.IsTrue(markdown.Contains("<postid>2</postid>"), "Post Id wasn't added"); }
public void PublishTest() { var webLogInfo = new WeblogInfo { ApiUrl = STR_JEKYLL_PROJECT_FOLDER, Name = "Jekyll Test Blog" }; var rawMd = System.IO.File.ReadAllText(STR_MM_POST_FILE_NAME); var post = new Post(); // filled from meta data but not used here var meta = WeblogPostMetadata.GetPostYamlConfigFromMarkdown(rawMd); var pub = new LocalJekyllPublisher(meta, webLogInfo, STR_MM_POST_FILE_NAME); pub.PublishPost(false); }
/// <summary> /// Retrieves Weblog Metadata and Post Data from a Jekyll post on disk /// </summary> /// <param name="jekyllPostFilename">Full path to a Jekyll post on disk</param> /// <returns></returns> private WeblogPostMetadata GetPostMetaDataFromFile(string jekyllPostFilename, Post post) { string content = null; try { content = File.ReadAllText(jekyllPostFilename); if (string.IsNullOrEmpty(content)) { return(null); } } catch { return(null); } var meta = WeblogPostMetadata.GetPostYamlConfigFromMarkdown(content, post); if (meta == null) { return(null); } string dateString = MarkdownUtilities.ExtractYamlValue(meta.YamlFrontMatter, "date"); DateTime date; if (!DateTime.TryParse(dateString, out date)) { dateString = jekyllPostFilename.Substring(0, 10); if (!DateTime.TryParse(dateString, out date)) { date = DateTime.Now.Date; } } post.DateCreated = date; meta.PostDate = date; content = Markdown.ToPlainText(meta.MarkdownBody); post.mt_excerpt = StringUtils.TextAbstract(content, 180); return(meta); }
public void GetPostConfigFromMarkdown() { WeblogInfo weblogInfo = WeblogAddinConfiguration.Current.Weblogs[ConstWeblogName]; Post post = new Post() { }; string markdown = MarkdownWithoutPostId; var addin = new WeblogAddin.WebLogAddin(); var meta = WeblogPostMetadata.GetPostConfigFromMarkdown(markdown, post, weblogInfo); Console.WriteLine("meta: \r\n" + JsonConvert.SerializeObject(meta, Formatting.Indented)); Console.WriteLine("post: \r\n" + JsonConvert.SerializeObject(post, Formatting.Indented)); Assert.IsTrue(meta.Abstract == "Abstract"); Assert.IsTrue(meta.Keywords == "Keywords"); Assert.IsTrue(meta.WeblogName == "WebLogName"); }
public void GetPosts() { var webLogInfo = new WeblogInfo { ApiUrl = STR_JEKYLL_PROJECT_FOLDER, Name = "Jekyll Test Blog" }; var rawMd = System.IO.File.ReadAllText(STR_MM_POST_FILE_NAME); var post = new Post(); // filled from meta data but not used here var meta = WeblogPostMetadata.GetPostYamlConfigFromMarkdown(rawMd, post); var pub = new LocalJekyllPublisher(meta, webLogInfo, null); var posts = pub.GetRecentPosts(20).ToList(); Console.WriteLine(posts.Count); foreach (var pst in posts) { Console.WriteLine($"{pst.Title} - {pst.mt_excerpt}"); } }
/// <summary> /// Creates a new post on disk and returns the filename /// </summary> /// <param name="post"></param> /// <param name="weblogName"></param> /// <returns></returns> public string CreateDownloadedPostOnDisk(Post post, string weblogName = null) { if (post == null) { return(null); } string filename = GetSafeFilename(post.Title); if (string.IsNullOrEmpty(weblogName)) { weblogName = WeblogInfo.Name; } var mmPostFolder = Path.Combine(WeblogAddinConfiguration.Current.PostsFolder, "Downloaded", weblogName, filename); if (!Directory.Exists(mmPostFolder)) { Directory.CreateDirectory(mmPostFolder); } var outputFile = Path.Combine(mmPostFolder, StringUtils.ToCamelCase(filename) + ".md"); string body = post.Body; string featuredImage = null; string categories = null; if (post.Categories != null && post.Categories.Length > 0) { categories = string.Join(",", post.Categories); } // Create the new post by creating a file with title preset var meta = new WeblogPostMetadata() { Title = post.Title, RawMarkdownBody = body, Categories = categories, Keywords = post.mt_keywords, Abstract = post.mt_excerpt, PostId = post.PostId?.ToString(), WeblogName = weblogName, FeaturedImageUrl = featuredImage, PostDate = post.DateCreated, PostStatus = post.PostStatus, Permalink = post.Permalink }; var postMarkdown = meta.SetPostYamlFromMetaData(); var jekyllPostFolder = Path.Combine(WeblogInfo.ApiUrl, "assets", meta.PostId); postMarkdown = CopyImagesToLocal(postMarkdown, jekyllPostFolder, mmPostFolder); try { File.WriteAllText(outputFile, postMarkdown); } catch (Exception ex) { this.SetError($@"Couldn't write new file at: {outputFile} {ex.Message}"); return(null); } mmApp.Configuration.LastFolder = Path.GetDirectoryName(outputFile); return(outputFile); }