-
Notifications
You must be signed in to change notification settings - Fork 23
/
statify.php
executable file
·112 lines (81 loc) · 2.54 KB
/
statify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
$isCmd = defined('STDIN');
require_once './version.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 the version (e.g. 2.7 or 3.0) dir to your server
* 5. Test your site
*/
// Define version prefix for menu
global $version_prefix;
$version_prefix = '/docs/' . DOCS_VERSION;
// Setup the base url for your site here
$url = 'https://svgjs.dev' . $version_prefix;
// Don't touch below here
define('DS', DIRECTORY_SEPARATOR);
// load the cms bootstrapper
include(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');
$kirby = kirby();
$kirby->urls->index = $version_prefix;
$site = $kirby->site();
if($site->multilang()) {
die('Multilanguage sites are not supported');
}
// root dir
$root = __DIR__ . $version_prefix . DS;
dir::copy(__DIR__ . DS . 'assets', $root . 'assets');
dir::copy(__DIR__ . DS . 'content', $root . 'content');
// set the timezone for all date functions
date_default_timezone_set($kirby->options['timezone']);
// load all extensions
$kirby->extensions();
// load all plugins
$kirby->plugins();
// load all models
$kirby->models();
// load all language variables
$kirby->localize();
foreach($site->index() as $page) {
// render page
$site->visit( $page->uri() );
$html = $kirby->render( $page );
// convert h2-6 tags
$html = preg_replace_callback( "#<(h[1-6])>(.*?)</\\1>#", 'retitle', $html );
// set root base
$name = $page->isHomePage() ? 'index.html' : $page->uri() . DS . 'index.html';
// write static file
f::write($root . $name, $html);
}
// write CNAME file
file_put_contents( $root . 'CNAME', 'svgjs.dev' );
// move 404 file
rename( $root . '404/index.html', $root . '404.html' );
rmdir( $root . '404' );
if($isCmd) {
echo "Version ".DOCS_VERSION." was exported to $version_prefix\n";
exit;
}
// helpers
function retitle( $match ) {
list( $_unused, $hx, $title ) = $match;
// clean id
$id = strtolower( preg_replace( '/[^A-Za-z0-9-]+/', '-', strip_tags( $title ) ) );
$id = preg_replace( '/^\-/', '', preg_replace( '/-$/', '', $id ) );
return "<$hx id='$id'>$title</$hx>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Statification</title>
</head>
<body>
Your site has been exported to the <b><?php echo $version_prefix ?></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>
</body>
</html>