26 lines
716 B
PHP
26 lines
716 B
PHP
<?php
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$recipesDir = __DIR__ . '/recipes';
|
|
|
|
if (!is_dir($recipesDir)) {
|
|
echo json_encode(["recipes" => new stdClass()], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
$categories = array_filter(glob($recipesDir . '/*'), 'is_dir');
|
|
$output = ["recipes" => []];
|
|
|
|
foreach ($categories as $categoryPath) {
|
|
$categoryName = basename($categoryPath);
|
|
$items = array_filter(glob($categoryPath . '/*'), 'is_dir');
|
|
$itemNames = array_map('basename', $items);
|
|
|
|
if (!empty($itemNames)) {
|
|
$output["recipes"][$categoryName] = array_values($itemNames);
|
|
}
|
|
}
|
|
|
|
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
?>
|