Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR] Refactor management system for post #29

Merged
merged 9 commits into from
Oct 5, 2023
Merged

[PR] Refactor management system for post #29

merged 9 commits into from
Oct 5, 2023

Conversation

Sharp0802
Copy link
Owner

  • Unintuitive design of management system for posts:

Before these commit, blogman adopted a management system for post based on a hash of the directory (hereinafter 'legacy-system'). Because of the characteristic of the legacy-system that uses the hash of the directory, the result URI for each post is confusing and not intuitive.

  • Spaghetti in code:

Before these commits, the SOLID principle was entirely ignored, and the code was confusing to read. These commits make code for a management system for posts tidied and concise.

Work List

  • Abstract tree structure into interfaces
  • Obsess the SOLID principle for file-system-tree and post-tree
  • Remove spaghetti codes

- src/BlogMan/Models/Abstraction/IReadOnlyTree.cs: Create interface of tree
- src/BlogMan/Models/Abstraction/ITree.cs: Create interface of tree
- src/BlogMan/Models/IO/FileSystemTree.cs: Create tree implementation of FileSystemInfo
- src/BlogMan/Models/Posts/PostBranch.cs: Create specialization of PostTree for directories
- src/BlogMan/Models/Posts/PostLeaf.cs: Create specialization of PostTree for files
- src/BlogMan/Models/Posts/PostRoot.cs: Create specialization of PostTree for a root of tree
- src/BlogMan/Models/Posts/PostTree.cs: Create implementation of ITree for posts
- src/BlogMan/Models/PostTree.cs: Delete legacy API
- src/BlogMan/Models/PostTreeNode.cs: Delete legacy API
- src/BlogMan/Models/Utilities/PostUtils.cs: Create utils for post-tree
- src/BlogMan/Models/Utilities/TreeUtils.cs: Create utils for generic tree
- src/BlogMan/Models/Utilities/UriUtils.cs: Create utils for generic uri
- src/BlogMan/Components/GoogleSitemapLinker.cs: Use new post management system
- src/BlogMan/Components/LinkerBase.cs: Use new post management system
- src/BlogMan/Components/RazorTemplateLinker.cs: Use new post management system
- src/BlogMan/Models/TemplateModel.cs: Use new post management system
- src/BlogMan/Resources/post.razor: Keep consistence of quote style
- src/BlogMan/Components/RazorTemplateLinker.cs: Fix compilation error
@Sharp0802 Sharp0802 added the enhancement New feature or request label Oct 3, 2023
@Sharp0802 Sharp0802 self-assigned this Oct 3, 2023
- */*: Remove unnecessary codes with Qodana
- src/qodana.yaml: Add qodana.yaml
- src/BlogMan.sln: Update solution
- src/BlogMan.Test/BlogMan.Test.csproj: Create project for testing
- src/BlogMan.Test/BlogMan.Test.csproj: Add test-case adoption
- src/BlogMan.Test/Program.cs: Add manual-testing line
- src/BlogMan.Test/Resources/.gitignore: GIT should ignore test result
- src/BlogMan.Test/Resoruces/**/*.*: Add test-case
- src/BlogMan.Test/Resources/test.json: Add test-case
- src/BlogMan/Program.cs: Expose entrypoint
@Sharp0802
Copy link
Owner Author

A change for src/BlogMan/Components/Logger.cs in the commit 20939e5 breaks the header and color of a log. Change required!

- src/BlogMan/Components/Logger.cs: Fix mismatched header for log
@Sharp0802
Copy link
Owner Author

Error log from b47a65a in #28:

info: Start preprocessing project
info: sharp0802-github-io: Preprocessing start
info: /home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test-post.md: Preprocessing start
info: /home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test0/test-post-1.md: Preprocessing start
info: /home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test0/test1/test-post-2.md: Preprocessing start
cmpl: '/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test-post.md' -> '/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/build/test-post.md','/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/build/test-post.yaml'
cmpl: '/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test0/test-post-1.md' -> '/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/build/test0/test-post-1.md','/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/build/test0/test-post-1.yaml'
cmpl: /home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test-post.md: Success to preprocess
cmpl: /home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test0/test-post-1.md: Success to preprocess
cmpl: '/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test0/test1/test-post-2.md' -> '/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/build/test0/test1/test-post-2.md','/home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/build/test0/test1/test-post-2.yaml'
cmpl: /home/sharp0802/repos/src/blogman/src/BlogMan.Test/Resources/post/test0/test1/test-post-2.md: Success to preprocess
cmpl: Complete preprocessing project
info: Start building project
Unhandled exception: System.NullReferenceException: Parent node cannot be null
   at BlogMan.Models.Posts.PostTree.<>c__DisplayClass11_0.<Burn>b__1(FileSystemInfo p, FileSystemInfo cur) in /home/sharp0802/repos/src/blogman/src/BlogMan/Models/Posts/PostTree.cs:line 31
   at BlogMan.Models.Utilities.TreeUtils.Burn[TFrom,TTo,TValue](TFrom from, Func`2 selector, BurnDelegate`2 burner) in /home/sharp0802/repos/src/blogman/src/BlogMan/Models/Utilities/TreeUtils.cs:line 50
   at BlogMan.Models.Utilities.TreeUtils.<>c__DisplayClass2_0`3.<Burn>b__0(TFrom child) in /home/sharp0802/repos/src/blogman/src/BlogMan/Models/Utilities/TreeUtils.cs:line 51
   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
   at BlogMan.Models.Posts.PostTree.Set(IEnumerable`1 children) in /home/sharp0802/repos/src/blogman/src/BlogMan/Models/Posts/PostTree.cs:line 42
   at BlogMan.Models.Utilities.TreeUtils.Burn[TFrom,TTo,TValue](TFrom from, Func`2 selector, BurnDelegate`2 burner) in /home/sharp0802/repos/src/blogman/src/BlogMan/Models/Utilities/TreeUtils.cs:line 52
   at BlogMan.Models.Posts.PostTree.Burn(FileSystemTree fst) in /home/sharp0802/repos/src/blogman/src/BlogMan/Models/Posts/PostTree.cs:line 24
   at BlogMan.Components.LinkerBase..ctor(Project project) in /home/sharp0802/repos/src/blogman/src/BlogMan/Components/LinkerBase.cs:line 42
   at BlogMan.Components.RazorTemplateLinker..ctor(Project project) in /home/sharp0802/repos/src/blogman/src/BlogMan/Components/RazorTemplateLinker.cs:line 15
   at BlogMan.Components.Initializer.Build(FileInfo project) in /home/sharp0802/repos/src/blogman/src/BlogMan/Components/Initializer.cs:line 102
   at System.CommandLine.Handler.<>c__DisplayClass2_0`1.<SetHandler>b__0(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.Invoke(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

- src/BlogMan/Components/Initializer.cs:
    - Call cleanup task correctly
    - Update directories in project internally
- src/BlogMan/Components/GoogleSitemapLinker.cs:
    - Fix runtime error when compiling xml
- src/BlogMan/Components/LinkerBase.cs:
    - Provide new cleanup API
    - Merge cleanup task to Initializer: Each linker is a component of pipeline(blogman). if cleanup task is in linker class, result will be reset on each phase of building.
- src/BlogMan/Components/Preprocessor.cs: Always clean build directory
- src/BlogMan/Components/RazorTemplateLinker.cs: Use new cleanup API
- src/BlogMan/Models/Posts/PostLeaf.cs: Reserve index file-name
- src/BlogMan/Models/Posts/PostTree.cs: Simplify filtering condition
- src/BlogMan/Models/Utilities/TreeUtils.cs:
    - Fix broken burning task
        - Fix invalid recursive call
@Sharp0802
Copy link
Owner Author

Tested for only its concepts. LGTM

@Sharp0802 Sharp0802 merged commit 2835d67 into master Oct 5, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant