Skip to content

Commit

Permalink
create overview page script
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jun 6, 2024
1 parent ee6dc6a commit 573b157
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/scripts/generate-index-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const crypto = require('crypto');
async function generateIndex() {
const recipesDir = path.join(__dirname, '../../docs/recipes');
const outputPath = path.join(recipesDir, 'index.json');
const readmePath = path.join(recipesDir, 'README.md');
const files = await fs.readdir(recipesDir);
const index = [];
let readmeContent = '# Recipes\n\n';

for (const file of files) {
if (file.endsWith('.md')) {
Expand All @@ -15,17 +17,32 @@ async function generateIndex() {
const titleMatch = content.match(/^#\s+(.+)$/m);
const title = titleMatch ? titleMatch[1] : 'Untitled';
const hash = crypto.createHash('md5').update(content).digest('hex');

// Extract metadata from the comment block
const metadataMatch = content.match(/<!--\s*({[^]*?})\s*-->/);
let description = 'No description available.';
if (metadataMatch) {
const metadata = JSON.parse(metadataMatch[1]);
if (metadata.description) {
description = metadata.description;
}
}

index.push({
file: file,
title: title,
path: `/docs/recipes/${file}`,
hash: hash,
});

readmeContent += `## [${title}](/docs/recipes/${file})\n\n${description}\n\n`;
}
}

await fs.writeJson(outputPath, index, { spaces: 2 });
await fs.writeFile(readmePath, readmeContent, 'utf-8');
console.log(`Index written to ${outputPath}`);
console.log(`README written to ${readmePath}`);
}

generateIndex().catch(err => {
Expand Down

0 comments on commit 573b157

Please sign in to comment.