Installation
Requirements
Section titled “Requirements”- PHP 8.2+
- Symfony 6.4, 7.x or 8.x
symfony/framework-bundleto register the bundle: the package does not install it, and the generator, the renderers and the dumpers work without it, see Without the bundlesymfony/consolefor thellms-txt:dumpcommand,symfony/twig-bundlefor the Twig functions,symfony/web-linkfor theLinkheader ofdiscovery.link_header
Installation
Section titled “Installation”composer require silarhi/llms-txt-bundleRegister the bundle if Flex did not:
return [ // ... Silarhi\LlmsTxtBundle\LlmsTxtBundle::class => ['all' => true],];Import the route serving /llms.txt:
llms_txt: resource: '@LlmsTxtBundle/config/routes.php'Without the bundle
Section titled “Without the bundle”An application without the framework or symfony/dependency-injection builds the services by hand, from an event
dispatcher and the router (the llms_txt route options):
use Silarhi\LlmsTxtBundle\Controller\LlmsTxtController;use Silarhi\LlmsTxtBundle\Event\LlmsTxtPopulateEvent;use Silarhi\LlmsTxtBundle\EventListener\RouteOptionsListener;use Silarhi\LlmsTxtBundle\LlmsTxt;use Silarhi\LlmsTxtBundle\Service\Dumper;use Silarhi\LlmsTxtBundle\Service\FullMarkdownRenderer;use Silarhi\LlmsTxtBundle\Service\Generator;use Silarhi\LlmsTxtBundle\Service\MarkdownRenderer;use Symfony\Component\EventDispatcher\EventDispatcher;use Symfony\Component\Filesystem\Filesystem;
$dispatcher = new EventDispatcher();$dispatcher->addSubscriber(new RouteOptionsListener($router, 'Pages')); // the routes carrying an "llms_txt" option$dispatcher->addListener(LlmsTxtPopulateEvent::class, static function (LlmsTxtPopulateEvent $event) use ($products): void { $event->getDocument()->addLinks('Products', $products->links()); // a generator of Link, read while writing});
$generator = new Generator($dispatcher, title: 'SILARHI', summary: 'Web and mobile applications.');
// public/llms.txt, and public/llms-full.txt from the same listeners(new Dumper($generator, new MarkdownRenderer(), new Filesystem(), __DIR__ . '/public', LlmsTxt::FILENAME))->dump();(new Dumper($generator, new FullMarkdownRenderer(), new Filesystem(), __DIR__ . '/public', LlmsTxt::FULL_FILENAME))->dump();
// or serve it: the dumped file when there is one, built on the fly otherwise$controller = new LlmsTxtController($generator, new MarkdownRenderer(), __DIR__ . '/public', 'text/plain; charset=UTF-8', 3600, LlmsTxt::FILENAME, true);$response = $controller($request);DumpCommand (with symfony/console), LlmsTxtExtension (with twig/twig) and MarkdownVersionListener are built
the same way. What needs a container stays with the bundle class: the configuration, the #[AsLlmsTxtLinkProvider]
attribute (add a LinkProviderListener to the dispatcher instead), the routes of routes.php, the cache warmers and
Twig’s escaping of the *.md.twig templates.
