Skip to content

Commit 4d95e50

Browse files
Fix: Correct docs generation and GitHub workflow
This commit addresses several issues in the documentation generation process: 1. **`docs/scripts/generate_site_data.py`:** * Modified to scan actual root-level language directories (e.g., C, Python) instead of a non-existent `code_examples/` directory. * Updated to fetch Git commit history from the entire repository, providing a more accurate "Recent Activity" feed. * Removed the unused `code_examples_dir` creation. 2. **`docs/index.html`:** * Corrected the language details modal to display actual filenames (using `file.name`) instead of `[object Object]`. * Updated to use language icons provided in `site_data.json` directly, removing the local `languageIcons` map. 3. **`.github/workflows/generate_docs.yml`:** * Adjusted the `paths` trigger to monitor actual language directories (e.g., `C/**`, `Python/**`) for changes, ensuring the workflow runs when relevant code is updated. * Removed the unnecessary `pip install pyyaml` step, as the script uses the standard `json` library. 4. **`docs/README.md`:** * Updated to accurately describe the new behavior of the `generate_site_data.py` script, including how it scans directories and fetches Git history. These changes ensure that the documentation website accurately reflects the content of the repository and that the generation process is robust and efficient.
1 parent 738340d commit 4d95e50

4 files changed

Lines changed: 35 additions & 21 deletions

File tree

.github/workflows/generate_docs.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ on:
55
branches:
66
- main
77
paths:
8-
- 'code_examples/**'
8+
- 'C/**'
9+
- 'C#/**'
10+
- 'C++/**'
11+
- 'Go/**'
12+
- 'Html/**'
13+
- 'Java/**'
14+
- 'Javascript/**'
15+
- 'PHP/**'
16+
- 'Python/**'
17+
- 'Rust/**'
18+
- 'typescript/**'
919
- 'docs/scripts/generate_site_data.py'
1020
schedule:
1121
- cron: '0 0 * * *'
@@ -29,7 +39,7 @@ jobs:
2939
python-version: '3.10'
3040

3141
- name: Install dependencies
32-
run: pip install pyyaml
42+
run: echo "No Python dependencies to install beyond standard library"
3343

3444
- name: Generate site data
3545
run: python docs/scripts/generate_site_data.py

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ The website dynamically displays:
1414
This information is sourced from the `docs/site_data.json` file.
1515

1616
The `docs/site_data.json` file is, in turn, generated by the Python script located at `docs/scripts/generate_site_data.py`. This script now:
17-
1. Scans the root of the repository to identify language-specific directories.
18-
2. For each language directory, it scans its top-level contents (files and sub-directories), excluding common build artifacts and hidden files, to gather the detailed file/project list.
19-
3. Fetches the latest commit history using Git commands.
17+
1. Scans the root of the repository (e.g., `../../` from its own location) to identify language-specific directories by looking for top-level folders that are not hidden (e.g., not starting with a `.`) and are not common non-code directories like `docs/`, `.git/`, or `.github/`.
18+
2. For each identified language directory, it recursively scans for files with supported extensions (e.g., `.py`, `.js`, `.java`) to gather information like filename, size, and last modified date.
19+
3. Fetches the latest commit history using Git commands for the entire repository.
2020
The script then compiles this information into the `site_data.json` file.
2121

2222
## Updating the Website Content

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ <h3 class="modal-title" id="modal-title">Language Details</h3>
907907
card.className = 'language-card fade-in';
908908
card.innerHTML = `
909909
<div class="language-header">
910-
<div class="language-icon">${languageIcons[language.name] || language.name.charAt(0)}</div>
910+
<div class="language-icon">${language.icon || language.name.charAt(0)}</div>
911911
<h3 class="language-name">${language.name}</h3>
912912
<span class="language-count">${language.files.length} examples</span>
913913
</div>
@@ -956,7 +956,7 @@ <h3 class="language-name">${language.name}</h3>
956956
language.files.forEach(file => {
957957
const fileItem = document.createElement('div');
958958
fileItem.className = 'file-item';
959-
fileItem.textContent = file;
959+
fileItem.textContent = file.name;
960960
fileGrid.appendChild(fileItem);
961961
});
962962

docs/scripts/generate_site_data.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def get_git_history():
99
"""Get real Git commit history for recent activity"""
1010
try:
11-
cmd = ['git', 'log', '--pretty=format:%an|%s|%cd', '--date=short', '-n', '5', '--', 'code_examples/']
11+
cmd = ['git', 'log', '--pretty=format:%an|%s|%cd', '--date=short', '-n', '5']
1212
result = subprocess.run(cmd, capture_output=True, text=True)
1313
activity = []
1414

@@ -70,16 +70,21 @@ def get_file_info(root, filename):
7070
"last_modified": datetime.fromtimestamp(os.path.getmtime(filepath)).strftime('%Y-%m-%d')
7171
}
7272

73-
def scan_code_examples(code_examples_dir):
74-
"""Scan the code examples directory and return structured data"""
73+
def scan_code_examples(base_dir):
74+
"""Scan the base directory for language directories and return structured data"""
7575
languages = []
76-
77-
for lang_dir in sorted(os.listdir(code_examples_dir)):
78-
lang_path = os.path.join(code_examples_dir, lang_dir)
79-
if not os.path.isdir(lang_path):
80-
continue
81-
82-
lang_files = []
76+
excluded_dirs = ['.git', 'docs', '.github', 'site_data_files']
77+
78+
for item_name in sorted(os.listdir(base_dir)):
79+
item_path = os.path.join(base_dir, item_name)
80+
if os.path.isdir(item_path) and \
81+
not item_name.startswith('.') and \
82+
item_name not in excluded_dirs:
83+
84+
lang_dir = item_name # item_name is now the language directory
85+
lang_path = item_path # path to the language directory
86+
87+
lang_files = []
8388
supported_extensions = ('.py', '.js', '.java', '.c', '.cpp', '.cs',
8489
'.go', '.rs', '.php', '.html', '.ts', '.sh')
8590

@@ -124,12 +129,11 @@ def get_language_icon(lang_name):
124129

125130
def generate_site_data():
126131
"""Generate the complete site data structure"""
127-
code_examples_dir = "code_examples"
128-
os.makedirs(code_examples_dir, exist_ok=True)
129-
132+
base_dir = "../../" # Point to the repository root
133+
130134
return {
131135
"last_updated": datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
132-
"languages": scan_code_examples(code_examples_dir),
136+
"languages": scan_code_examples(base_dir),
133137
"recent_activity": get_git_history(),
134138
"stats": {
135139
"total_languages": 0, # Will be updated after

0 commit comments

Comments
 (0)