예제 #1
0
        public void Append(WikiDirectory wikiDirectory)
        {
            if (Predef == null)
            {
                Predef = new List <string>();
            }
            if (Chaps == null)
            {
                Chaps = new List <string>();
            }
            if (Appendix == null)
            {
                Appendix = new List <string>();
            }
            if (Postdef == null)
            {
                Postdef = new List <string>();
            }

            var items =
                wikiDirectory
                .WikiEntries
                .Select(x => x.MarkdownName)
                .Where(
                    x => !Predef.Contains(x) &&
                    !Chaps.Contains(x) &&
                    !Appendix.Contains(x) &&
                    !Postdef.Contains(x));

            foreach (var item in items)
            {
                Chaps.Add(item);
            }
        }
예제 #2
0
        private static void Parse(WikiDirectory wikiDirectory)
        {
            var dotOrderPath = Path.Combine(wikiDirectory.FullName, ".order");

            IEnumerable<string> children;
            if (File.Exists(dotOrderPath))
            {
                children = File.ReadAllLines(dotOrderPath);
            }
            else
            {
                var directories = wikiDirectory._directoryInfo
                    .GetDirectories()
                    .Select(x => x.Name);
                var files = wikiDirectory._directoryInfo
                    .GetFiles()
                    .Where(x => x.Extension == ".md")
                    .Select(x => x.Name.Substring(0, x.Name.Length - x.Extension.Length));

                children = directories.Union(files).OrderBy(x => x);
            }

            foreach (var child in children)
            {
                var childPath = Path.Combine(wikiDirectory.FullName, child);
                if (Directory.Exists(childPath))
                {
                    var directoryWikiEntry =
                        File.Exists($"{childPath}.md")
                            ? new WikiFile(new FileInfo($"{childPath}.md"))
                            : (WikiEntry)new NullWikiFile();

                    var childWikiDirectory = 
                        new WikiDirectory(new DirectoryInfo(childPath), directoryWikiEntry);
                    Parse(childWikiDirectory);
                    wikiDirectory.AddWikiEntry(childWikiDirectory);
                }
                else if (File.Exists($"{childPath}.md"))
                {
                    wikiDirectory.AddWikiEntry(new WikiFile(new FileInfo($"{childPath}.md")));
                }
                else
                {
                    throw new InvalidOperationException($"{childPath} is not exists.");
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length <= 1 || !Directory.Exists(args[0]))
            {
                Console.WriteLine("第一引数にWikiディレクトリを第二引数に出力先フォルダを指定してください。");
                return;
            }

            var source = args[0];
            var dest   = args[1];

            if (!Directory.Exists(dest))
            {
                Directory.CreateDirectory(dest);
            }


            var wikiDirectory = WikiDirectory.Parse(source);

            foreach (var wikiEntry in wikiDirectory.WikiEntries)
            {
                using var streamWriter =
                          new StreamWriter(
                              Path.Combine(dest, wikiEntry.MarkdownName),
                              false,
                              new UTF8Encoding(false));
                wikiEntry.Write(streamWriter);
                streamWriter.Flush();
            }
            using var catalogReader =
                      new StreamReader(
                          Path.Combine(source, "catalog-md.yml"),
                          new UTF8Encoding(false));
            var catalog = Catalog.Load(catalogReader);

            catalog.Append(wikiDirectory);

            using var catalogWriter =
                      new StreamWriter(
                          Path.Combine(dest, "catalog.yml"),
                          false,
                          new UTF8Encoding(false));
            catalog.SaveToReViewCatalog(catalogWriter);

            Console.WriteLine("Completed.");
        }
예제 #4
0
 public static WikiDirectory Parse(string path)
 {
     var wikiDirectory = new WikiDirectory(new DirectoryInfo(path), new NullWikiFile());
     Parse(wikiDirectory);
     return wikiDirectory;
 }