If you want to use Drupal to generate HTML, Tome ships with a static site generator that uses Drupal's internal request handling and concurrency to ensure that pages are exported as quickly as possible.
The static site generation flow works like:
- The "drush tome:static" command is ran.
- The "tome.static" service collects all paths known to Drupal. Currently this is a combination of all routes that do not use parameters, and all entity "canonical" paths (and the paths of their translations). If the site uses URL language negotiation, each configured language prefix is also collected. Only entities/routes that are accessible to anonymous are exported.
- Paths are exported using a user-configurable concurrency, which defaults to five. This means that five paths will be processed by Drupal at a time.
- For each path, the script first checks if the path is a static file that can be immediately copied. This is common for pre-generated files in the files directory.
- If the path isn't a static file, a new process is invoked and Drupal handles the request. This is done using the "http.kernel" service. If a response with the status code 200 is returned, the content of that response is saved to the filesystem.
- If the response was HTML, that HTMl is parsed and assets are collected. The currently recognized assets are pager links (to support Views pagers), images, responsive images (using srcset), stylesheets, scripts, and favicons.
- If the response was CSS, URLs within "url(...)" are parsed as assets.
- All collected asset paths are then returned to the parent process, which exports them starting at step 3.
- Steps 3-8 repeat until there are no more assets to be exported.
If a path that your site needs is not collected automatically, you can subscribe to the "Drupal\tome\Event\TomeEvents:COLLECT_PATHS" event, which allows you to add, remove, and replace collected paths. Additionally APIs for processing responses will be added as needed.