Static site generation

You may use any static site generator in conjunction with Tome by reading exporting JSON directly. See tome-gatsby for an example of a Gatsby integration.

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:

  1. The "drush tome:static" command is ran.
  2. 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.
  3. The "cache.tome_static" service removes all paths that already cached and in the static build. The cache uses core cache tags to determine cacheability of paths.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. If the response was CSS, URLs within "url(...)" are parsed as assets.
  9. All collected asset paths are then returned to the parent process, which exports them starting at step 3.
  10. 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.