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);
        }
Beispiel #2
0
        public virtual async Task Build(IList <T> data)
        {
            FSStaticBuilder.EnsureDirectoryEmpty(RootPath);
            FSStaticBuilder.EnsureDirectoryEmpty(Paths.GetDataRoot(RootPath));
            FSStaticBuilder.EnsureDirectoryEmpty(Paths.GetConfigRoot(RootPath));
            FSStaticBuilder.EnsureDirectoryEmpty(Paths.GetIndexRoot(RootPath));

            await BuildData(data).ConfigureAwait(false);
        }
        async Task BuildRouteIndex(IList <Page> data)
        {
            var gr = from x in data group x by x.Route;

            foreach (var g in gr)
            {
                string path = Paths.GetRouteFile(RootPath, g.Key);
                await using var st = FSStaticBuilder.GetFileRewriteStream(path);
                await JsonSerializer.SerializeAsync(st, (from p in g select p.Id).ToArray()).ConfigureAwait(false);
            }
        }
        public void Setup()
        {
            RootPath = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Guid.NewGuid().ToString());
            FSStaticBuilder.EnsureDirectoryExists(RootPath);

            PostData   = Enumerable.Range(0, Length).Select(x => Generator.GetPost()).ToArray();
            LayoutData = Enumerable.Range(0, Length).Select(x => Generator.GetLayout()).ToArray();
            PageData   = Enumerable.Range(0, Length).Select(x => Generator.GetPage()).ToArray();
            FileData   = Enumerable.Range(0, Length).Select(x => Generator.GetFile()).ToArray();

            Builder = new BlogBuilder(new BlogOptions(), RootPath);
        }
Beispiel #5
0
        protected virtual async Task BuildData(IList <T> data)
        {
            List <TId> ids = new List <TId>();

            foreach (var v in data)
            {
                var id = v.Id?.ToString() ?? throw new NullReferenceException(nameof(v.Id));
                await using var st = FSStaticBuilder.GetFileRewriteStream(Paths.GetDataFile(RootPath, id));
                await JsonSerializer.SerializeAsync(st, v).ConfigureAwait(false);

                ids.Add(v.Id);
            }

            await BuildDataIdList(ids, Paths.GetConfigRoot(RootPath)).ConfigureAwait(false);
        }
        async Task BuildIndexKeyword(IList <Post> data)
        {
            FSStaticBuilder.EnsureDirectoryEmpty(Paths.GetKeywordRoot(RootPath));

            var(collection, map) = await KeywordCollectionBuilder.BuildFromPosts(data.ToAsyncEnumerable());

            foreach (var v in collection.Items)
            {
                await BuildDataIdList(map[v.OneName()].Select(x => x.Id).ToArray(),
                                      Paths.GetKeywordRoot(RootPath, v)).ConfigureAwait(false);
            }

            await using var st = FSStaticBuilder.GetFileRewriteStream(Paths.GetKeywordMetadata(RootPath));
            await JsonSerializer.SerializeAsync(st, collection).ConfigureAwait(false);
        }
Beispiel #7
0
        protected virtual async Task BuildDataIdList(IList <TId> dataIds, string rootPath)
        {
            {
                var stats = new QueryStatistic
                {
                    Count = dataIds.Count
                };
                await using var st = FSStaticBuilder.GetFileRewriteStream(Paths.GetStatisticFile(rootPath));
                await JsonSerializer.SerializeAsync(st, stats).ConfigureAwait(false);
            }

            {
                await using var st = FSStaticBuilder.GetFileRewriteStream(Paths.GetIdListFile(rootPath));
                await JsonSerializer.SerializeAsync(st, dataIds).ConfigureAwait(false);
            }
        }
Beispiel #8
0
        public async Task Setup()
        {
            RootPath = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "fstest");
            FSStaticBuilder.EnsureDirectoryExists(RootPath);

            PostData        = Enumerable.Range(0, 100).Select(x => Generator.GetPost()).ToArray();
            LayoutData      = Enumerable.Range(0, 100).Select(x => Generator.GetLayout()).ToArray();
            PageData        = Enumerable.Range(0, 100).Select(x => Generator.GetPage()).ToArray();
            FileData        = Enumerable.Range(0, 100).Select(x => Generator.GetFile()).ToArray();
            BlogOptionsData = new BlogOptions();

            BlogBuilder builder = new BlogBuilder(BlogOptionsData, RootPath);
            await builder.Build();

            await builder.BuildPosts(PostData);

            await builder.BuildLayouts(LayoutData);

            await builder.BuildPages(PageData);

            await builder.BuildFiles(FileData);

            BlogService = new FileSystemBlogService(new PhysicalFileProvider(RootPath).AsFileProvider());
        }
 public void Cleanup()
 {
     FSStaticBuilder.EnsureDirectoryExists(RootPath, false);
 }
Beispiel #10
0
 public RecordFSRepo(string rootPath) : base(rootPath)
 {
     FSStaticBuilder.EnsureDirectoryExists(rootPath);
     FileProvider = new PhysicalFileProvider(rootPath).AsFileProvider();
 }