示例#1
0
        static void Main(string[] args)
        {
            var t1 = DateTime.Now;

            Config.ConfigFile = args.Length > 1 ? args[0] : "config.json"; //设置配置文件

            foreach (var item in Config.ConfigList)
            {
                Console.WriteLine("Beginning……");
                AllMdFiles.Clear();
                GetAllMdFiles(item.Origin);

                Console.WriteLine("Copy template files……");
                Files.CopyDirectory(item.Template, item.WebRoot); //复制模板到网站根目录,包括 CSS、JS、字体、图片等,不包含 .md .json .yml

                Console.WriteLine("Copy source files……");
                Files.CopyDirectory(item.Origin, item.Destination); //复制源文件夹中的资源文件到输出目录,包括图片等,不包含 .md .json .yml

                Console.WriteLine("Build catalog……");
                var catalog = YmlConverter.ToHtml(item.Catalog, Path.GetFullPath(Config.ConfigFile).Replace(Config.ConfigFile, ""));
                BuildMarkDown(catalog, item); //对 MarkDown 文件夹进行解析、编译以及样式处理
            }
            var t2 = DateTime.Now;

            Console.WriteLine($"Finish: {(int)(t2 - t1).TotalSeconds}s");


            Console.ForegroundColor = ConsoleColor.Yellow;
            if (!string.IsNullOrEmpty(MdConverter.errorLog.ToString()))
            {
                Console.WriteLine(MdConverter.errorLog.ToString());
                Console.WriteLine($"Content Error Link: {MdConverter.errorLinkCount}/{MdConverter.linkCount}");
            }

            if (!string.IsNullOrEmpty(YmlConverter.errorLog.ToString()))
            {
                Console.WriteLine(YmlConverter.errorLog.ToString());
                Console.WriteLine($"Catalog Error Link: {YmlConverter.errorLinkCount}/{YmlConverter.linkCount}");
            }
            Console.ForegroundColor = ConsoleColor.White;

            try
            {
                File.WriteAllText("log.txt", $"{DateTime.Now}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            var t1 = DateTime.Now;

            Config.ConfigFile = "config.json"; //设置配置文件

            foreach (var item in Config.ConfigList)
            {
                AllMdFiles.Clear();
                GetAllMdFiles(item.Origin);

                //复制模板到网站根目录,包括 CSS、JS、字体、图片等,不包含 .md .json .yml
                Console.WriteLine("Copy template files……");
                Files.CopyDirectory("template", "wwwroot");

                //复制源文件夹中的资源文件到输出目录,包括图片等,不包含 .md .json .yml
                Console.WriteLine("Copy source files……");
                Files.CopyDirectory(item.Origin, item.Destination);

                Console.WriteLine("Build catalog……");
                var catalog = YmlConverter.ToHtml(Path.Combine(item.Origin, "toc.yml"), Path.GetFullPath(Config.ConfigFile).Replace(Config.ConfigFile, ""));
                AllMdFiles.ForEach(md =>
                {
                    if (!catalog.Contains(md.Replace("\\", "/").Replace(".md", ".html")))
                    {
                        YmlConverter.ErrorLogs.Add($"The file is not in the catalog: {md}");
                    }
                });
                BuildMarkDown(catalog, item); //对 MarkDown 文件夹进行解析、编译以及样式处理
            }
            var t2 = DateTime.Now;

            Console.WriteLine($"Finish: {(int)(t2 - t1).TotalSeconds}s");


            Console.ForegroundColor = ConsoleColor.Yellow;
            if (!string.IsNullOrEmpty(MdConverter.ErrorLogs.ToString()))
            {
                Console.WriteLine(string.Join("\r\n", MdConverter.ErrorLogs.ToArray()));
                Console.WriteLine($"Content Error Link: {MdConverter.ErrorLogs.Count}");
            }

            if (!string.IsNullOrEmpty(YmlConverter.ErrorLogs.ToString()))
            {
                Console.WriteLine(string.Join("\r\n", YmlConverter.ErrorLogs.ToArray()));
                Console.WriteLine($"Catalog Error Link: {YmlConverter.ErrorLogs.Count}");
            }
            Console.ForegroundColor = ConsoleColor.White;

            try { File.WriteAllText("log.txt", $"{DateTime.Now}"); } catch (Exception) { }

            Console.WriteLine("Press 'Enter' key in 3 seconds to pause...");
            Thread t = new(new ThreadStart(ConsolePause));

            t.Start();
            var t3 = DateTime.Now;

            while (true)
            {
                if ((DateTime.Now - t3).TotalSeconds > 3 && !isPause)
                {
                    Environment.Exit(0);
                }
                Thread.Sleep(100);
            }
        }