private static void ReportGraph(EntryGraph graph, int indent = 0) { Console.WriteLine((new String('\t', indent)) + graph.Entry.Id); indent++; foreach (var child in graph.Children) { ReportGraph(child, indent); } }
private static void ReportPost(Entry post, EntryGraph graph) { Console.WriteLine("Id: " + post.Id); Console.WriteLine("Published: " + post.Published); Console.WriteLine("Updated: " + post.Updated); Console.WriteLine("Title: " + post.Title); Console.WriteLine("Url: " + post.Url); Console.WriteLine("Tags: " + String.Join(", ", post.Tags)); Console.WriteLine("Author: " + post.Author.Name); Console.WriteLine("Content Length: " + post.Content.Length); ReportGraph(graph); }
private static void BuildRss(Rss comments, Blog meta, EntryGraph graph) { if (graph.Children != null && graph.Children.Count > 0) { comments.Channel.Items.Add(new Item { Title = meta.Title, AbsoluteUrl = DESTINATION_BLOG_PATH + meta.Url, Content = "", ThreadIdentified = meta.Id, Published = meta.Published, Status = "open", Comments = BuildComments(graph.Children, "") }); } }
public static void Export(EntryGraph graph, Rss comments) { var debug = false; Console.WriteLine(graph.Entry.Url); Blog meta = new Blog(); meta.Id = Guid.NewGuid().ToString(); meta.Url = graph.Entry.Url; meta.Author = graph.Entry.Author.Name; meta.Published = graph.Entry.Published; meta.Modified = graph.Entry.Updated; meta.Title = graph.Entry.Title; //meta.Image; //meta.Description; meta.Enabled = true; meta.Redirects = new List <Redirect> { new Redirect { Url = graph.Entry.BloggerUrl, RedirectType = HttpStatusCode.MovedPermanently, RedirectByParameter = true, RedirectByRoute = false } }; string contentFolder = CreateContentFolder(graph.Entry.Url); string mediaFolder = CreateMediaFolder(graph.Entry.Url); string mediaPath = MEDIABASEPATH + graph.Entry.Url; var md = graph.Entry.Content; // Add Carriage Returns if (debug) { Console.WriteLine("Add Carriage Returns"); } md = md.Replace("<br />", Environment.NewLine); // Map <hx> if (debug) { Console.WriteLine("Map <hx>"); } md = Regex.Replace(md, "<h1>(.*?)</h1>", x => { return("# " + x.Groups[1] + Environment.NewLine); // + new String('-', x.Groups[1].Length) + Environment.NewLine; }); md = Regex.Replace(md, "<h2>(.*?)</h2>", x => { return("## " + x.Groups[1] + Environment.NewLine); // + new String('-', x.Groups[1].Length) + Environment.NewLine; }); md = Regex.Replace(md, "<h3>(.*?)</h3>", x => { return("### " + x.Groups[1] + Environment.NewLine); // + new String('-', x.Groups[1].Length) + Environment.NewLine; }); // Replace non-breaking spaces if (debug) { Console.WriteLine("Replace non-breaking spaces"); } md = md.Replace(" ", " "); // Remove any meta Tags if (debug) { Console.WriteLine("Remove any meta Tags"); } md = Regex.Replace(md, "<meta (.*?)/>" + Environment.NewLine, ""); // Map blogger image if (debug) { Console.WriteLine("Map blogger image"); } md = Regex.Replace(md, "<div class=\"separator\"(.*?)<a href=\"(.*?)\"(.*?)<img (.*?)src=\"(.*?)\"(.*?)</div>", x => { return("![Image](" + ProcessImage(mediaFolder, mediaPath, x.Groups[2].Value) + ")" + Environment.NewLine); }); // Remove summary breaks if (debug) { Console.WriteLine("Remove summary breaks"); } md = md.Replace("<a name='more'></a>" + Environment.NewLine + Environment.NewLine, DESCRIPTION_BREAK_TAG); md = md.Replace("<a name='more'></a>" + Environment.NewLine, DESCRIPTION_BREAK_TAG); md = md.Replace("<a name='more'></a>", DESCRIPTION_BREAK_TAG); // Remove RFC Weekly header if (debug) { Console.WriteLine("Remove RFC Weekly header"); } Regex rfcWeeklyHeaderRegex = new Regex("<a href=\"(.*?)Hopefully someone else will also find useful.", RegexOptions.Singleline); md = rfcWeeklyHeaderRegex.Replace(md, ""); // Map Anchors if (debug) { Console.WriteLine("Map Anchors"); } md = Regex.Replace(md, "<a (.*?)>(.*?)</a>", x => { var sb = new StringBuilder(); sb.Append("["); sb.Append(x.Groups[2]); sb.Append("]"); sb.Append("("); sb.Append(Regex.Matches(x.Groups[1].ToString(), "href=\"(.*?)\"")[0].Groups[1]); sb.Append(")"); return(sb.ToString()); }); // Map Lists if (debug) { Console.WriteLine("Map Lists"); } md = md.Replace("<ul>", Environment.NewLine); md = md.Replace("<li>", "* "); md = md.Replace("</li>", Environment.NewLine); md = md.Replace("</ul>", Environment.NewLine); // Gists if (debug) { Console.WriteLine("Gists"); } md = Regex.Replace(md, "<script src=\"(.*?)\">(.*?)</script>", x => "%[" + x.Groups[1].Value + "]"); // Remove Spread the love if (debug) { Console.WriteLine("Remove Spread the love"); } md = Regex.Replace(md, "<div id=\"SpreadTheLove\">(.*?)</div>", ""); // Remove Divs if (debug) { Console.WriteLine("Remove Divs"); } md = Regex.Replace(md, "<div(.*?)>", ""); md = md.Replace("</div>", ""); // Replace html encoding if (debug) { Console.WriteLine("Replace html encoding"); } md = md.Replace(">", ">"); // Remove empty lines at the start & end if (debug) { Console.WriteLine("Remove empty lines at the start & end"); } while (md.StartsWith(Environment.NewLine)) { md = md.Substring(Environment.NewLine.Length); } while (md.EndsWith(Environment.NewLine + Environment.NewLine)) { md = md.Substring(0, md.Length - Environment.NewLine.Length); } // Load the Description (then remove the tag) if (debug) { Console.WriteLine("Load the Description (then remove the tag)"); } if (md.Contains(DESCRIPTION_BREAK_TAG)) { meta.Description = md.Substring(0, md.IndexOf(DESCRIPTION_BREAK_TAG)); md = md.Replace(DESCRIPTION_BREAK_TAG, ""); } // Set up the Keywords if (debug) { Console.WriteLine("Setup the keywords"); } meta.KeyWords = graph.Entry.Tags; // RFC Weekly specific actions if (debug) { Console.WriteLine("RFC Weekly specific actions"); } if (graph.Entry.Title.ToLower().Contains("rfc") && graph.Entry.Title.ToLower().Contains("weekly")) { // Add the image & description meta.Image = "/media/blog/rfc-weekly/RFCWeeklyTwitterCard.png"; meta.Description = "RFC Weekly - a summary of things that I find interesting. It is an indulgence; its the weekly update that I would like to receive. Unfortunately no-one else is producing it so I figured I best get on with it. Hopefully someone else will also find useful."; // Add as a key word if (!meta.KeyWords.Contains("RFCWeekly")) { meta.KeyWords.Add("RFCWeekly"); } } if (debug) { Console.WriteLine("Save to file"); } SaveMarkdown(contentFolder, graph.Entry.Url, md); SaveMeta(contentFolder, graph.Entry.Url, meta); BuildRss(comments, meta, graph); }