Esempio n. 1
0
        public static string ProcessArticle(string path, string projectRoot)
        {
            string result = QwfReader.ReadFileText(projectRoot + "\\layout\\template.html");
            // Get document info
            var           lines          = QwfReader.GetFileTextLines(path);
            List <string> qwiLines       = new List <string>();
            List <string> articleLines   = new List <string>();
            bool          readingArticle = false;

            foreach (string line in lines)
            {
                if (line == "==")
                {
                    readingArticle = true;
                    continue;
                }
                if (readingArticle)
                {
                    articleLines.Add(line);
                }
                else
                {
                    qwiLines.Add(line);
                }
            }
            var    qwi     = QwfReader.ReadQwi(qwiLines);
            string article = QwfReader.MDToHTML(articleLines);

            result = result.Replace(";;TITLE;;", qwi["Title"]);
            result = result.Replace(";;ARTICLE;;", article);
            result = result.Replace(";;SIDEBAR_LINKS;;", GetSidebarLinks());
            result = result.Replace(";;FOOTER;;", GetFooterText());
            return(result);
        }
Esempio n. 2
0
        public static void CreateCategoryPages(string projectRoot, string resultDir)
        {
            string template = QwfReader.ReadFileText(projectRoot + "\\layout\\template.html");

            foreach (KeyValuePair <string, Dictionary <string, List <string> > > category in categories)
            {
                string text = "";
                text += "<h1>" + "Category: " + category.Key + "</h2>";
                text += "<p>" + categoryDescriptions[category.Key] + "</p>";
                foreach (KeyValuePair <string, List <string> > section in category.Value)
                {
                    text += "<h2>" + section.Key + "</h2>";
                    for (int i = 0; i < section.Value.Count; i += 2)
                    {
                        text += "<a href=" + section.Value[i] + ">" + section.Value[i + 1] + "</a>" + "<br><br>";
                    }
                }
                string resultHtml = template;
                resultHtml = resultHtml.Replace(";;TITLE;;", "Category: " + category.Key);
                resultHtml = resultHtml.Replace(";;ARTICLE;;", text);
                resultHtml = resultHtml.Replace(";;SIDEBAR_LINKS;;", GetSidebarLinks());
                resultHtml = resultHtml.Replace(";;FOOTER;;", GetFooterText());

                System.IO.File.WriteAllText(resultDir + "\\categories\\" + category.Key + ".html", resultHtml);
            }
        }
Esempio n. 3
0
        static int Main(string[] args)
        {
            // Find site .qwi file (neesd to be first argument) and get the project settings.
            if (args.Length == 0)
            {
                Console.WriteLine("Please provide a valid path to a qudicalwiki folder.");
                Console.WriteLine("(qwikigen.exe path/to/folder)");
                return(1);
            }

            string projectRoot = args[0];

            siteSettings = QwfReader.ReadQwi(QwfReader.GetFileTextLines(projectRoot + "\\siteinfo.qwi"));

            // Set up some folders and copy assets and layout over

            string resultDir = projectRoot + "\\result";

            if (Directory.Exists(resultDir))
            {
                Directory.Delete(resultDir, true);
            }
            Directory.CreateDirectory(resultDir);
            Directory.CreateDirectory(resultDir + "\\assets");
            Directory.CreateDirectory(resultDir + "\\styles");
            Directory.CreateDirectory(resultDir + "\\articles");
            Directory.CreateDirectory(resultDir + "\\categories");

            File.Copy(projectRoot + "\\layout\\style.css", resultDir + "\\styles\\style.css");

            CopyAll(new DirectoryInfo(projectRoot + "\\assets"), new DirectoryInfo(resultDir + "\\assets"));

            SiteConstructor.categories           = new Dictionary <string, Dictionary <string, List <string> > >();
            SiteConstructor.categoryDescriptions = new Dictionary <string, string>();
            SiteConstructor.CreateCategories(new DirectoryInfo(projectRoot + "\\articles"), new DirectoryInfo(resultDir + "\\articles"), projectRoot, resultDir);
            SiteConstructor.CreateCategoryPages(projectRoot, resultDir);

            System.IO.File.WriteAllText(resultDir + "\\index.html", SiteConstructor.GenerateHomepage(projectRoot, resultDir, siteSettings));

            SiteConstructor.ConvertArticles(new DirectoryInfo(projectRoot + "\\articles"), new DirectoryInfo(resultDir + "\\articles"), projectRoot);

            Console.WriteLine("Site generated!");

            return(0);
        }
Esempio n. 4
0
        public static string GenerateHomepage(string projectRoot, string resultDir, Dictionary <string, string> siteSettings)
        {
            string        result       = QwfReader.ReadFileText(projectRoot + "\\layout\\template.html");
            List <string> articleLines = new List <string>()
            {
                "# Welcome to the Qudical Developer Wiki!",
                "Here you'll _(hopefully)_ find some useful information regarding the technical side of Qudical projects.",
                "# Categories:"
            };
            string article = QwfReader.MDToHTML(articleLines);

            foreach (KeyValuePair <string, Dictionary <string, List <string> > > category in categories)
            {
                string path = "\\qudicalwiki\\categories\\" + category.Key + ".html";
                article += "<h2><a href=\"" + path + "\">" + category.Key + "</a></h2>";
                article += $"<p>{categoryDescriptions[category.Key]}</p>";
            }
            result = result.Replace(";;TITLE;;", siteSettings["SiteName"]);
            result = result.Replace(";;ARTICLE;;", article);
            result = result.Replace(";;SIDEBAR_LINKS;;", GetSidebarLinks());
            result = result.Replace(";;FOOTER;;", GetFooterText());
            return(result);
        }
Esempio n. 5
0
        private static void ProcessArticleCategory(string path, string projectRoot, string resultDir)
        {
            // Get document info
            var           lines          = QwfReader.GetFileTextLines(path);
            List <string> qwiLines       = new List <string>();
            bool          readingArticle = false;

            foreach (string line in lines)
            {
                if (line == "==")
                {
                    readingArticle = true;
                    continue;
                }
                if (!readingArticle)
                {
                    qwiLines.Add(line);
                }
            }
            var    qwi          = QwfReader.ReadQwi(qwiLines);
            string relativePath = Path.GetRelativePath(resultDir, path.Replace(".qwa", ".html"));

            // Add current page to category and section, create them if they don't exist already.
            if (categories.ContainsKey(qwi["Category"]))
            {
                if (categories[qwi["Category"]].ContainsKey(qwi["Section"]))
                {
                    if (!categories[qwi["Category"]][qwi["Section"]].Contains(relativePath))
                    {
                        categories[qwi["Category"]][qwi["Section"]].Add(relativePath);
                        categories[qwi["Category"]][qwi["Section"]].Add(qwi["Title"]);
                    }
                }
                else
                {
                    categories[qwi["Category"]][qwi["Section"]] = new List <string>()
                    {
                        relativePath, qwi["Title"]
                    };
                    Console.WriteLine("Creating section " + qwi["Section"]);
                }
            }
            else
            {
                categories[qwi["Category"]] = new Dictionary <string, List <string> >();
                Console.WriteLine("Creating category " + qwi["Category"]);

                if (categories[qwi["Category"]].ContainsKey(qwi["Section"]))
                {
                    if (!categories[qwi["Category"]][qwi["Section"]].Contains(relativePath))
                    {
                        categories[qwi["Category"]][qwi["Section"]].Add(relativePath);
                        categories[qwi["Category"]][qwi["Section"]].Add(qwi["Title"]);
                    }
                }
                else
                {
                    categories[qwi["Category"]][qwi["Section"]] = new List <string>()
                    {
                        relativePath, qwi["Title"]
                    };
                    Console.WriteLine("Creating section " + qwi["Section"]);
                }
            }

            // Get category description, if that has been set.
            if (qwi.ContainsKey("CategoryDescription"))
            {
                if (!categoryDescriptions.ContainsKey(qwi["Category"]))
                {
                    categoryDescriptions[qwi["Category"]] = QwfReader.MDToHTML(qwi["CategoryDescription"]);
                }
                else
                {
                    Console.WriteLine("WARNING! Category " + qwi["Category"] + " has multiple description definitions!");
                }
            }
        }