Skip to content

Commit a150bac

Browse files
committed
wip
1 parent d4c1dae commit a150bac

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

app/Http/Middleware/AddLlmsTxtHeader.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@
44

55
use Closure;
66
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\View;
78
use Symfony\Component\HttpFoundation\Response;
89

910
class AddLlmsTxtHeader
1011
{
1112
public function handle(Request $request, Closure $next): Response
1213
{
13-
$response = $next($request);
14-
1514
$baseUrl = 'https://pestphp.com';
16-
17-
$response->headers->set('X-Llms-Txt', "{$baseUrl}/llms.txt");
15+
$rootLlmsTxt = "{$baseUrl}/llms.txt";
1816

1917
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);
18+
$pageLlmsTxt = "{$baseUrl}/docs/{$matches[1]}/llms.txt";
2419
}
2520

21+
View::share('llmsTxt', $pageLlmsTxt ?? $rootLlmsTxt);
22+
23+
$response = $next($request);
24+
25+
$response->headers->set('X-Llms-Txt', $rootLlmsTxt);
26+
$response->headers->set('Link', '<'.($pageLlmsTxt ?? $rootLlmsTxt).'>; rel="alternate"; type="text/plain"', false);
27+
2628
return $response;
2729
}
2830
}

resources/views/docs.blade.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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-
62
<main role="main" class="flex-auto overflow-hidden w-full">
73
<section class="documentation">
84
<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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +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') }}">
36+
<meta name="llms-txt" content="{{ $llmsTxt ?? url('/llms.txt') }}">
37+
<link rel="alternate" type="text/plain" href="{{ $llmsTxt ?? url('/llms.txt') }}" title="LLM-friendly version">
3738

3839
<meta name="csrf-token" content="{{ csrf_token() }}">
3940

0 commit comments

Comments
 (0)