Ejemplo n.º 1
0
 public PageModel(PageTreeItem <IFileInfo> treeItem, string content)
 {
     TreeItem = treeItem;
     Content  = content;
 }
Ejemplo n.º 2
0
        private PageTreeItem <IFileInfo> LoadDirectory(IFileProvider fileProvider, string basePath, IFileInfo parentDirectory, PageDirectoryLoaderOptions options)
        {
            PageTreeItem <IFileInfo> root = null;
            var files = fileProvider.GetDirectoryContents(basePath)
                        .ToList();

            var children = new List <PageTreeItem <IFileInfo> >();

            // Load all the files
            foreach (var file in files.Where(x => !x.IsDirectory))
            {
                if (options.IndexPageMatcher != null && options.IndexPageMatcher.Match(file.Name).HasMatches)
                {
                    // This is the index page.
                    root = new PageTreeItem <IFileInfo>(file, basePath, Path.Combine(basePath, file.Name));
                }
                else
                {
                    var path = basePath == "/"
                        ? $"/{options.PageSlug(file)}"
                        : $"{basePath}/{options.PageSlug(file)}";

                    if (options.NormalPageMatcher != null)
                    {
                        if (options.NormalPageMatcher.Match(file.Name).HasMatches)
                        {
                            children.Add(new PageTreeItem <IFileInfo>(file, path, Path.Combine(basePath, file.Name)));
                        }
                    }
                    else
                    {
                        children.Add(new PageTreeItem <IFileInfo>(file, path, Path.Combine(basePath, file.Name)));
                    }
                }
            }

            if (root == null)
            {
                root = new PageTreeItem <IFileInfo>(parentDirectory, basePath, basePath);
            }

            root.Children.AddRange(children);

            // Load all the child directories
            foreach (var directory in files.Where(x => x.IsDirectory))
            {
                var path = new PathString().Add(basePath)
                           .Add("/" + directory.Name);
                var treeItem = LoadDirectory(fileProvider, path, directory, options);
                if (treeItem != null)
                {
                    if ((treeItem.Data == null || treeItem.Data.IsDirectory) && treeItem.Children.Count == 0)
                    {
                        continue;
                    }

                    root.Children.Add(treeItem);
                }
            }

            foreach (var child in root.Children)
            {
                child.Parent = root;
            }

            return(root);
        }