* Generate the instructions section with a table of all instructions
(instructionsDir)
| 288 | * Generate the instructions section with a table of all instructions |
| 289 | */ |
| 290 | function generateInstructionsSection(instructionsDir) { |
| 291 | // Check if directory exists |
| 292 | if (!fs.existsSync(instructionsDir)) { |
| 293 | return ""; |
| 294 | } |
| 295 | |
| 296 | // Get all instruction files |
| 297 | const instructionFiles = fs |
| 298 | .readdirSync(instructionsDir) |
| 299 | .filter((file) => file.endsWith(".instructions.md")); |
| 300 | |
| 301 | // Map instruction files to objects with title for sorting |
| 302 | const instructionEntries = instructionFiles.map((file) => { |
| 303 | const filePath = path.join(instructionsDir, file); |
| 304 | const title = extractTitle(filePath); |
| 305 | return { file, filePath, title }; |
| 306 | }); |
| 307 | |
| 308 | // Sort by title alphabetically |
| 309 | instructionEntries.sort((a, b) => a.title.localeCompare(b.title, "en")); |
| 310 | |
| 311 | console.log(`Found ${instructionEntries.length} instruction files`); |
| 312 | |
| 313 | // Return empty string if no files found |
| 314 | if (instructionEntries.length === 0) { |
| 315 | return ""; |
| 316 | } |
| 317 | |
| 318 | // Create table header |
| 319 | let instructionsContent = |
| 320 | "| Title | Description |\n| ----- | ----------- |\n"; |
| 321 | |
| 322 | // Generate table rows for each instruction file |
| 323 | for (const entry of instructionEntries) { |
| 324 | const { file, filePath, title } = entry; |
| 325 | const link = encodeURI(`instructions/${file}`); |
| 326 | |
| 327 | // Check if there's a description in the frontmatter |
| 328 | const customDescription = extractDescription(filePath); |
| 329 | |
| 330 | // Create badges for installation links |
| 331 | const badges = makeBadges(link, "instructions", "source"); |
| 332 | |
| 333 | if (customDescription && customDescription !== "null") { |
| 334 | // Use the description from frontmatter, table-safe |
| 335 | instructionsContent += `| [${title}](../${link})<br />${badges} | ${formatTableCell( |
| 336 | customDescription |
| 337 | )} |\n`; |
| 338 | } else { |
| 339 | // Fallback to the default approach - use last word of title for description, removing trailing 's' if present |
| 340 | const topic = title.split(" ").pop().replace(/s$/, ""); |
| 341 | instructionsContent += `| [${title}](../${link})<br />${badges} | ${topic} specific coding standards and best practices |\n`; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | return `${TEMPLATES.instructionsSection}\n${TEMPLATES.instructionsUsage}\n\n${instructionsContent}`; |
| 346 | } |
| 347 |
nothing calls this directly
no test coverage detected