Skip to content

Commit

Permalink
update script
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jun 6, 2024
1 parent bead6d9 commit 7e7bdd2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions .github/scripts/generate-index-recipes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const path = require('path');
const crypto = require('crypto');

async function generateIndex() {
const recipesDir = path.join(__dirname, '../../docs/recipes');
const outputPath = path.join(recipesDir, 'index.json');
Expand All @@ -10,8 +10,12 @@ async function generateIndex() {
const index = [];
let readmeContent = '# Recipes\n\n';

console.log('Generating index and README...');
console.log(`Reading files from ${recipesDir}`);

for (const file of files) {
if (file.endsWith('.md')) {
console.log(`Processing file: ${file}`);
const filePath = path.join(recipesDir, file);
const content = await fs.readFile(filePath, 'utf-8');
const titleMatch = content.match(/^#\s+(.+)$/m);
Expand Down Expand Up @@ -39,13 +43,16 @@ async function generateIndex() {
}
}

console.log(`Writing index to ${outputPath}`);
await fs.writeJson(outputPath, index, { spaces: 2 });

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

console.log('Index and README generation complete.');
}

generateIndex().catch(err => {
console.error(err);
console.error('Error generating index and README:', err);
process.exit(1);
});

0 comments on commit 7e7bdd2

Please sign in to comment.