Skip to content

Commit 3c5203e

Browse files
committed
generate the labels from :page-role:
1 parent 62ae41f commit 3c5203e

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

scripts/generate_gql_error_index.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ def read_error_file(file_path):
1616
return match.group(1).strip()
1717
return None
1818

19+
def get_page_role(file_path):
20+
"""Extract page-role from error file if it exists."""
21+
try:
22+
with open(file_path, 'r') as f:
23+
for line in f:
24+
if line.strip().startswith(':page-role:'):
25+
# Extract the role value after ':page-role:'
26+
return line.strip()[11:].strip()
27+
except Exception as e:
28+
print(f"Warning: Failed to read page role from {file_path}: {e}")
29+
return None
30+
1931
def get_section_descriptions(index_file):
2032
"""Extract section descriptions from the original index file.
2133
Only captures the text that appears immediately after a section heading and before any error codes."""
@@ -113,16 +125,26 @@ def generate_index(errors_dir, output_file, original_index, include_descriptions
113125
# Get section descriptions from original index
114126
section_descriptions = get_section_descriptions(original_index)
115127

116-
# Get error codes and descriptions from files
128+
# Get error codes, descriptions, and page roles from files
117129
error_codes = {}
118130
for file in os.listdir(errors_dir):
119131
if file.endswith('.adoc') and file != 'index.adoc' and file != 'auto-index.adoc':
120132
error_code = file[:-5] # Remove .adoc extension
121-
description = read_error_file(os.path.join(errors_dir, file)) if include_descriptions else None
122-
if include_descriptions and description:
123-
error_codes[error_code] = description
124-
elif not include_descriptions:
125-
error_codes[error_code] = None
133+
file_path = os.path.join(errors_dir, file)
134+
135+
# Get description if needed
136+
description = None
137+
if include_descriptions:
138+
description = read_error_file(file_path)
139+
140+
# Get page role
141+
page_role = get_page_role(file_path)
142+
143+
# Store information about this error code
144+
error_codes[error_code] = {
145+
'description': description,
146+
'page_role': page_role
147+
}
126148

127149
# Group error codes by section
128150
sections = defaultdict(list)
@@ -164,10 +186,15 @@ def generate_index(errors_dir, output_file, original_index, include_descriptions
164186

165187
# Add error codes for this section
166188
for error_code in sections[section]:
189+
# Add page role if exists
190+
if error_codes[error_code]['page_role']:
191+
content.append(f'[role=label--{error_codes[error_code]["page_role"]}]')
192+
167193
content.append(f'=== xref:errors/gql-errors/{error_code}.adoc[{error_code}]')
168194
content.append('')
169-
if include_descriptions and error_codes[error_code]:
170-
content.append(f'Status description:: {error_codes[error_code]}')
195+
196+
if include_descriptions and error_codes[error_code]['description']:
197+
content.append(f'Status description:: {error_codes[error_code]["description"]}')
171198
content.append('')
172199

173200
# Add glossary section once at the end of the document (outside both loops)
@@ -207,4 +234,4 @@ def main():
207234
generate_index(errors_dir, output_file, original_index, not args.no_descriptions)
208235

209236
if __name__ == '__main__':
210-
main()
237+
main()

0 commit comments

Comments
 (0)