-
Notifications
You must be signed in to change notification settings - Fork 1
/
staticgen.php
58 lines (48 loc) · 1.38 KB
/
staticgen.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
<?php
define('FILES_DIR', "files/");
define('OUT_FOLDER', "out-website/");
env_var('SITE_NAME');
env_var('SAVE_ENABLED');
env_var('REQUIRE_AUTH');
env_var('USER');
env_var('PASS');
function env_var($name) {
$value = getenv($name);
if($value)
$_ENV[$name] = $value;
}
# Create output folder
if(!is_dir(OUT_FOLDER))
mkdir(OUT_FOLDER);
if(!is_dir(OUT_FOLDER.FILES_DIR))
mkdir(OUT_FOLDER.FILES_DIR);
$files = scandir(FILES_DIR);
foreach ($files as $file) {
if($file === "..")
continue;
if(!is_dir(FILES_DIR . $file))
continue;
if($file === ".") # Homepage
unset($_REQUEST['file']);
else {
$_REQUEST['file'] = $file;
# Create folder for page
if(!is_dir(OUT_FOLDER . $file))
mkdir(OUT_FOLDER . $file);
}
$outfile = OUT_FOLDER . ($file === "." ? "" : $file . "/") ."index.html";
ob_start();
include('index.php');
$output = ob_get_clean();
file_put_contents($outfile, $output);
# Copy files
if($file !== ".") {
if(!is_dir(OUT_FOLDER.FILES_DIR.$file))
mkdir(OUT_FOLDER.FILES_DIR.$file);
foreach($list_files as $copyfile) {
echo(FILES_DIR.$file."/".$copyfile." -> ".OUT_FOLDER.FILES_DIR.$file."/".$copyfile."\n");
copy(FILES_DIR.$file."/".$copyfile, OUT_FOLDER.FILES_DIR.$file."/".$copyfile);
}
}
}
?>