#!/usr/bin/env php $parts[0]]; if (isset($parts[1]) && $parts[1] !== '') $crumb['href'] = $parts[1]; $breadcrumb[] = $crumb; } } // Sanitize every path segment while preserving deliberate nesting. $slugParts = array_map(static function (string $part): string { $part = preg_replace('/[^a-z0-9-]/', '-', strtolower(trim($part))); return trim((string)preg_replace('/-+/', '-', (string)$part), '-'); }, explode('/', trim((string)$slug, '/'))); $slug = implode('/', array_filter($slugParts, static fn(string $part): bool => $part !== '')); if (!raijuPageIsValidPath($slug)) { fwrite(STDERR, "Error: --slug is required and must contain alphanumeric characters.\n"); exit(1); } if (!preg_match('/^[a-z]{2}$/', $lang)) { fwrite(STDERR, "Error: --lang must be a 2-letter lowercase code (e.g. en, de, es).\n"); exit(1); } if (!in_array($type, ['standard', 'custom'])) { fwrite(STDERR, "Error: --type must be 'standard' or 'custom'.\n"); exit(1); } $titleSlug = basename(str_replace('/', DIRECTORY_SEPARATOR, $slug)); $title = $opts['title'] ?? ucfirst(str_replace('-', ' ', $titleSlug)); $description = $opts['description'] ?? ''; // ── Path computation ────────────────────────────────────────────────── $pageKey = raijuPageContentKey($lang, $slug); $jsonPath = $projectRoot . '/content/pages/' . $pageKey . '.json'; $templatePath = raijuPageTemplatePath($projectRoot, $lang, $slug); // Check for existing files (without --force) if (!$dryRun && !$force) { if (file_exists($jsonPath)) { fwrite(STDERR, "Error: $jsonPath already exists. Use --force to overwrite.\n"); exit(1); } if ($type === 'custom' && file_exists($templatePath)) { fwrite(STDERR, "Error: $templatePath already exists. Use --force to overwrite.\n"); exit(1); } } // ── Generate JSON content ───────────────────────────────────────────── $json = [ 'page' => $pageKey, 'path' => $slug, 'lang' => $lang, 'title' => $title, 'description' => $description, 'lastModified' => null, ]; if ($navLocations !== null) { $json['nav'] = $navLocations; } if ($breadcrumb !== null) { $json['breadcrumb'] = $breadcrumb; } if ($type === 'standard') { $json['sections'] = [ [ 'id' => 's1', 'type' => 'heading', 'text' => $title, 'level' => 'h1', ], [ 'id' => 's2', 'type' => 'text', 'title' => '', 'content' => '
Add your content here.
', ], ]; } else { $json['hero'] = [ 'title' => $title, 'subtitle' => 'Your tagline here.', ]; $json['content'] = [ 'heading' => 'Content', 'text' => 'Add your content here.
', ]; } $jsonContent = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n"; // ── Generate PHP template (custom only) ─────────────────────────────── $templateContent = ''; if ($type === 'custom') { $safeTitle = addcslashes($title, "'"); $safeDesc = addcslashes($description, "'"); $includePrefix = str_repeat('../', substr_count($slug, '/') + 1); $templateContent = <<