Exemple #1
0
        async Task BuildIndexCategory()
        {
            FsBuilder.EnsureDirectoryEmpty("categories");

            var(tree, map) = CategoryTreeBuilder.BuildFromPosts(Data);

            Queue <CategoryTree.Node> q = new Queue <CategoryTree.Node>();

            foreach (var v in tree.Root.Children.Values)
            {
                q.Enqueue(v);
            }

            while (q.Count > 0)
            {
                var node = q.Dequeue();

                string subdir = Path.Join("categories", Path.Combine(node.Category.Items.Select(NameUtility.Encode).ToArray()));

                PagingProvider <string> paging = new PagingProvider <string>(Path.Join(RootPath, subdir));

                await paging.Build(map[node].Select(x => x.Id).ToArray(),
                                   PagingConfig).ConfigureAwait(false);

                foreach (var v in node.Children.Values)
                {
                    q.Enqueue(v);
                }
            }

            using var st = FsBuilder.GetFileRewriteStream("categories/all.json");
            await JsonSerializer.SerializeAsync(st, tree).ConfigureAwait(false);
        }
        async Task BuildIndexCategory(IList <Post> data)
        {
            FSStaticBuilder.EnsureDirectoryEmpty(Paths.GetCategoryRoot(RootPath));

            var(tree, map) = await CategoryTreeBuilder.BuildFromPosts(data.ToAsyncEnumerable());

            Queue <CategoryTree.CategoryTreeNode> q = new Queue <CategoryTree.CategoryTreeNode>();

            foreach (var v in tree.Root.Children.Values)
            {
                q.Enqueue(v);
            }

            while (q.Count > 0)
            {
                var node = q.Dequeue();

                await BuildDataIdList(map[node].Select(x => x.Id).ToArray(),
                                      Paths.GetCategoryRoot(RootPath, node.Category)).ConfigureAwait(false);

                foreach (var v in node.Children.Values)
                {
                    q.Enqueue(v);
                }
            }

            await using var st = FSStaticBuilder.GetFileRewriteStream(Paths.GetCategoryMetadata(RootPath));
            await JsonSerializer.SerializeAsync(st, tree).ConfigureAwait(false);
        }