Example #1
0
        private RepositoryIndex ImportIndex(DirectoryInfo currentPath, MarkdownDocument document)
        {
            RepositoryIndex index = new RepositoryIndex();

            index.Name = currentPath.Name;

            foreach (var ii in document)
            {
                ListBlock list = ii as ListBlock;

                if (list != null)
                {
                    foreach (ListItemBlock jj in list)
                    {
                        var link = ImportIndexEntry(currentPath, jj);

                        if (link != null)
                        {
                            index.Children.Add(link);
                        }
                    }
                }
            }

            return(index);
        }
        public void Export(RepositoryIndex index, string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

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

            var filePath = Path.Combine(path, "readme.md");

            using (var writer = new StreamWriter(filePath))
            {
                writer.WriteLine("<!-- index -->");
                writer.WriteLine($"## {index.Name}");

                if (index.Children != null)
                {
                    foreach (var child in index.Children)
                    {
                        writer.WriteLine($"* [{child.Name}]({child.Name}/readme.md)");
                    }
                }
            }

            if (index.Children != null)
            {
                foreach (var child in index.Children)
                {
                    Export(child, Path.Combine(path, child.Name));
                }
            }
        }