Ejemplo 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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!");
                }
            }
        }