public Command Create() { var cmd = new Command("markdown", "Convert WordPress export files into a markdown format.") { Handler = CommandHandler.Create(async(string wpexportFilePath, string exportFilePath) => { this.settings = this.settingsManager.LoadSettings(nameof(StackerSettings)); if (!File.Exists(wpexportFilePath)) { Console.WriteLine($"File not found {wpexportFilePath}"); return; } this.serializer = this.serializerFactory.GetSerializer(); BlogSite blogSite = await this.LoadWordPressExportAsync(wpexportFilePath).ConfigureAwait(false); var feed = this.LoadFeed(blogSite); var sb = new StringBuilder(); FileInfo fi = new FileInfo(exportFilePath); DirectoryInfo tempHtmlFolder = new DirectoryInfo(Path.Join(Path.GetTempPath(), "stacker", "html")); DirectoryInfo tempMarkdownFolder = new DirectoryInfo(Path.Join(Path.GetTempPath(), "stacker", "md")); string inputTempHtmlFilePath; string outputTempMarkdownFilePath; string outputFilePath; if (!fi.Directory.Exists) { fi.Directory.Create(); } if (!tempHtmlFolder.Exists) { tempHtmlFolder.Create(); } if (!tempMarkdownFolder.Exists) { tempMarkdownFolder.Create(); } await this.downloadTasks.DownloadAsync(feed, exportFilePath).ConfigureAwait(false); foreach (var ci in feed) { var contentItem = this.cleanerManager.PostDownload(ci); sb.AppendLine("---"); sb.Append(this.CreateYamlHeader(contentItem)); sb.Append("---"); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); await using (var writer = File.CreateText(Path.Combine(tempHtmlFolder.FullName, contentItem.UniqueId + ".html"))) { await writer.WriteAsync(contentItem.Content.Body).ConfigureAwait(false); } inputTempHtmlFilePath = Path.Combine(tempHtmlFolder.FullName, contentItem.UniqueId + ".html"); outputTempMarkdownFilePath = Path.Combine(tempMarkdownFolder.FullName, contentItem.UniqueId + ".md"); outputFilePath = Path.Combine(exportFilePath, contentItem.Author.Username.ToLowerInvariant(), contentItem.UniqueId + ".md"); FileInfo outputFile = new FileInfo(outputFilePath); if (!outputFile.Directory.Exists) { outputFile.Directory.Create(); } if (this.ExecutePandoc(inputTempHtmlFilePath, outputTempMarkdownFilePath)) { sb.Append(await File.ReadAllTextAsync(outputTempMarkdownFilePath).ConfigureAwait(false)); string content = sb.ToString(); Console.WriteLine(outputFilePath); try { content = this.cleanerManager.PostConvert(content); } catch (Exception exception) { Console.WriteLine(exception.Message); } await using (var writer = File.CreateText(outputFilePath)) { await writer.WriteAsync(content).ConfigureAwait(false); } } // Remote the temporary html file. File.Delete(inputTempHtmlFilePath); sb.Clear(); } }), }; cmd.AddArgument(new Argument <string>("wp-export-file-path") { Description = "WordPress Export file path." }); cmd.AddArgument(new Argument <string>("export-file-path") { Description = "File path for the exported files." }); return(cmd); }
public static IEnumerable <Post> FilterByValid(this IEnumerable <Post> posts, StackerSettings settings) { return(posts.Where(p => settings.Users.Exists(u => u.IsActive && string.Equals(u.Email, p.Author.Email, StringComparison.InvariantCultureIgnoreCase)))); }