Skip to content

Instantly share code, notes, and snippets.

@bugsysop
Forked from bastianallgeier/statify.php
Last active March 19, 2017 03:15
Show Gist options
  • Save bugsysop/2b6205b595a3ebc9c063 to your computer and use it in GitHub Desktop.
Save bugsysop/2b6205b595a3ebc9c063 to your computer and use it in GitHub Desktop.
A first draft for a script, which converts a Kirby site into a static site. It's a rough first draft, so don't expect it to be perfect. Play with it, if you like it!
<?php
/**
* Instructions:
*
* 1. Put this into the document root of your Kirby site
* 2. Make sure to setup the base url for your site correctly
* 3. Run this script with `php statify.php` or open it in your browser
* 4. Upload all files and folders from static to your server
* 5. Test your site
*/
// Setup the base url for your site here
$url = 'http://yourdomain.com';
// Don't touch below here
define('DS', DIRECTORY_SEPARATOR);
// load the cms bootstrapper
include(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');
// start the cms
$site = kirby::setup(array(
'url' => $url
));
dir::copy(__DIR__ . DS . 'assets', __DIR__ . DS . 'static' . DS . 'assets');
dir::copy(__DIR__ . DS . 'content', __DIR__ . DS . 'static' . DS . 'content');
foreach($site->index() as $page) {
$site->visit($page->uri());
$html = kirby::render($page);
if($page->isHomePage()) {
$root = __DIR__ . DS . 'static' . DS . 'index.html';
} else {
$root = __DIR__ . DS . 'static' . DS . $page->uri() . DS . 'index.html';
}
f::write($root, $html);
}
?>
Your site has been exported to the <b>static</b> folder.<br />
Copy all sites and folders from there and upload them to your server.<br />
Make sure the main URL is correct: <b><?php echo $url ?></b>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment