Refactor directory structure creation and enhance documentation generation

- Simplified the creation of output directory structure in `init_project` and `generate_docs` functions.
- Added a `sanitize_filename` function to ensure valid filenames for generated documentation files.
- Implemented individual documentation file creation for modules and files in the `generate_docs` function.
- Updated links in the renderer to use the new `sanitize_for_link` function for safe URL generation.
- Adjusted the `extract_docstring` method in `PythonAnalyzer` to accept the body parameter without using it, preparing for future enhancements.
This commit is contained in:
2026-01-25 20:38:49 +03:00
parent 3701cee205
commit df50701764
3 changed files with 57 additions and 11 deletions

View File

@@ -6,6 +6,16 @@
use crate::model::ProjectModel;
use handlebars::Handlebars;
fn sanitize_for_link(filename: &str) -> String {
filename
.chars()
.map(|c| match c {
'/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' => '_',
c => c,
})
.collect()
}
pub struct Renderer {
templates: Handlebars<'static>,
}
@@ -243,7 +253,7 @@ impl Renderer {
layout_items.push(serde_json::json!({
"path": file_doc.path,
"purpose": "Source file",
"link": format!("docs/architecture/files/{}.md", file_id)
"link": format!("docs/architecture/files/{}.md", sanitize_for_link(&file_doc.path))
}));
}
@@ -280,7 +290,7 @@ impl Renderer {
"symbol_count": module.symbols.len(),
"inbound_count": module.inbound_modules.len(),
"outbound_count": module.outbound_modules.len(),
"link": format!("docs/architecture/modules/{}.md", module_id)
"link": format!("docs/architecture/modules/{}.md", sanitize_for_link(module_id))
}));
}