コード例 #1
0
        private void AddChildItems(ChapterItemDto parentItem, List <object> pages, string docsDir)
        {
            foreach (var page in pages)
            {
                var subPages = page as Dictionary <object, object>;
                foreach (var key in subPages.Keys)
                {
                    var value = subPages[key];

                    var node = new ChapterItemDto();
                    node.Name = key.ToString();
                    parentItem.Children.Add(node);

                    if (value is string)
                    {
                        var url = $"{docsDir}:{value}";
                        node.Url = url.Replace("/", ":");
                    }
                    else
                    {
                        List <object> nodes = value as List <object>;
                        if (nodes != null)
                        {
                            AddChildItems(node, nodes, docsDir);
                        }
                    }
                }
            }
        }
コード例 #2
0
        private List <ChapterItemDto> GetChapterItems(Dictionary <object, object> mkDocsConfiguration)
        {
            var pages = mkDocsConfiguration["pages"];

            var docsDir = "docs";

            if (mkDocsConfiguration.ContainsKey("docs_dir"))
            {
                var mkDocsdir = mkDocsConfiguration["docs_dir"].ToString();
                if (!string.IsNullOrWhiteSpace(mkDocsdir))
                {
                    docsDir = mkDocsdir;
                }
            }

            var parentItem  = new ChapterItemDto();
            var listOfPages = pages as List <object>;

            if (listOfPages != null)
            {
                AddChildItems(parentItem, listOfPages, docsDir);
            }

            var rootChapterItems = new List <ChapterItemDto>();

            foreach (var item in parentItem.Children)
            {
                rootChapterItems.Add(item);
            }

            return(rootChapterItems);
        }