Esempio n. 1
0
        internal void Process()
        {
            navs = ParseDirectory(Nav.RootPath + src);
            p    = new MarkdownPipelineBuilder().UsePipeTables(new PipeTableOptions {
                RequireHeaderSeparator = true
            })
                   .UseBootstrap()
                   .UseYamlFrontMatter()
                   .UseGenericAttributes()
                   .UseAutoIdentifiers(AutoIdentifierOptions.GitHub)
                   .Build();

            for (int i = 0; i < MDs.Count; i++)
            {
                StringBuilder nhtml = new StringBuilder();
                StringBuilder ohtml = new StringBuilder();

                foreach (NavItem item in navs.Items)
                {
                    ActiveState active = ActiveState.None;
                    string      uid    = Nav.GetNavItem(MDs[i]).UID;
                    string      nid    = Nav.SanitizeFilename(item.Title).Replace(" ", string.Empty);

                    if (item.Items.Any(t => t.UID == uid))
                    {
                        active = ActiveState.Child;
                        nhtml.AppendLine("<li class=\"panel expanded active\">" +
                                         $"<a class=\"area\" href=\"#{nid}\" data-parent=\"#main-nav\" data-toggle=\"collapse\">{item.Title}</a>");
                        nhtml.AppendLine($"<ul id=\"{nid}\" class=\"collapse in\">");
                    }
                    else
                    {
                        nhtml.AppendLine("<li class=\"panel collapsed\">" +
                                         $"<a class=\"area\" href=\"#{nid}\" data-parent=\"#main-nav\" data-toggle=\"collapse\">{item.Title}</a>");
                        nhtml.AppendLine($"<ul id=\"{nid}\" class=\"collapse\">");
                    }

                    ohtml.AppendLine($"<optgroup label=\"{item.Title}\">");

                    foreach (NavItem navItem in item.Items)
                    {
                        if (active == ActiveState.Child && uid == navItem.UID)
                        {
                            nhtml.AppendLine(ProcessNav(navItem, active, uid));
                            ohtml.AppendLine($"<option selected=\"selected\" value=\"{navItem.Link}\">{navItem.Title}</option>");
                        }
                        else
                        {
                            nhtml.AppendLine(ProcessNav(navItem, ActiveState.None, uid));
                            ohtml.AppendLine($"<option value=\"{navItem.Link}\">{navItem.Title}</option>");
                        }
                    }

                    nhtml.AppendLine("</ul></li></div>");
                    ohtml.AppendLine("</optgroup>");
                }


                navHtml = minifier.Minify(nhtml.ToString()).MinifiedContent;
                optHtml = "<select id=\"small-nav-dropdown\">" + minifier.Minify(ohtml.ToString()).MinifiedContent + "</select>";

                ProcessMD(MDs[i]);
            }//);

            //! Uncomment to use parallel processing. Useful when you have hundreds of files.
            // Parallel.For(0, MDs.Count, i => ProcessMD(MDs[i]));
        }
Esempio n. 2
0
        private NavItem ParseDirectory(string dir)
        {
            IEnumerable <string> dirs = Directory.EnumerateDirectories(dir);

            string dirName = dir.Contains("Bleeding") ? dir.Trim('\\').Split('\\').Last()
                                 : Nav.tt.ToTitleCase(dir.Trim('\\').Split('\\').Last());

            if (dirName.Contains("-"))
            {
                dirName = dirName.Split('-')[1].Trim();
            }

            NavItem current = new NavItem(dirName);

            string[] xml = Directory.GetFiles(dir, "*.update");

            XmlSerializer xs = new XmlSerializer(typeof(UpdateManifest));

            foreach (string x in xml)
            {
                UpdateManifest manifest;
                using (var fs = new FileStream(x, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    manifest = xs.Deserialize(fs) as UpdateManifest;
                }

                string version     = Version.Parse(manifest.Version).ToString(4);
                string versionSafe = version.Replace(".", "_");

                StringBuilder md = new StringBuilder();

                md.AppendLine("---");
                md.AppendLine("uid: gaea_" + versionSafe);
                md.AppendLine("title: Gaea " + version);
                md.AppendLine("---\n\n");
                md.AppendLine($"**Released on {manifest.ReleaseDate:dd MMMM yyyy}**\n");
                md.AppendLine($"<a href=\"{manifest.URL}\">Download {manifest.Size / 1024.0 / 1024.0:F}MB</a> <br>");
                md.AppendLine("\n");
                md.AppendLine("<div class=\"release-note\">\n");
                md.AppendLine(manifest.FullDescription);
                md.AppendLine("</div>");

                File.WriteAllText($"{Path.GetDirectoryName(x)}\\{version}.md", md.ToString());
            }

            string[] mds = Directory.GetFiles(dir, "*.md");

            if (dir.Contains("Changelogs"))
            {
                mds = mds.OrderByDescending(x => x).ToArray();
            }

            foreach (string md in mds.Where(md => !md.ToLower().EndsWith(".params.md") && !md.Contains("--")))
            {
                var temp = Nav.GetNavItem(md);
                temp.Link = Nav.ReplaceNumbers(temp.Link.Replace(Nav.RootPath + "source", string.Empty).Replace("\\", "/").Replace(".md", ".html"));

                if (temp.Show)
                {
                    current.Items.Add(temp);
                }

                MDs.Add(md);
            }

            foreach (string d in dirs)
            {
                current.Items.Add(ParseDirectory(d));
            }

            return(current);
        }
Esempio n. 3
0
        internal void ProcessMD(string md)
        {
            string name = Nav.SanitizeFilename(md);
            string html = raw_html;

            html = html.Replace("<!--REPLACE--OPT-->", optHtml);
            html = html.Replace("<!--REPLACE--NAV-->", navHtml);
            html = html.Replace("<!--REPLACE-SUPERNAV-->", MainNavHTML);

            #region Get Title

            string[] lines = File.ReadAllLines(md);

            if (lines.Length > 3)
            {
                for (int i = 1; i < 3; i++)
                {
                    if (lines[i].Contains("title:"))
                    {
                        title = lines[i].Split(':')[1].Trim();
                    }
                }
            }

            if (string.IsNullOrEmpty(title.Trim()))
            {
                title = name.Replace("-", " ");
            }

            StringBuilder bread = new StringBuilder();

            if (navs != null)
            {
                bread.AppendLine("<ol class=\"breadcrumb visible-md visible-lg\">");
                bread.AppendLine(
                    "<li class=\"breadcrumb-item\"><a href=\"/index.html\">Home</a></li>");
                bread.AppendLine($"<li class=\"breadcrumb-item\"><a href=\"{BaseItem.Link}\">{BaseItem.Title}</a></li>");
                if (navs.Items.Any(i => i.Items.Any(x => x.Title == title)))
                {
                    bread.AppendLine(
                        $"<li class=\"breadcrumb-item\">{navs.Items.First(i => i.Items.Any(x => x.Title == title))}</li>");
                }
                bread.AppendLine($"<li class=\"breadcrumb-item active\">{title}</li>");
                bread.AppendLine("</ol>");
            }

            #endregion Get Title

            StringBuilder raw = new StringBuilder();

            foreach (string s in lines.Skip(3))
            {
                if (s.StartsWith("^"))
                {
                    string include = $"{Nav.RootPath}\\source\\_includes\\{s.Replace("^", string.Empty)}.md";
                    if (File.Exists(include))
                    {
                        raw.AppendLine(File.ReadAllText(include));
                    }
                }
                else
                {
                    raw.AppendLine(ProcessLinks(s));
                }
            }

            if (!md.ToLower().Contains("index.md"))
            {
                string doc = Markdown.ToPlainText(raw.ToString());

                doc = Regex.Replace(doc.Substring(0, doc.Length >= 1200 ? 1200 : doc.Length), @"\{([^\}]+)\}", "");
                doc = Regex.Replace(doc.Substring(0, doc.Length >= 1200 ? 1200 : doc.Length), @"\<([^\>]+)\>", "");

                search.Add(new SearchObject
                {
                    url    = Nav.GetNavItem(md).Link,
                    title  = title,
                    hive   = BaseItem.Title,
                    parent = navs.Items.Any(i => i.Items.Any(x => x.Title == title)) ?
                             navs.Items.First(i => i.Items.Any(x => x.Title == title)).Title
                                                        : "",
                    text = doc
                });
            }

            StringBuilder output = new StringBuilder();
            output.AppendLine(Markdown.ToHtml(raw.ToString(), p));

            if (ProcessProceduralFiles)
            {
                string @params = $"{Path.GetDirectoryName(md)}\\{Path.GetFileNameWithoutExtension(md)}.params.md";

                //? PARAMETERS
                if (File.Exists(@params))
                {
                    output.AppendLine(ProcessParams(@params));
                }
            }

            if (ProcessExampleFiles)
            {
                //! EXAMPLES
                output.AppendLine(ProcessExamples(md));
            }

            if (ProcessTutorialFiles)
            {
                //! TUTORIALS
                output.AppendLine(ProcessTutorials(md));
            }

            html = html.Replace("<!--REPLACE--BODY-->", $"{bread}<p class=\"faux-h1\">{title}</p>{output}");
            html = html.Replace("%%TITLE%%", title);
            //html = html.Replace("<!--REPLACE--BREADCRUMBS-->", bread.ToString());

            try
            {
                string subpath = Path.GetDirectoryName(md.Replace(Nav.RootPath, Nav.RootPath + dst))
                                 .Replace("source\\", "");

                if (subpath.Contains("Data"))
                {
                }
                if (!subpath.EndsWith("\\"))
                {
                    subpath += "\\";
                }

                subpath = Nav.ReplaceNumbers(subpath);
                Directory.CreateDirectory(subpath);

                //File.WriteAllText(subpath + name + ".html", html);
                File.WriteAllText(subpath + name + ".html", minifier.Minify(html).MinifiedContent);
            }
            catch (IOException)
            {
                Console.WriteLine("ERROR: " + Nav.RootPath + dst + name + ".html could not be written.");
            }

            //Console.Write(".");
        }