#!/usr/bin/php CSS if ($config['css'] == true) { // Create CSS output directory if needed if (!file_exists(SITE . '/css')) mkdir(SITE . '/css', 0755); require ROOT . '/less.php/lib/Less/Autoloader.php'; Less_Autoloader::register(); $colorScheme = [ 'darkColor' => 'black', 'lightColor' => 'white', 'mainColor' => 'red', ]; $options = [ 'cache_dir' => SITE . '/css', 'compress' => true, ]; if (file_exists(SITE . '/style.less')) $lessFiles = [ROOT . '/style.less' => '', SITE . '/style.less' => '']; else $lessFiles = [ROOT . '/style.less' => '']; define('CSS_FILENAME', Less_Cache::Get($lessFiles, $options, $colorScheme)); } // Determine whether links need to use Onion or DNS function clearnetOrOnion($clearnet_url, $onion_url) { return (DESTINATION === 'onion') ? $onion_url : $clearnet_url; } exec('find ' . SITE . "/src -name '*.gmi' -o -name '*.md'", $pages); foreach ($pages as $page) { $pathParts = pathinfo(str_replace('/src', '', $page)); // Create parent directory if needed if (!file_exists($pathParts['dirname'])) mkdir($pathParts['dirname'], 0755, true); // Execute PHP code ob_start(); eval('?>' . file_get_contents($page)); file_put_contents($pathParts['dirname'] . '/' . $pathParts['basename'], ob_get_contents()); ob_end_clean(); // Convert Gemtext to Markdown if ($pathParts['extension'] === 'gmi') { $gmilines = explode(LF, file_get_contents($pathParts['dirname'] . '/' . $pathParts['basename'])); foreach ($gmilines as $key => $line) { if (substr($line, 0, 2) === '=>') { preg_match('/=> +(.[^ ]+)/', $line, $lnUrl); preg_match('/=> +.[^ ]+ +(.+)/', $line, $lnTitle); $urlPathParts = pathinfo(parse_url($lnUrl[1], PHP_URL_PATH)); // .gmi > .md for local links if (!str_contains($lnUrl[1], ':') AND $urlPathParts['extension'] === 'gmi') // If it's a local link $lnUrl[1] = $urlPathParts['dirname'] . '/' . $urlPathParts['filename'] . '.md'; if (isset($lnTitle[1])) { $gmilines[$key] = '[' . $lnTitle[1] . '](' . $lnUrl[1] . ')'; } else { $gmilines[$key] = '[' . $lnUrl[1] . '](' . $lnUrl[1] . ')'; } } } $code = ''; foreach ($gmilines as $line) { $code = $code . LF . $line; } file_put_contents($pathParts['dirname'] . '/' . $pathParts['filename'] . '.md', $code); } // Compile Markdown to HTML $markdown = file_get_contents($pathParts['dirname'] . '/' . $pathParts['filename'] . '.md'); if (preg_match("/# (.*)\\n/", $markdown, $matches)) // If a main heading is found $title = $matches[1]; // Then it will be the HTML page