@@ -50,7 +50,8 @@ convert_spec_to_html() {
5050 local output_file=" $OUTPUT_DIR /${relative_path% .* } .html"
5151
5252 # Create output directory if it doesn't exist
53- local output_dir=$( dirname " $output_file " )
53+ local output_dir
54+ output_dir=$( dirname " $output_file " )
5455 mkdir -p " $output_dir "
5556
5657 echo -e " ${BLUE} 📄 Converting: $spec_file ${NC} "
@@ -90,130 +91,7 @@ cat > "$INDEX_FILE" << 'EOF'
9091 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9192 <title>Devtron API Documentation</title>
9293 <style>
93- body {
94- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
95- line-height: 1.6;
96- margin: 0;
97- padding: 20px;
98- background-color: #f5f5f5;
99- }
100- .container {
101- max-width: 1200px;
102- margin: 0 auto;
103- background: white;
104- padding: 30px;
105- border-radius: 8px;
106- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
107- }
108- h1 {
109- color: #2c3e50;
110- text-align: center;
111- margin-bottom: 30px;
112- font-size: 2.5em;
113- }
114- .description {
115- text-align: center;
116- color: #7f8c8d;
117- margin-bottom: 40px;
118- font-size: 1.1em;
119- }
120- .stats {
121- background: #ecf0f1;
122- padding: 20px;
123- border-radius: 6px;
124- margin-bottom: 30px;
125- text-align: center;
126- }
127- .stats h2 {
128- margin: 0 0 15px 0;
129- color: #34495e;
130- }
131- .stats-grid {
132- display: grid;
133- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
134- gap: 20px;
135- margin-top: 15px;
136- }
137- .stat-item {
138- background: white;
139- padding: 15px;
140- border-radius: 6px;
141- border-left: 4px solid #3498db;
142- }
143- .stat-number {
144- font-size: 2em;
145- font-weight: bold;
146- color: #3498db;
147- }
148- .stat-label {
149- color: #7f8c8d;
150- font-size: 0.9em;
151- }
152- .categories {
153- display: grid;
154- grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
155- gap: 20px;
156- }
157- .category {
158- background: #f8f9fa;
159- border-radius: 6px;
160- padding: 20px;
161- border: 1px solid #e9ecef;
162- }
163- .category h3 {
164- color: #2c3e50;
165- margin-top: 0;
166- border-bottom: 2px solid #3498db;
167- padding-bottom: 10px;
168- }
169- .api-list {
170- list-style: none;
171- padding: 0;
172- }
173- .api-list li {
174- margin: 8px 0;
175- }
176- .api-list a {
177- color: #3498db;
178- text-decoration: none;
179- padding: 5px 10px;
180- border-radius: 4px;
181- transition: background-color 0.2s;
182- display: inline-block;
183- }
184- .api-list a:hover {
185- background-color: #e3f2fd;
186- text-decoration: underline;
187- }
188- .footer {
189- text-align: center;
190- margin-top: 40px;
191- padding-top: 20px;
192- border-top: 1px solid #ecf0f1;
193- color: #7f8c8d;
194- }
195- .timestamp {
196- font-size: 0.9em;
197- color: #95a5a6;
198- }
199- .errors-section {
200- background: #fff5f5;
201- border: 1px solid #fed7d7;
202- border-radius: 6px;
203- padding: 20px;
204- margin: 20px 0;
205- }
206- .errors-section h3 {
207- color: #c53030;
208- margin-top: 0;
209- }
210- .error-list {
211- background: white;
212- border-radius: 4px;
213- padding: 15px;
214- font-family: monospace;
215- font-size: 0.9em;
216- }
94+ /* styles omitted for brevity — keep your existing CSS here */
21795 </style>
21896</head>
21997<body>
@@ -234,45 +112,35 @@ cat > "$INDEX_FILE" << 'EOF'
234112 </div>
235113
236114 <script>
237- // API data structure
238115 const apiData = {
239116EOF
240117
241118# Generate the JavaScript data for the index page
242119echo " Generating JavaScript data for index page..."
243120
244- # Initialize counters
245121total_apis=0
246122categories_count=0
247123
248- # Process each spec file to build the data structure
249124for spec_file in $spec_files ; do
250125 relative_path=" ${spec_file# $SPECS_DIR / } "
251126 filename=$( basename " $spec_file " )
252127 name_without_ext=" ${filename% .* } "
253128 category=$( dirname " $relative_path " )
254129
255- # Skip if it's the root specs directory
256130 if [ " $category " = " ." ]; then
257131 category=" root"
258132 fi
259133
260- # Clean up category name for display
261134 display_category=$( echo " $category " | sed ' s/-/ /g' | sed ' s/_/ /g' | sed ' s/\b\w/\U&/g' )
262135
263- # Get the title from the spec file (first line with 'title:')
264136 title=$( grep -m 1 ' ^[[:space:]]*title:' " $spec_file " \
265137 | sed ' s/^[[:space:]]*title:[[:space:]]*//' \
266138 | tr -d ' "' \
267139 || echo " $name_without_ext " )
268140
269-
270- # Create the output filename
271141 output_file=" ${relative_path% .* } .html"
272142
273- # Check if the HTML file was actually created successfully
274143 if [ -f " $OUTPUT_DIR /$output_file " ]; then
275- # Add to JavaScript data
276144 cat >> " $INDEX_FILE " << EOF
277145 "${category} _${name_without_ext} ": {
278146 "category": "${display_category} ",
@@ -284,26 +152,31 @@ EOF
284152 fi
285153done
286154
287- # Remove the last comma and close the data structure
288- sed -i ' ' ' $ s/,$//' " $INDEX_FILE "
155+ # Log what find returns for index.html
156+ echo -e " ${YELLOW} 🔍 Searching for index.html in $OUTPUT_DIR ...${NC} "
157+ find . -name " index.html" -path " */docs/api-docs/*"
158+
159+ # Remove trailing comma only if file exists
160+ if [[ -f " $INDEX_FILE " ]]; then
161+ sed -i ' $ s/,$//' " $INDEX_FILE "
162+ else
163+ echo -e " ${RED} ⚠️ $INDEX_FILE not found, skipping trailing comma fix${NC} "
164+ fi
289165
290166cat >> " $INDEX_FILE " << 'EOF '
291167 };
292168
293- // Function to populate the page
294169 function populatePage() {
295170 const categoriesContainer = document.getElementById('categories');
296171 const categories = {};
297172
298- // Group APIs by category
299173 Object.values(apiData).forEach(api => {
300174 if (!categories[api.category]) {
301175 categories[api.category] = [];
302176 }
303177 categories[api.category].push(api);
304178 });
305179
306- // Create category sections
307180 Object.keys(categories).sort().forEach(category => {
308181 const categoryDiv = document.createElement('div');
309182 categoryDiv.className = 'category';
@@ -315,7 +188,6 @@ cat >> "$INDEX_FILE" << 'EOF'
315188 const apiList = document.createElement('ul');
316189 apiList.className = 'api-list';
317190
318- // Sort APIs within category by title
319191 categories[category].sort((a, b) => a.title.localeCompare(b.title)).forEach(api => {
320192 const listItem = document.createElement('li');
321193 const link = document.createElement('a');
@@ -330,12 +202,9 @@ cat >> "$INDEX_FILE" << 'EOF'
330202 categoriesContainer.appendChild(categoryDiv);
331203 });
332204
333- // Update statistics
334-
335205 document.getElementById('timestamp').textContent = new Date().toLocaleString();
336206 }
337207
338- // Initialize the page
339208 document.addEventListener('DOMContentLoaded', populatePage);
340209 </script>
341210</body>
354223echo -e " ${BLUE} 📁 Output directory: $OUTPUT_DIR ${NC} "
355224echo -e " ${BLUE} 🌐 Main index: $INDEX_FILE ${NC} "
356225
357- # Create a simple README for the docs
226+ # Create README
358227cat > " $OUTPUT_DIR /README.md" << 'EOF '
359228# Devtron API Documentation
360-
361- This directory contains HTML documentation generated from OpenAPI specifications using Redocly.
362-
363- ## Files
364-
365- - `index.html` - Main index page with links to all API documentation
366- - Individual HTML files for each API specification
367- - `errors.log` - Log of any files that failed to convert
368-
369- ## How to Use
370-
371- 1. Open `index.html` in your web browser to see the main index
372- 2. Click on any API link to view the detailed documentation
373- 3. All documentation is self-contained and can be hosted on any web server
374-
375- ## Generation
376-
377- To regenerate the documentation, run:
378-
379- ```bash
380- ./scripts/generate-api-docs.sh
381- ```
382-
383- ## Requirements
384-
385- - Redocly CLI (`npm install -g @redocly/cli`)
386- - Bash shell
387-
388- ## Notes
389-
390- - Each HTML file is self-contained and includes all necessary CSS and JavaScript
391- - Documentation is generated from OpenAPI 3.0+ specifications
392- - Files are organized by category for easy navigation
393- - If some files fail to convert, check the errors.log file for details
229+ ... (keep your existing README text here)
394230EOF
395231
396232echo -e " ${GREEN} ✅ README created: $OUTPUT_DIR /README.md${NC} "
0 commit comments