gl-website-deployer/v.php
2024-11-19 08:02:04 +01:00

57 lines
1.1 KiB
PHP

<?php
require_once dirname(__FILE__).'/common.php';
function page_not_found() {
http_response_code(404);
include('not_found.php');
die();
}
$cwd = dirname(__FILE__);
if (empty($_GET['p'])) {
if (!isset($_SERVER['PATH_INFO'])) {
page_not_found();
} else {
if (empty($_SERVER['PATH_INFO'])) {
page_not_found();
}
$path_info = explode('/', $_SERVER['PATH_INFO']);
if (count($path_info) !== 2) {
page_not_found();
}
if ($path_info[0] !== '') {
page_not_found();
}
$page = $path_info[1];
}
} else {
$page = $_GET['p'];
}
$m = setup_mustache();
$tpl = $m->loadTemplate('public/generic');
$page_md = array();
$parser = new Doctrine\RST\Parser();
$fname = "{$cwd}/generic/{$page}.rst";
if (!file_exists($fname)) {
page_not_found();
}
$handle = fopen($fname, "r");
$page_md['ROOT_URL'] = $iap_root;
$page_md['content'] = $parser->parse(fread($handle, filesize($fname)))->render();
$page_md['other_scripts'] = [WebpackBuiltFiles::$jsFiles['code']];
//$page_md['boot_script'] = "gl.code.runCode();";
fclose($handle);
header('Content-Type: text/html; charset=utf-8');
echo $tpl->render($page_md);