Skip to content

Commit d494d32

Browse files
generate schema docs index pages.
1 parent 6acc29b commit d494d32

3 files changed

Lines changed: 144 additions & 5 deletions

File tree

docs/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ vendor
77
*Zone.Identifier
88
node_modules
99
_config.version.yml
10-
schema
10+
schemas

docs/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SCHEMA_BASE_INPUT_DIR = ../schemas
66
SCHEMA_INPUT_DIR = $(SCHEMA_BASE_INPUT_DIR)/output
77
SCHEMA_DOCS_INPUT_DIR = $(SCHEMA_BASE_INPUT_DIR)/docs
88
BASE_OUTPUT_DIR = _site
9-
BASE_DOCS_OUTPUT_DIR = schema
9+
BASE_DOCS_OUTPUT_DIR = schemas
1010
SCHEMA_OUTPUT_DIR = $(BASE_OUTPUT_DIR)/schemas
1111
SCHEMA_DOCS_OUTPUT_DIR = $(BASE_DOCS_OUTPUT_DIR)
1212

@@ -29,7 +29,7 @@ define baseurlparam =
2929
$(if $(BASE_URL),-- --baseurl $(BASE_URL),-- --baseurl "")
3030
endef
3131

32-
build: build-schemas build-docs copy-schemas show-build-output
32+
build: build-schemas copy-schema-docs build-docs copy-schemas show-build-output
3333

3434
build-docs: version
3535
npm run build $(baseurlparam)
@@ -61,8 +61,14 @@ show-build-output:
6161
@echo "Build output in $(BASE_OUTPUT_DIR):"
6262
@find $(BASE_OUTPUT_DIR) -type f -name "*" | sort
6363

64+
clean: clean-docs clean-schemas
65+
clean-docs:
66+
rm -rf $(BASE_OUTPUT_DIR)
67+
68+
6469
clean-schemas:
6570
rm -rf $(SCHEMA_OUTPUT_DIR)
71+
rm -rf $(SCHEMA_DOCS_OUTPUT_DIR)
6672

6773
debug: version
6874
npm run debug

schemas/scripts/generate_docs.py

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def generate_schema_docs(src_dir, docs_dir):
3131
for yaml_file in yaml_files:
3232
generate_single_doc(yaml_file, src_path, docs_path)
3333

34-
# Generate index file
35-
generate_index(yaml_files, src_path, docs_path)
34+
# Generate hierarchical index files
35+
generate_hierarchical_indices(yaml_files, src_path, docs_path)
3636

3737

3838
def generate_single_doc(yaml_file, src_path, docs_path):
@@ -195,6 +195,139 @@ def generate_property_doc(prop_name, prop_def):
195195
return content
196196

197197

198+
def generate_hierarchical_indices(yaml_files, src_path, docs_path):
199+
"""Generate hierarchical index files for all directories containing schemas."""
200+
# Get all unique directories that contain schema files
201+
directories = set()
202+
schemas_by_dir = {}
203+
204+
for yaml_file in yaml_files:
205+
rel_path = yaml_file.relative_to(src_path)
206+
dir_path = rel_path.parent
207+
208+
# Add this directory and all parent directories
209+
current_dir = dir_path
210+
while True:
211+
directories.add(current_dir)
212+
if current_dir == Path('.'):
213+
break
214+
current_dir = current_dir.parent
215+
216+
# Group schemas by their immediate directory
217+
dir_key = str(dir_path) if dir_path != Path('.') else 'root'
218+
if dir_key not in schemas_by_dir:
219+
schemas_by_dir[dir_key] = []
220+
schemas_by_dir[dir_key].append(rel_path)
221+
222+
# Generate index file for each directory
223+
for directory in directories:
224+
generate_directory_index(directory, schemas_by_dir, src_path, docs_path, directories)
225+
226+
227+
def generate_directory_index(directory, schemas_by_dir, src_path, docs_path, all_directories):
228+
"""Generate an index file for a specific directory."""
229+
# Determine the index file path
230+
if directory == Path('.'):
231+
index_file = docs_path / "index.md"
232+
dir_title = "Schema Documentation"
233+
dir_key = 'root'
234+
else:
235+
index_file = docs_path / directory / "index.md"
236+
dir_title = f"Schema Documentation - {directory.name}"
237+
dir_key = str(directory)
238+
239+
# Ensure directory exists
240+
index_file.parent.mkdir(parents=True, exist_ok=True)
241+
242+
# Get parent directory for navigation
243+
parent_dir = directory.parent if directory != Path('.') else None
244+
parent_link = ""
245+
if parent_dir is not None:
246+
if parent_dir == Path('.'):
247+
parent_link = "[↑ Parent Directory](../index.md)"
248+
else:
249+
# Calculate relative path to parent index
250+
depth = len(directory.parts)
251+
parent_path = "../" * depth + str(parent_dir) + "/index.md"
252+
parent_link = f"[↑ Parent Directory]({parent_path})"
253+
254+
# Start building content
255+
content = f"""---
256+
title: "{dir_title}"
257+
description: "Index of schema documentation in {directory if directory != Path('.') else 'root directory'}"
258+
generated: "{datetime.now().isoformat()}"
259+
directory: "{directory}"
260+
---
261+
262+
# {dir_title}
263+
264+
"""
265+
266+
# Add parent navigation
267+
if parent_link:
268+
content += f"{parent_link}\n\n"
269+
270+
# Add schemas in this directory
271+
schemas_in_dir = schemas_by_dir.get(dir_key, [])
272+
if schemas_in_dir:
273+
content += "## Schemas in this directory\n\n"
274+
for schema_path in sorted(schemas_in_dir):
275+
doc_path = schema_path.with_suffix('.md')
276+
schema_name = schema_path.stem.replace('.schema', '')
277+
278+
# Calculate relative path from current index to schema
279+
if directory == Path('.'):
280+
rel_doc_path = str(doc_path)
281+
else:
282+
rel_doc_path = str(doc_path.relative_to(directory))
283+
284+
content += f"- [{schema_name}]({rel_doc_path})\n"
285+
content += "\n"
286+
287+
# Add subdirectories
288+
subdirs = []
289+
for other_dir in all_directories:
290+
if other_dir != directory and other_dir != Path('.'):
291+
# Check if other_dir is a child of current directory
292+
try:
293+
if directory == Path('.'):
294+
# Root directory - check for immediate children
295+
if len(other_dir.parts) == 1:
296+
subdirs.append(other_dir)
297+
else:
298+
# Non-root directory - check if it's an immediate child
299+
if other_dir.parent == directory:
300+
subdirs.append(other_dir)
301+
except ValueError:
302+
# Not a relative path
303+
continue
304+
305+
if subdirs:
306+
content += "## Subdirectories\n\n"
307+
for subdir in sorted(subdirs):
308+
if directory == Path('.'):
309+
subdir_link = f"{subdir}/index.md"
310+
else:
311+
subdir_link = f"{subdir.name}/index.md"
312+
content += f"- [{subdir.name}/]({subdir_link})\n"
313+
content += "\n"
314+
315+
# Add generation info
316+
total_schemas_in_tree = len([s for s in schemas_by_dir.values() for s in s])
317+
content += f"""## Generation Info
318+
319+
- **Schemas in this directory**: {len(schemas_in_dir)}
320+
- **Total schemas in tree**: {total_schemas_in_tree}
321+
- **Generated**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
322+
- **Source directory**: `{src_path}`
323+
"""
324+
325+
with open(index_file, 'w') as f:
326+
f.write(content)
327+
328+
print(f"Generated index: {index_file}")
329+
330+
198331
def generate_index(yaml_files, src_path, docs_path):
199332
"""Generate an index file listing all schemas."""
200333
index_file = docs_path / "index.md"

0 commit comments

Comments
 (0)