예제 #1
0
        public void GenerateHTML(TextWriter wr)
        {
            dynamic data     = this.DataDynamic;
            string  ownerstr = HTML.GetOwnerString(data);

            HTML.RenderHeader(data.title, wr);

            if (HTML.EnableAttribution)
            {
                wr.WriteLine("<p><a href=\"{0}\">Source</a> - by {1}</p>", data.link, ownerstr);
            }
            else
            {
                wr.WriteLine("<p><a href=\"{0}\">Link</a></p>", data.link);
            }

            wr.WriteLine("<blockquote>");
            wr.WriteLine(data.body);
            wr.WriteLine("</blockquote>");

            foreach (Answer a in this.Answers)
            {
                a.GenerateHTML(wr);
            }

            HTML.RenderBottom(wr);
        }
예제 #2
0
        public void GenerateHTML(TextWriter wr)
        {
            string ownerstr = HTML.GetOwnerString(this);

            HTML.RenderHeader(this.Title, wr);

            if (HTML.EnableAttribution)
            {
                wr.WriteLine("<p><a href=\"{0}\">Source</a> - by {1}</p>", this.Link, ownerstr);
            }
            else
            {
                wr.WriteLine("<p><a href=\"{0}\">Link</a></p>", this.Link);
            }

            wr.WriteLine("<blockquote>");
            wr.WriteLine(this.Body);
            wr.WriteLine("</blockquote>");

            foreach (AnswerMarkdown a in this.Answers)
            {
                a.GenerateHTML(wr);
            }

            HTML.RenderBottom(wr);
        }
예제 #3
0
        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);
            }
        }