|
18 | 18 |
|
19 | 19 | final readonly class ChapterController |
20 | 20 | { |
21 | | - #[Get('/docs/{path:.*}')] |
22 | 21 | #[Get('/current/{path:.*}')] |
23 | 22 | #[Get('/main/{path:.*}')] |
24 | 23 | public function docsRedirect(string $path): Redirect |
@@ -54,18 +53,34 @@ public function index(): Redirect |
54 | 53 | )); |
55 | 54 | } |
56 | 55 |
|
| 56 | + #[StaticPage(DefaultDocumentationDataProvider::class)] |
| 57 | + #[Get('/docs/{category}/{slug}')] |
| 58 | + public function default(string $category, string $slug, ChapterRepository $chapterRepository): View|Response |
| 59 | + { |
| 60 | + return $this->chapterView(Version::default(), $category, $slug, $chapterRepository) ?? new NotFound(); |
| 61 | + } |
| 62 | + |
57 | 63 | #[StaticPage(DocumentationDataProvider::class)] |
58 | 64 | #[Get('/{version}/{category}/{slug}')] |
59 | 65 | public function __invoke(string $version, string $category, string $slug, ChapterRepository $chapterRepository): View|Response |
60 | 66 | { |
| 67 | + if ($version === Version::default()->value) { |
| 68 | + return new Redirect(uri([self::class, 'default'], category: $category, slug: $slug)); |
| 69 | + } |
| 70 | + |
61 | 71 | if (is_null($version = Version::tryFromString($version))) { |
62 | 72 | return new NotFound(); |
63 | 73 | } |
64 | 74 |
|
| 75 | + return $this->chapterView($version, $category, $slug, $chapterRepository) ?? new NotFound(); |
| 76 | + } |
| 77 | + |
| 78 | + private function chapterView(Version $version, string $category, string $slug, ChapterRepository $chapterRepository): ?ChapterView |
| 79 | + { |
65 | 80 | $currentChapter = $chapterRepository->find($version, $category, $slug); |
66 | 81 |
|
67 | 82 | if (! $currentChapter || $currentChapter->hidden) { |
68 | | - return new NotFound(); |
| 83 | + return null; |
69 | 84 | } |
70 | 85 |
|
71 | 86 | return new ChapterView( |
|
0 commit comments