I’m looking for a way to generate a static version of specified nodes ( in my case they are book nodes pages).
I want to do it periodically in my custom Drupal cronjob,
most of the Drupal static modules are obsolete and there is no version for Drupal 9.
I found TOME module but looks like it’s mostly for generating full website static generation through admin panel or drush
command line.
I tried drush tome:static-export-path /mybookpath --uri=localhost:8080
but it’s blindly going through all the links on the pages and download all of them.
with digging more into the documentation I found this which is good to use tome services. in this case, there is no URI parameter option( it’s only available for drush command) and it does not replace URLs ( image,link, style ( css) urls) and use the main version.
<?php /** @var Drupaltome_staticStaticGeneratorInterface $static */ $static = Drupal::service('tome_static.generator'); /** @var Drupaltome_staticRequestPreparer $request_preparer */ $request_preparer = Drupal::service('tome_static.request_preparer'); // Prepare for a new request. This is necessary so that static caches in Drupal // can be reset between multiple requests in one bootstrap. $request_preparer->prepareForRequest(); // Request an arbitrary path. "$invoke_paths" at this point is anything that // needs to be copied (an existing file) or requested (an image derivative, // other paths, etc.) $invoke_paths = $static->requestPath('/foo'); // Export paths will try to copy or remove as many paths as possible without // making a new internal request. $invoke_paths = $static->exportPaths($invoke_paths); // The remaining invoke paths need to be handled in new requests. foreach ($invoke_paths as $path) { // Since we are only trying to export one path, restrict new requests to // paths with extensions, which are probably RSS feeds and image derivatives. if (pathinfo($path, PATHINFO_EXTENSION)) { $request_preparer->prepareForRequest(); // This could return more paths, but we're ignoring that for simplicity. $static->requestPath($path); } }
My question: What is the best solution to generate static HTML files will all assets of specific Drupal nodes?