Route discovery

Is there a mechanism by which a plugin CLI can discover all known routes for the install? My specific work case would be discovering all pages, generating their HTML, then scanning the HTML for absolute links for processing.

From within a my console command I’ve tried $pages = $this->getGrav()['pages'], which indeed gives me a Grav\Common\Page\Pages object, but none of the member functions give me any data (routes() is empty, for example).

Found the precache plugin and indeed its CLI uses curl, so apparently it’s not currently possible to discover routes using the CLI. Is this a feature that can be added? I basically want to be able to do the code in the onShutdown function but in the CLI.

You can actually get the routes. The precache plugin CLI command uses Curl so that the page is requested with the correct URL. This is important because Grav needs to be able to build the correct URL structure for links and references in the page. The plugin still does the work by finding all the routes and looping over them, calling '$page->content()` on each to cache:

/** @var Pages $pages */
$pages = $this->grav['pages'];
$routes = $pages->routes();

foreach ($routes as $route => $path) {
	// Log our progress
	if ($log_pages) {
		$this->grav['log']->addWarning('precache: '.$route);

	try {
		$page = $pages->get($path);
		// call the content to load/cache it
	} catch (\Exception $e) {
		// do nothing on error

But pages and routes aren’t available within the CLI itself. The precache plugin uses the CLI to trigger a GET that then triggers the onShutdown event.

In my case, I was hoping to have a standalone CLI that would scan the pages and do it’s work so as to not add load during viewing. The plugin can already scan the pages on cache misses, but I was hoping to provide an alternative.

It’s not the end of the world. I was just hoping that functionality would be available. Thanks for the reply, though!