Skip to content

Commit 332be36

Browse files
committed
wip
1 parent a150bac commit 332be36

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

app/Http/Controllers/DocsController.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Illuminate\Contracts\Foundation\Application;
77
use Illuminate\Contracts\View\Factory;
88
use Illuminate\Http\RedirectResponse;
9+
use Illuminate\Http\Request;
10+
use Illuminate\Http\Response;
911
use Illuminate\View\View;
1012

1113
class DocsController extends Controller
@@ -17,9 +19,9 @@ class DocsController extends Controller
1719
/**
1820
* Handle the incoming request.
1921
*
20-
* @return Application|Factory|View|RedirectResponse
22+
* @return Application|Factory|View|RedirectResponse|Response
2123
*/
22-
public function __invoke(Documentation $docs, ?string $page = null)
24+
public function __invoke(Request $request, Documentation $docs, ?string $page = null)
2325
{
2426
if ($page === null) {
2527
return redirect()->route('docs', [self::DEFAULT_PAGE]);
@@ -29,10 +31,14 @@ public function __invoke(Documentation $docs, ?string $page = null)
2931
abort(404);
3032
}
3133

32-
$index = $docs->getIndex(config('site.defaultVersion'));
33-
3434
$document = $docs->get(config('site.defaultVersion'), $page);
3535

36+
if ($request->accepts(['text/markdown', 'text/plain']) && ! $request->accepts(['text/html'])) {
37+
return response($document['markdown'])->header('Content-Type', 'text/markdown; charset=utf-8');
38+
}
39+
40+
$index = $docs->getIndex(config('site.defaultVersion'));
41+
3642
$matter = $document['matter'];
3743
$markdown = $document['markdown'];
3844
$body = $document['html'];

routes/web.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
Route::group([
2020
//
2121
], function () {
22-
Route::get('/', fn () => file_get_contents(public_path('www/index.html')));
22+
Route::get('/', function (Illuminate\Http\Request $request) {
23+
if ($request->accepts(['text/markdown', 'text/plain']) && ! $request->accepts(['text/html'])) {
24+
return app(LlmsTxtController::class)->index();
25+
}
26+
27+
return file_get_contents(public_path('www/index.html'));
28+
});
2329

2430
Route::get('/llms.txt', [LlmsTxtController::class, 'index']);
2531
Route::get('/llms-full.txt', [LlmsTxtController::class, 'full']);

0 commit comments

Comments
 (0)