. */ // get version $version = trim(file_get_contents("docs/version")); // include assorted important utilities include "src/utils.php"; // read arguments from user config $config = parse_ini_file("config.ini"); $repos = strip_trailing_slash($config["repositories"]); $title = $config["title"]; $theme = $config["theme"]; // get file to serve based on URL $url = strip_trailing_slash(substr($_SERVER['REQUEST_URI'], 1)); $page_type = get_page_type($url); if ($page_type === "invalid") { include "src/errors/404.php"; die(); } // homepage does not need to check for Git repo if ($page_type === "home") { include "src/pages/home.php"; die(); } // get Git repo $project = before_first_slash($url); $git_dir = get_git_dir("$repos/$project"); // 404 if not a git directory if (! $git_dir) { include "src/errors/404.php"; die(); } // use cached version if it exists, otherwise make it $last_commit = get_last_commit_time($git_dir); if (file_exists("cache/$url.html") && $last_commit < filemtime("cache/$url.html")) { include "cache/$url.html"; } else { // create directory in cache if it doesn't exist $directory = "cache/" . before_last_slash($url); if (!file_exists($directory)) { mkdir($directory, 0777, true); } // create cached file ob_start(); // get default branch $branch = get_main_git_branch($git_dir); include "src/pages/$page_type.php"; $cache_file = fopen("cache/$url.html", 'w'); fwrite($cache_file, ob_get_contents()); fclose($cache_file); ob_end_flush(); } ?>