-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.php
More file actions
executable file
·60 lines (49 loc) · 1.5 KB
/
build.php
File metadata and controls
executable file
·60 lines (49 loc) · 1.5 KB
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
#!/usr/bin/php
<?php
define('BUILD_DIR', 'build');
define('ASSETS_DIR', 'assets');
define('STATICS_DIR', 'statics');
define('TEMPLATES_DIR', 'templates');
require_once('config.php');
/*************************
* Render a "template"
*/
function render($PAGE, $template) {
global $SITE;
$filepath = sprintf('%s/%s.tpl', TEMPLATES_DIR, $template);
# die($filepath);
if (!file_exists($filepath))
return render($PAGE, 'default');
ob_start();
require($filepath);
$content = ob_get_clean();
ob_end_clean();
return $content;
}
/*************************
* Append site base_path
*/
function url($path) {
global $SITE;
return sprintf('%s%s', $SITE['base_path'], $path);
}
/*************************
* Real code for real men
*/
printf("--> removing '%s'\n", BUILD_DIR);
echo system(sprintf('rm -rf "%s"', BUILD_DIR));
printf("--> copying statics '%s' to '%s'\n", STATICS_DIR, BUILD_DIR);
echo system(sprintf('cp -R "%s" "%s"', STATICS_DIR, BUILD_DIR));
printf("--> copying assets '%s' to '%s/'\n", ASSETS_DIR, BUILD_DIR);
echo system(sprintf('cp -R "%s" "%s/"', ASSETS_DIR, BUILD_DIR));
foreach ($SITE['menu'] as $page_name => $page_data) {
printf("--> rendering '%s' \n", $page_name);
$_dstpath = '%s/%s.html';
$dstpath = sprintf($_dstpath, BUILD_DIR, $page_name);
$page = array(
'page' => $page_name,
'title' => $page_data['title'],
'file' => sprintf('%s.tpl', $page_name));
$page['content'] = render($page, $page_name);
file_put_contents($dstpath, render($page, 'layout'));
}