Example #1
0
        private List <NavItem> CreateNavItems(GithubUri githubUri, IReadOnlyCollection <ContentInfo> files)
        {
            var navItems = files
                           .Where(r => (GithubUri.CheckIfMarkdownFile(r.Name) || r.Type == "dir") &&
                                  !r.Name.StartsWith("."))
                           .Select(r =>
                                   new NavItem(
                                       r.Name,
                                       githubUri.Owner + "/" + githubUri.RepoName + "/" + r.Path,
                                       r.Type == "dir" ? NavType.Directory : NavType.Markdown,
                                       false))
                           .OrderBy(r => r.Type)
                           .ThenBy(r => r.Title)
                           .ToList();

            if (navItems != null && navItems.Count > 0)
            {
                if (githubUri.IsMarkdownFile)
                {
                    navItems.First(n => n.Uri.EndsWith(githubUri.FilePath)).IsDefault = true;
                }
                else if (navItems.Any(n => n.Uri.EndsWith(README)))
                {
                    navItems.First(n => n.Uri.EndsWith(README)).IsDefault = true;
                }
                else if (navItems.Any(n => GithubUri.CheckIfMarkdownFile(n.Uri)))
                {
                    navItems.First(n => GithubUri.CheckIfMarkdownFile(n.Uri)).IsDefault = true;
                }
            }

            return(navItems);
        }
Example #2
0
        private async Task <string> DownloadMarkdownFileAsync(string owner, string repoName, string filePath)
        {
            if (!GithubUri.CheckIfMarkdownFile(filePath))
            {
                return("");
            }

            var file = await _githubRepo.GetFileContentAsync(owner, repoName, filePath);

            return(file.Content);
        }
Example #3
0
        private async Task <string> GetFilePathOrDefaultAsync(GithubUri githubUri)
        {
            if (!string.IsNullOrWhiteSpace(githubUri.FilePath))
            {
                return(githubUri.FilePath);
            }

            var _files = await _githubRepo.GetAllContentsAsync(githubUri.Owner, githubUri.RepoName, "");

            return(_files.First(f => GithubUri.CheckIfMarkdownFile(f.Name)).Path);
        }