Skip to content

Commit 1dd210c

Browse files
committed
adjust docs UI
1 parent b66bae2 commit 1dd210c

2 files changed

Lines changed: 49 additions & 12 deletions

File tree

codewiki/src/be/documentation_generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ async def generate_module_documentation(self, components: Dict[str, Any], leaf_n
186186
repo_name, components, leaf_nodes, [], working_dir
187187
)
188188

189+
# save final_module_tree to module_tree.json
190+
file_manager.save_json(final_module_tree, os.path.join(working_dir, MODULE_TREE_FILENAME))
191+
189192
# rename repo_name.md to overview.md
190193
repo_overview_path = os.path.join(working_dir, f"{repo_name}.md")
191194
if os.path.exists(repo_overview_path):

codewiki/templates/github_pages/app.js

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,54 @@
2828

2929
handleRoute() {
3030
const hash = window.location.hash.slice(1) || '/';
31-
const path = hash === '/' ? 'overview.md' : hash;
31+
// Remove leading slash if present
32+
const cleanHash = hash.startsWith('/') ? hash.slice(1) : hash;
33+
const path = (hash === '/' || cleanHash === '') ? 'overview.md' : cleanHash;
3234
this.loadMarkdown(path);
3335
this.updateBreadcrumbs(path);
3436
}
3537

3638
async loadMarkdown(filename) {
39+
const content = document.getElementById('markdown-content');
40+
41+
// Show loading state
42+
content.innerHTML = '<div class="loading">Loading...</div>';
43+
3744
try {
3845
const response = await fetch(filename);
39-
if (!response.ok) throw new Error(`Failed to load ${filename}`);
46+
if (!response.ok) {
47+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
48+
}
4049
const markdown = await response.text();
4150
this.renderMarkdown(markdown);
51+
this.updateActiveLink(filename);
4252
} catch (error) {
4353
console.error('Error loading markdown:', error);
44-
const content = document.getElementById('markdown-content');
45-
content.innerHTML = `<h1>Error</h1><p>Could not load ${filename}</p>`;
54+
content.innerHTML = `
55+
<h1>📄 Document Not Found</h1>
56+
<p>Could not load <code>${filename}</code></p>
57+
<p style="color: #6a737d; font-size: 0.9rem;">
58+
${error.message}
59+
</p>
60+
<p>
61+
<a href="#/" style="color: #0366d6;">← Back to Overview</a>
62+
</p>
63+
`;
4664
}
4765
}
4866

67+
updateActiveLink(filename) {
68+
// Update active state on navigation links
69+
document.querySelectorAll('.nav-link').forEach(link => {
70+
link.classList.remove('active');
71+
const linkPath = link.getAttribute('href').replace('#/', '').replace('#', '');
72+
const currentPath = filename;
73+
if (linkPath === currentPath || (linkPath === '' && filename === 'overview.md')) {
74+
link.classList.add('active');
75+
}
76+
});
77+
}
78+
4979
renderMarkdown(markdown) {
5080
const html = marked.parse(markdown);
5181
const content = document.getElementById('markdown-content');
@@ -70,15 +100,23 @@
70100

71101
updateBreadcrumbs(path) {
72102
const breadcrumbs = document.getElementById('breadcrumbs');
103+
104+
// Handle overview case
105+
if (path === 'overview.md') {
106+
breadcrumbs.innerHTML = '<a href="#/">Home</a>';
107+
return;
108+
}
109+
73110
const parts = path.split('/').filter(p => p);
74111

75112
let html = '<a href="#/">Home</a>';
76113
let currentPath = '';
77114

78115
for (const part of parts) {
79-
currentPath += '/' + part;
116+
currentPath += (currentPath ? '/' : '') + part;
80117
html += ' <span class="separator">›</span> ';
81-
html += `<a href="#${currentPath}">${part.replace('.md', '')}</a>`;
118+
const displayName = formatModuleName(part.replace('.md', ''));
119+
html += `<a href="#/${currentPath}">${displayName}</a>`;
82120
}
83121

84122
breadcrumbs.innerHTML = html;
@@ -102,11 +140,7 @@
102140
link.textContent = formatModuleName(moduleName);
103141
link.className = 'nav-link';
104142

105-
// Highlight active link
106-
link.addEventListener('click', function() {
107-
document.querySelectorAll('.nav-link').forEach(l => l.classList.remove('active'));
108-
this.classList.add('active');
109-
});
143+
// Active link highlighting is handled by updateActiveLink in the router
110144

111145
item.appendChild(link);
112146
container.appendChild(item);
@@ -210,7 +244,7 @@
210244
const overviewLink = document.createElement('a');
211245
overviewLink.href = '#/';
212246
overviewLink.textContent = 'Overview';
213-
overviewLink.className = 'nav-link active';
247+
overviewLink.className = 'nav-link'; // Active state will be set by router
214248
overviewItem.appendChild(overviewLink);
215249
navTree.appendChild(overviewItem);
216250

0 commit comments

Comments
 (0)