|
| 1 | +# HTMLGenerator and Template Improvements |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Updated the HTMLGenerator class and its associated templates based on the frontend code and generated documentation examples. The improvements enable automatic loading of module trees and metadata, better navigation rendering, and enhanced user experience. |
| 6 | + |
| 7 | +## Changes Made |
| 8 | + |
| 9 | +### 1. HTMLGenerator Class (`codewiki/cli/html_generator.py`) |
| 10 | + |
| 11 | +#### New Methods |
| 12 | + |
| 13 | +**`load_module_tree(docs_dir: Path)`** |
| 14 | +- Automatically loads `module_tree.json` from the documentation directory |
| 15 | +- Provides fallback structure if file doesn't exist |
| 16 | +- Returns properly structured module tree for navigation rendering |
| 17 | + |
| 18 | +**`load_metadata(docs_dir: Path)`** |
| 19 | +- Loads `metadata.json` from the documentation directory |
| 20 | +- Returns None if not found (non-critical) |
| 21 | +- Enables display of generation information in the viewer |
| 22 | + |
| 23 | +#### Updated `generate()` Method |
| 24 | + |
| 25 | +**New Parameters:** |
| 26 | +- `docs_dir`: Documentation directory path for auto-loading |
| 27 | +- `metadata`: Metadata dictionary (auto-loaded if docs_dir provided) |
| 28 | +- `module_tree`: Now optional, auto-loaded from docs_dir if not provided |
| 29 | + |
| 30 | +**Key Improvements:** |
| 31 | +- Auto-loads module_tree.json and metadata.json when docs_dir is provided |
| 32 | +- Embeds metadata in the configuration for client-side display |
| 33 | +- Maintains backward compatibility with existing code |
| 34 | + |
| 35 | +**Before:** |
| 36 | +```python |
| 37 | +html_generator.generate( |
| 38 | + output_path=output_path, |
| 39 | + title=title, |
| 40 | + module_tree=manual_module_tree, # Had to be manually provided |
| 41 | + repository_url=url |
| 42 | +) |
| 43 | +``` |
| 44 | + |
| 45 | +**After:** |
| 46 | +```python |
| 47 | +html_generator.generate( |
| 48 | + output_path=output_path, |
| 49 | + title=title, |
| 50 | + docs_dir=output_dir, # Auto-loads module_tree and metadata |
| 51 | + repository_url=url |
| 52 | +) |
| 53 | +``` |
| 54 | + |
| 55 | +### 2. Documentation Generator Adapter (`codewiki/cli/adapters/doc_generator.py`) |
| 56 | + |
| 57 | +#### Updated `_run_html_generation()` Method |
| 58 | + |
| 59 | +**Before:** |
| 60 | +- Created placeholder module tree with just "Overview" |
| 61 | +- Ignored the actual generated module structure |
| 62 | +- No metadata integration |
| 63 | + |
| 64 | +**After:** |
| 65 | +- Uses `docs_dir` parameter for automatic loading |
| 66 | +- Properly loads the module_tree.json generated in stage 2 |
| 67 | +- Automatically loads metadata.json for display |
| 68 | +- Adds progress update for loading phase |
| 69 | + |
| 70 | +### 3. JavaScript Application (`codewiki/templates/github_pages/app.js`) |
| 71 | + |
| 72 | +#### Enhanced Navigation Rendering |
| 73 | + |
| 74 | +**`renderNavTree()` Function:** |
| 75 | +- Improved recursive rendering for deeply nested structures |
| 76 | +- Skips metadata properties ('description', 'components') in iteration |
| 77 | +- Better handling of module data objects |
| 78 | +- Properly renders children at any depth level |
| 79 | + |
| 80 | +**New `formatModuleName()` Function:** |
| 81 | +- Converts underscores and hyphens to spaces |
| 82 | +- Capitalizes each word for better readability |
| 83 | +- Example: `search_providers` → `Search Providers` |
| 84 | + |
| 85 | +**New `renderMetadata()` Function:** |
| 86 | +- Creates styled metadata info box for sidebar |
| 87 | +- Displays generation information: |
| 88 | + - Model used for generation |
| 89 | + - Timestamp (formatted as locale string) |
| 90 | + - Commit ID (first 8 characters) |
| 91 | + - Total components count |
| 92 | +- Returns null if no metadata available |
| 93 | + |
| 94 | +#### Updated `init()` Function |
| 95 | + |
| 96 | +**Additions:** |
| 97 | +- Renders metadata info box in sidebar after overview link |
| 98 | +- Positioned between overview and divider for prominence |
| 99 | +- Only displays if metadata is available in config |
| 100 | + |
| 101 | +### 4. Styles (`codewiki/templates/github_pages/styles.css`) |
| 102 | + |
| 103 | +#### Navigation Improvements |
| 104 | + |
| 105 | +**Font Sizing for Nested Levels:** |
| 106 | +- Base level: 0.875rem |
| 107 | +- Second level (2rem padding): 0.8125rem, subdued color |
| 108 | +- Third level (3rem padding): 0.75rem, more subdued color |
| 109 | +- Improves visual hierarchy for deep structures |
| 110 | + |
| 111 | +**New Metadata Box Styling:** |
| 112 | +- Dedicated `.metadata-box` class |
| 113 | +- Consistent styling with theme |
| 114 | +- Proper spacing and borders |
| 115 | + |
| 116 | +#### Content Enhancements |
| 117 | + |
| 118 | +**Blockquote Styling:** |
| 119 | +- Blue left border (matches theme) |
| 120 | +- Light background |
| 121 | +- Proper padding and margins |
| 122 | + |
| 123 | +**Image Handling:** |
| 124 | +- `max-width: 100%` for responsiveness |
| 125 | +- Auto height to maintain aspect ratio |
| 126 | +- Rounded corners (6px) |
| 127 | +- Proper margins |
| 128 | + |
| 129 | +**Horizontal Rules:** |
| 130 | +- Clean, minimal styling |
| 131 | +- Consistent with theme colors |
| 132 | +- Generous vertical spacing |
| 133 | + |
| 134 | +**Mermaid Diagrams:** |
| 135 | +- White background for contrast |
| 136 | +- Light border and rounded corners |
| 137 | +- Center alignment |
| 138 | +- Proper padding and margins |
| 139 | + |
| 140 | +**Loading State:** |
| 141 | +- Center-aligned loading indicator |
| 142 | +- Subdued color scheme |
| 143 | +- Adequate padding |
| 144 | + |
| 145 | +#### Layout Improvements |
| 146 | + |
| 147 | +**Footer Support:** |
| 148 | +- `#app` uses `min-height` instead of `height` for proper scrolling |
| 149 | +- `#footer` uses `margin-top: auto` to stick to bottom |
| 150 | +- Proper flex layout for sticky footer |
| 151 | + |
| 152 | +### 5. HTML Template (`codewiki/templates/github_pages/index.html`) |
| 153 | + |
| 154 | +#### New Footer Section |
| 155 | + |
| 156 | +**Added:** |
| 157 | +- Footer with CodeWiki attribution |
| 158 | +- Positioned at bottom of page |
| 159 | +- Subtle styling with theme colors |
| 160 | +- Link to project (placeholder for actual URL) |
| 161 | + |
| 162 | +**Benefits:** |
| 163 | +- Professional appearance |
| 164 | +- Clear attribution |
| 165 | +- Consistent with modern web practices |
| 166 | + |
| 167 | +## Benefits of These Improvements |
| 168 | + |
| 169 | +### 1. Automated Data Loading |
| 170 | +- No need to manually load module_tree.json |
| 171 | +- Metadata automatically integrated |
| 172 | +- Reduces code duplication |
| 173 | +- Fewer errors from manual data handling |
| 174 | + |
| 175 | +### 2. Better Navigation |
| 176 | +- Proper rendering of nested module structures |
| 177 | +- Clear visual hierarchy |
| 178 | +- Better readability with formatted names |
| 179 | +- Supports arbitrary nesting depth |
| 180 | + |
| 181 | +### 3. Enhanced User Experience |
| 182 | +- Generation information visible in sidebar |
| 183 | +- Model, timestamp, commit info at a glance |
| 184 | +- Better understanding of documentation provenance |
| 185 | +- Professional appearance with footer |
| 186 | + |
| 187 | +### 4. Improved Styling |
| 188 | +- Better support for nested navigation |
| 189 | +- Enhanced markdown rendering |
| 190 | +- Responsive images |
| 191 | +- Proper mermaid diagram display |
| 192 | +- Sticky footer layout |
| 193 | + |
| 194 | +### 5. Code Quality |
| 195 | +- Better separation of concerns |
| 196 | +- More reusable components |
| 197 | +- Improved error handling |
| 198 | +- Backward compatible |
| 199 | + |
| 200 | +## Testing Recommendations |
| 201 | + |
| 202 | +1. **Test with Real Repository:** |
| 203 | + ```bash |
| 204 | + cd /path/to/test-repo |
| 205 | + codewiki generate --github-pages |
| 206 | + ``` |
| 207 | + |
| 208 | +2. **Verify Module Tree Rendering:** |
| 209 | + - Check that all nested modules appear |
| 210 | + - Verify indentation and hierarchy |
| 211 | + - Test navigation clicks |
| 212 | + |
| 213 | +3. **Check Metadata Display:** |
| 214 | + - Verify generation info box appears |
| 215 | + - Check model name display |
| 216 | + - Verify timestamp formatting |
| 217 | + - Test with and without commit ID |
| 218 | + |
| 219 | +4. **Test Responsive Design:** |
| 220 | + - View on mobile devices |
| 221 | + - Test sidebar toggle |
| 222 | + - Verify navigation usability |
| 223 | + - Check content readability |
| 224 | + |
| 225 | +5. **Verify Markdown Rendering:** |
| 226 | + - Test code blocks with syntax highlighting |
| 227 | + - Verify mermaid diagram rendering |
| 228 | + - Check image display |
| 229 | + - Test blockquotes and lists |
| 230 | + |
| 231 | +## Migration Guide |
| 232 | + |
| 233 | +### For Existing Code |
| 234 | + |
| 235 | +**Old usage:** |
| 236 | +```python |
| 237 | +html_generator = HTMLGenerator() |
| 238 | +module_tree = load_some_module_tree() |
| 239 | +html_generator.generate( |
| 240 | + output_path=output_path, |
| 241 | + title=title, |
| 242 | + module_tree=module_tree |
| 243 | +) |
| 244 | +``` |
| 245 | + |
| 246 | +**New usage (recommended):** |
| 247 | +```python |
| 248 | +html_generator = HTMLGenerator() |
| 249 | +html_generator.generate( |
| 250 | + output_path=output_path, |
| 251 | + title=title, |
| 252 | + docs_dir=docs_directory # Auto-loads everything |
| 253 | +) |
| 254 | +``` |
| 255 | + |
| 256 | +**Still supported (backward compatible):** |
| 257 | +```python |
| 258 | +html_generator = HTMLGenerator() |
| 259 | +html_generator.generate( |
| 260 | + output_path=output_path, |
| 261 | + title=title, |
| 262 | + module_tree=manually_loaded_tree # Still works |
| 263 | +) |
| 264 | +``` |
| 265 | + |
| 266 | +## Future Enhancements |
| 267 | + |
| 268 | +Potential improvements for future iterations: |
| 269 | + |
| 270 | +1. **Search Functionality:** |
| 271 | + - Full-text search across documentation |
| 272 | + - Module/component search |
| 273 | + - Code snippet search |
| 274 | + |
| 275 | +2. **Dark Mode:** |
| 276 | + - Theme toggle |
| 277 | + - System preference detection |
| 278 | + - Persistent user preference |
| 279 | + |
| 280 | +3. **Table of Contents:** |
| 281 | + - Auto-generated from headers |
| 282 | + - Sticky sidebar TOC |
| 283 | + - Smooth scrolling |
| 284 | + |
| 285 | +4. **Dependency Graphs:** |
| 286 | + - Interactive visualization |
| 287 | + - Load from temp/dependency_graphs |
| 288 | + - Zoom and pan support |
| 289 | + |
| 290 | +5. **Code Copy Button:** |
| 291 | + - One-click code copying |
| 292 | + - Visual feedback |
| 293 | + - Syntax-aware copying |
| 294 | + |
| 295 | +6. **Version Selector:** |
| 296 | + - Multiple doc versions |
| 297 | + - Comparison view |
| 298 | + - Changelog integration |
| 299 | + |
| 300 | +## Files Modified |
| 301 | + |
| 302 | +1. `/Users/anhnh/Documents/vscode/CodeWiki/codewiki/cli/html_generator.py` |
| 303 | +2. `/Users/anhnh/Documents/vscode/CodeWiki/codewiki/cli/adapters/doc_generator.py` |
| 304 | +3. `/Users/anhnh/Documents/vscode/CodeWiki/codewiki/templates/github_pages/app.js` |
| 305 | +4. `/Users/anhnh/Documents/vscode/CodeWiki/codewiki/templates/github_pages/styles.css` |
| 306 | +5. `/Users/anhnh/Documents/vscode/CodeWiki/codewiki/templates/github_pages/index.html` |
| 307 | + |
| 308 | +## Conclusion |
| 309 | + |
| 310 | +These improvements bring the CLI's HTMLGenerator in line with the frontend implementation while maintaining backward compatibility and adding new features. The auto-loading functionality significantly simplifies usage, while the enhanced navigation and metadata display provide a better user experience. |
| 311 | + |
0 commit comments