Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Grav\Plugin\Console;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* Class GeneratorCommand
*
* @package Grav\Plugin\Console
*/
class GeneratorCommand extends ConsoleCommand
{
/**
*
*/
protected function configure()
{
$this->setName("generate")
->setDescription("Generates the static site")
->setHelp('Used for bootstrapping a static site');
}
/**
* @return int|null|void
*/
protected function serve()
{
$export_dir = ROOT_DIR . 'site_export';
$grav = self::getGrav();
$grav['config']->init();
$grav['errors']->resetHandlers();
$grav['uri']->init();
$grav['debugger']->init();
$grav['twig']->init();
$grav['pages']->init();
$routes = $grav['pages']->routes();
foreach ($routes as $route => $path) {
@mkdir($export_dir . $route, 0755);
$page = $grav['pages']->get($path);
$output = $grav['twig']->processSitePage($page);
file_put_contents(
$export_dir . $route . DS . 'index.html',
$output
);
}
$to_copy_folders = array('assets', 'css', 'css-compiled', 'fonts', 'images', 'js', 'scss');
foreach ($to_copy_folders as $folder) {
$source = ROOT_DIR . DS . 'user/themes/antimatter/' . $folder;
$dest = $export_dir . DS . 'user/themes/antimatter/' . $folder;
@mkdir($dest, 0755, true);
foreach (
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST
) as $item
) {
if ($item->isDir()) {
@mkdir($dest . DS . $iterator->getSubPathName(), 0755);
} else {
@copy($item, $dest . DS . $iterator->getSubPathName());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment