diff --git a/app/Http/Controllers/DocsController.php b/app/Http/Controllers/DocsController.php index b93a96b..e82d0e9 100644 --- a/app/Http/Controllers/DocsController.php +++ b/app/Http/Controllers/DocsController.php @@ -25,6 +25,9 @@ public function __invoke(Documentation $docs, ?string $page = null) return redirect()->route('docs', [self::DEFAULT_PAGE]); } + $isMarkdown = str($page)->endsWith('.md'); + $page = str($page)->replace('.md', '')->toString(); + if (! $docs->exists(config('site.defaultVersion'), $page) || in_array($page, self::EXCLUDED)) { abort(404); } @@ -37,6 +40,10 @@ public function __invoke(Documentation $docs, ?string $page = null) $markdown = $document['markdown']; $body = $document['html']; + if ($isMarkdown) { + return response($markdown, 200, ['Content-Type' => 'text/plain']); + } + return view('docs', compact('body', 'matter', 'markdown', 'page', 'index')); } } diff --git a/routes/web.php b/routes/web.php index d8f8653..2cf060e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,4 +23,3 @@ Route::get('/docs/editor-setup', IDEPluginsController::class)->name('ide-plugins'); Route::get('/docs/{page?}', DocsController::class)->name('docs')->where('page', '.*'); }); - diff --git a/tests/Browser/SmokeTest.php b/tests/Browser/SmokeTest.php index 90d723d..df392ef 100644 --- a/tests/Browser/SmokeTest.php +++ b/tests/Browser/SmokeTest.php @@ -5,3 +5,7 @@ $response->assertNoSmoke(); }); + +it('serves pages in markdown format', function () { + visit('/docs/installation.md')->assertNoSmoke(); +});