Example #1
0
        private static string ProcessNav(NavItem n, ActiveState active, string uid)
        {
            StringBuilder html = new StringBuilder();

            if (n.UID == uid)
            {
                active = ActiveState.Self;
            }

            string activeClass = active == ActiveState.Self ? "active" : "";

            //string openClass = active == ActiveState.Child ? "open" : "";
            html.AppendLine($"<li class=\"{activeClass}\">");

            {
                string link = n.Link.Replace(Nav.RootPath, string.Empty).Replace("\\", "/").Replace(".md", ".html");
                html.AppendLine($"<a href=\"{link}\">{n.Title}</a>");
            }

            html.AppendLine("</li>");

            return(html.ToString());
        }
Example #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);
        }
Example #3
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]));
        }