예제 #1
0
        public Task IndexContentFiles()
        {
            logger.LogInformation("Loading posts from disk...");
            this.Posts.Clear();

            if (string.IsNullOrWhiteSpace(webHostEnvironment.WebRootPath))
            {
                webHostEnvironment.WebRootPath =
                    Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
            }

            var contentPath = Path.Combine(webHostEnvironment.WebRootPath, "posts");

            Posts = Directory.GetDirectories(contentPath)
                    .Select(dir => Path.Combine(dir, "index.md"))
                    .Select(ParseMetadataPrivate)
                    .Where(m => m != null)
                    .OrderByDescending(x => x.PublicationDate)
                    .ToList();

            logger.LogInformation("Loaded {0} posts", Posts.Count);

            this.Posts = postFileSorter.Sort(this.Posts);

            return(Task.CompletedTask);
        }
예제 #2
0
        public async Task IndexContentFiles()
        {
            this.Posts.Clear();

            BlobContainerClient container =
                new BlobContainerClient(config.ConnectionString, config.Container);

            await container.CreateIfNotExistsAsync();

            await foreach (BlobItem blobItem in container.GetBlobsAsync())
            {
                if (blobItem.Name.EndsWith("index.md"))
                {
                    logger.LogInformation($"Indexing {blobItem.Name}");
                    var blobClient = new BlobClient(config.ConnectionString, config.Container, blobItem.Name);
                    var reader     = new StreamReader(blobClient.Download().Value.Content);
                    var post       = ReadPost(reader).Result;
                    Posts.Add(post);
                }
            }

            this.Posts = postFileSorter.Sort(this.Posts);
        }