File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55use Closure ;
66use Illuminate \Http \Request ;
7+ use Illuminate \Support \Facades \View ;
78use Symfony \Component \HttpFoundation \Response ;
89
910class 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}
Original file line number Diff line number Diff line change 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" >
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments