-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-index.js
More file actions
41 lines (32 loc) · 1.18 KB
/
generate-index.js
File metadata and controls
41 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get current directory in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Get the recipes directory path
const recipesDir = path.join(__dirname, 'public', 'recipes');
// Function to scan for JSON files and create index
function generateRecipeIndex() {
try {
// Read all files in the recipes directory
const files = fs.readdirSync(recipesDir);
// Filter for JSON files, excluding index.json and recipes.json
const recipeFiles = files.filter(file =>
file.endsWith('.json') &&
file !== 'index.json' &&
file !== 'recipes.json'
);
// Write the index file
const indexPath = path.join(recipesDir, 'index.json');
fs.writeFileSync(indexPath, JSON.stringify(recipeFiles, null, 2));
console.log(`Generated recipe index with ${recipeFiles.length} files:`);
recipeFiles.forEach(file => console.log(` - ${file}`));
} catch (error) {
console.error('Error generating recipe index:', error);
process.exit(1);
}
}
// Run the function
generateRecipeIndex();