Skip to content

Commit d4c1dae

Browse files
committed
Makes LLM-friendly links, headers, meta
1 parent e0855e4 commit d4c1dae

7 files changed

Lines changed: 40 additions & 1 deletion

File tree

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Kernel extends HttpKernel
3838
\App\Http\Middleware\VerifyCsrfToken::class,
3939
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4040
\App\Http\Middleware\RedirectRequest::class,
41+
\App\Http\Middleware\AddLlmsTxtHeader::class,
4142
],
4243

4344
'api' => [
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class AddLlmsTxtHeader
10+
{
11+
public function handle(Request $request, Closure $next): Response
12+
{
13+
$response = $next($request);
14+
15+
$baseUrl = 'https://pestphp.com';
16+
17+
$response->headers->set('X-Llms-Txt', "{$baseUrl}/llms.txt");
18+
19+
if (preg_match('#^docs/([^/]+)$#', $request->path(), $matches)) {
20+
$page = $matches[1];
21+
$response->headers->set('Link', "<{$baseUrl}/docs/{$page}/llms.txt>; rel=\"alternate\"; type=\"text/plain\"", false);
22+
} else {
23+
$response->headers->set('Link', "<{$baseUrl}/llms.txt>; rel=\"llms-txt\"; type=\"text/plain\"", false);
24+
}
25+
26+
return $response;
27+
}
28+
}

public/robots.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
User-agent: *
22
Disallow:
3+
4+
# LLM-friendly documentation
5+
llms-txt: https://pestphp.com/llms.txt

public/www/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<meta property="og:description" content="Pest is a testing framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.">
2121
<meta property="og:url" content="https://pestphp.com">
2222
<meta property="og:image" content="https://pestphp.com/assets/img/og-v4.jpg">
23+
<meta name="llms-txt" content="https://pestphp.com/llms.txt">
24+
<link rel="alternate" type="text/plain" href="https://pestphp.com/llms.txt" title="LLM-friendly documentation">
2325
<link rel="icon" href="/www/favicon.svg" type="image/svg+xml">
2426
<link rel="preconnect" href="https://fonts.googleapis.com">
2527
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

resources/views/docs.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<x-app-layout layout="app" :title="$matter['title']" :description="$matter['description']">
2+
<x-slot name="head">
3+
<link rel="alternate" type="text/plain" href="{{ url("/docs/{$page}/llms.txt") }}" title="LLM-friendly version">
4+
</x-slot>
5+
26
<main role="main" class="flex-auto overflow-hidden w-full">
37
<section class="documentation">
48
<div class="max-w-7xl sm:px-6 lg:flex lg:px-8 mx-auto">

resources/views/layouts/base.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<meta property="og:image" content="https://pestphp.com/assets/img/og-v4.jpg">
3434
@endif
3535

36+
<meta name="llms-txt" content="{{ url('/llms.txt') }}">
37+
3638
<meta name="csrf-token" content="{{ csrf_token() }}">
3739

3840
<link rel="icon" href="/www/favicon.svg" type="image/svg+xml">

routes/web.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@
2929
Route::get('/docs/{page}.md', [LlmsTxtController::class, 'page']);
3030
Route::get('/docs/{page?}', DocsController::class)->name('docs')->where('page', '.*');
3131
});
32-

0 commit comments

Comments
 (0)