* Generate HTML for a single category * @param {string} categoryName - Category directory name * @returns {Promise } Generated HTML for all entries in the category
(categoryName)
| 30 | * @returns {Promise<string>} Generated HTML for all entries in the category |
| 31 | */ |
| 32 | async function generateCategorySection(categoryName) { |
| 33 | const categoryPath = path.join(__dirname, '../data', categoryName); |
| 34 | |
| 35 | let entries = []; |
| 36 | let errors = []; |
| 37 | |
| 38 | try { |
| 39 | entries = await readYamlDir(categoryPath); |
| 40 | } catch (err) { |
| 41 | // If directory doesn't exist, return empty string |
| 42 | if (err.code === 'ENOENT') { |
| 43 | return { html: '', count: 0, errors: [] }; |
| 44 | } |
| 45 | // Re-throw other errors |
| 46 | throw err; |
| 47 | } |
| 48 | |
| 49 | // Validate and filter entries |
| 50 | const validEntries = []; |
| 51 | for (const entry of entries) { |
| 52 | const result = validateEntry(entry, entry._filePath || path.join(categoryPath, `${entry.name || 'unknown'}.yaml`)); |
| 53 | |
| 54 | if (result.valid) { |
| 55 | validEntries.push(entry); |
| 56 | } else { |
| 57 | const errorMsg = formatValidationErrors(result); |
| 58 | errors.push(errorMsg); |
| 59 | console.error(errorMsg); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Sort alphabetically by name (case-insensitive) |
| 64 | validEntries.sort((a, b) => { |
| 65 | const nameA = (a.name || '').toLowerCase(); |
| 66 | const nameB = (b.name || '').toLowerCase(); |
| 67 | return nameA.localeCompare(nameB); |
| 68 | }); |
| 69 | |
| 70 | // Generate HTML for each entry |
| 71 | const htmlParts = validEntries.map(entry => generateEntryHtml(entry)); |
| 72 | |
| 73 | // Join with double newlines for proper spacing |
| 74 | const html = htmlParts.join('\n\n'); |
| 75 | |
| 76 | return { html, count: validEntries.length, errors }; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Main function to generate the README |
no test coverage detected