This commit is contained in:
2025-05-19 05:44:23 +04:00
parent cb664b2115
commit f9bdb22c67
4 changed files with 2 additions and 135 deletions

View File

@@ -1,52 +0,0 @@
# Docusaurus Library Code Review
This document outlines potential issues and suggested improvements for the Docusaurus library.
## Critical Issues
1. **Unexpected Program Termination**
- In `dsite.v` line 205, there's an `exit(0)` call in the `process_md` method.
- This will terminate the entire program unexpectedly when processing markdown files.
- **Recommendation**: Remove the `exit(0)` call and allow the function to complete normally.
2. **Function Signature Mismatch**
- In `clean.v` line 6, the `clean` method requires an `ErrorArgs` parameter: `pub fn (mut site DocSite) clean(args ErrorArgs) !`
- In `dsite.v` line 62, the function is called without arguments: `s.clean()!`
- **Recommendation**: Either make the parameter optional or update all calling code to provide the required argument.
## General Improvements
1. **Incomplete Example**
- The example file `docusaurus_example.vsh` is incomplete, only showing initialization.
- **Recommendation**: Complete the example with site creation, configuration, and building/development operations.
2. **Commented Code**
- There are several instances of commented-out code, such as in the `factory.v` file.
- **Recommendation**: Either complete the implementation of these features or remove the commented code for clarity.
3. **Debug Statements**
- The `process_md` method contains debug print statements (`println(myfm)` and `println(mymd.markdown()!)`)
- **Recommendation**: Replace with a proper logging system or remove if not needed for production.
4. **Error Handling**
- Some error handling could be improved with more descriptive error messages.
- **Recommendation**: Add more context to error messages, especially in file operations.
5. **Documentation**
- While the config structures have some documentation, many methods lack proper documentation.
- **Recommendation**: Add proper V-doc style comments to all public methods and structures.
## Architectural Suggestions
1. **Configuration Management**
- Consider providing a more fluent API for configuration, rather than requiring JSON file manipulation.
2. **Dependency Injection**
- The factory pattern is well-implemented, but consider making dependencies more explicit.
3. **Testing**
- No tests were found in the codebase.
- **Recommendation**: Add unit tests for critical functions.
4. **Logging**
- Replace direct console output with a proper logging system that can be configured based on environment.

View File

@@ -1,59 +0,0 @@
module docusaurus
import json
import os
// load_config loads all configuration from the specified directory
pub fn load_config(cfg_dir string) !Config {
// Ensure the config directory exists
if !os.exists(cfg_dir) {
return error('Config directory ${cfg_dir} does not exist')
}
// Load and parse footer config
footer_content := os.read_file(os.join_path(cfg_dir, 'footer.json'))!
footer := json.decode(Footer, footer_content)!
// Load and parse main config
main_config_path := os.join_path(cfg_dir, 'main.json')
main_content := os.read_file(main_config_path)!
main := json.decode(Main, main_content) or {
eprintln('${main_config_path} is not in the right format please fix.')
println('
## EXAMPLE OF A GOOD ONE:
- note the list for buildDest and buildDestDev
- note its the full path where the html is pushed too
{
"title": "ThreeFold Web4",
"tagline": "ThreeFold Web4",
"favicon": "img/favicon.png",
"url": "https://docs.threefold.io",
"url_home": "docs/introduction",
"baseUrl": "/",
"image": "img/tf_graph.png",
"metadata": {
"description": "ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet.",
"image": "https://threefold.info/kristof/img/tf_graph.png",
"title": "ThreeFold Docs"
},
"buildDest":["root@info.ourworld.tf:/root/hero/www/info/tfgrid4"],
"buildDestDev":["root@info.ourworld.tf:/root/hero/www/infodev/tfgrid4"]
}
')
exit(99)
}
// Load and parse navbar config
navbar_content := os.read_file(os.join_path(cfg_dir, 'navbar.json'))!
navbar := json.decode(Navbar, navbar_content)!
return Config{
footer: footer
main: main
navbar: navbar
}
}

View File

@@ -5,8 +5,8 @@ import os
import freeflowuniverse.herolib.core.pathlib
// import freeflowuniverse.herolib.ui.console
// import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.ui.console
// import freeflowuniverse.herolib.develop.gittools
// import freeflowuniverse.herolib.ui.console
@[heap]
pub struct DocusaurusFactory {
@@ -45,28 +45,6 @@ pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
// path_publish: pathlib.get_dir(path: args_.publish_path, create: true)!
}
// Process HeroScript
mut heroscript_text := args.heroscript
mut heroscript_path := args.heroscript_path
// If no heroscript is explicitly provided, check current directory
if heroscript_text == '' && heroscript_path == '' {
// First check if there's a .heroscript file in the current directory
current_dir := os.getwd()
cfg_dir := os.join_path(current_dir, 'cfg')
if os.exists(cfg_dir) {
heroscript_path = cfg_dir
}
}
// Process any HeroScript that was found
if heroscript_text != '' || heroscript_path != '' {
ds.config = play(
heroscript: heroscript_text
heroscript_path: heroscript_path
)!
}
ds.template_install(install: true, template_update: args.update, delete: true)!
return ds