public void GenerateHTML(TextWriter wr) { dynamic data = this.DataDynamic; string ownerstr = HTML.GetOwnerString(data); wr.WriteLine("<h2>Answer {0}</h2>", data.answer_id); if (HTML.EnableAttribution) { wr.WriteLine("<p><a href=\"https://{0}/a/{1}/\">Source</a> - by {2}</p>", this.site, data.answer_id, ownerstr); } else { wr.WriteLine("<p><a href=\"https://{0}/a/{1}/\">Link</a></p>", this.site, data.answer_id); } wr.WriteLine("<blockquote>"); wr.WriteLine(data.body); wr.WriteLine("</blockquote>"); }
public static void Generate(string site, string subdir, string toc_title) { string datadir = "..\\..\\..\\..\\data\\" + site + "\\"; string postsdir = Path.Combine(datadir, subdir + "\\"); string htmldir = "..\\..\\..\\..\\html\\" + site + "\\"; string targetdir = Path.Combine(htmldir, subdir + "\\"); string path; TextWriter wr; if (!Directory.Exists(htmldir)) { Directory.CreateDirectory(htmldir); } if (!Directory.Exists(targetdir)) { Directory.CreateDirectory(targetdir); } Console.WriteLine("Generating HTML files ({0}, {1})...", site, subdir); PostSet posts = PostSet.LoadFromDir(postsdir, site); Dictionary <int, Question> questions = posts.Questions; Console.WriteLine("JSON questions: {0}", questions.Count); foreach (int q in questions.Keys) { string title = questions[q].DataDynamic.title; path = Path.Combine(targetdir, q.ToString() + ".md"); wr = new StreamWriter(path, false); using (wr) { questions[q].GenerateHTML(wr); } } Console.WriteLine("JSON answers: {0}", posts.SingleAnswers.Count); foreach (int a in posts.SingleAnswers.Keys) { path = Path.Combine(targetdir, a.ToString() + ".md"); wr = new StreamWriter(path, false); using (wr) { HTML.RenderHeader(a, wr); posts.SingleAnswers[a].GenerateHTML(wr); HTML.RenderBottom(wr); } } Console.WriteLine("Markdown questions: {0}", posts.MarkdownQuestions.Count); foreach (int q in posts.MarkdownQuestions.Keys) { path = Path.Combine(targetdir, q.ToString() + ".md"); wr = new StreamWriter(path, false); using (wr) { posts.MarkdownQuestions[q].GenerateHTML(wr); } } Console.WriteLine("Markdown answers: {0}", posts.MarkdownAnswers.Count); foreach (int a in posts.MarkdownAnswers.Keys) { path = Path.Combine(targetdir, a.ToString() + ".md"); wr = new StreamWriter(path, false); using (wr) { HTML.RenderHeader(posts.MarkdownAnswers[a].Title, wr); posts.MarkdownAnswers[a].GenerateHTML(wr); HTML.RenderBottom(wr); } } Console.WriteLine("Generating TOC ({0}: {1})...", site, toc_title); path = Path.Combine(targetdir, "index.md"); wr = new StreamWriter(path, false); using (wr) { HTML.RenderTOC(site, toc_title, posts, wr); } Console.WriteLine("Generating toc.yml ({0}: {1})...", site, toc_title); path = Path.Combine(targetdir, "toc.yml"); wr = new StreamWriter(path, false); using (wr) { HTML.RenderYamlTOC(site, toc_title, posts, wr); } }