#!/usr/bin/php CSS require ROOT . "/bibli/less.php/lib/Less/Autoloader.php"; Less_Autoloader::register(); $colorScheme = array( "darkColor" => "#2a2a2a", "darkerColor" => "#222222", "lightColor" => "white", "lightlessColor" => "#eeeeee", "mainColor" => "red", ); if ($config['trueBlack']) { $colorScheme['darkColor'] = "#000000"; $colorScheme['darkerColor'] = "#000000"; } $options = array('cache_dir' => SITE . '/css', 'compress' => true); if (file_exists(SITE . "/style.less")) $lessFiles = array(ROOT . '/style.less' => '', SITE . '/style.less' => ''); else $lessFiles = array(ROOT . '/style.less' => ''); define("CSS_FILENAME", Less_Cache::Get($lessFiles, $options, $colorScheme)); exec(FIND . " " . SITE . " -name '*.gmi' -o -name '*.md'", $pages); // URLs don't end with .html on the Antopie website function formerUrlLocale($page) { if (DESTINATION === "dns" OR DESTINATION === "onion") { echo $page; } else { echo $page . ".html"; } } // Determine whether links need to use Onion or DNS function clearnetOrOnion($clearnetUrl, $onionUrl) { if (DESTINATION === "onion") { return $onionUrl; } else { return $clearnetUrl; } } foreach ($pages as $page) { $pathParts = pathinfo($page); // Convert Gemtext to Markdown if ($pathParts['extension'] === "gmi") { $gmilines = explode("\n", file_get_contents($page)); if (substr($gmilines[0], 0, 2) === "# ") $title = substr($gmilines[0], 2); else $title = NULL; foreach ($gmilines as $key => $line) { if (substr($line, 0, 2) === "=>") { preg_match("/=> +(.[^ ]+)/", $line, $lnUrl); preg_match("/=> +.[^ ]+ +(.+)/", $line, $lnTitle); // Escape Markdown special characters $mdSpecial = array("[", "]", "(", ")"); $htmlEntities = array("[", "]", "(", ")"); $lnUrl[1] = str_replace($mdSpecial, $htmlEntities, $lnUrl[1]); $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])) { $lnTitle[1] = str_replace($mdSpecial, $htmlEntities, $lnTitle[1]); $gmilines[$key] = "[" . $lnTitle[1] . "](" . $lnUrl[1] . ")"; } else { $gmilines[$key] = "[" . $lnUrl[1] . "](" . $lnUrl[1] . ")"; } } } $code = ""; foreach ($gmilines as $line) { $code = $code . "\n" . $line; } file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".md", $code); } // Execute PHP code ob_start(); eval("?>" . file_get_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".md")); $pageContent = ob_get_contents(); ob_end_clean(); // Compile Markdown to HTML with Parsedown require_once ROOT . "/bibli/parsedown/Parsedown.php"; require_once ROOT . "/bibli/parsedown-extra/ParsedownExtra.php"; $Parsedown = new ParsedownExtra; $Parsedown = $Parsedown->setUrlsLinked(false); $Parsedown = $Parsedown->setMarkupEscaped(false); $Parsedown = $Parsedown->setBreaksEnabled(true); $pageContent = $Parsedown->text($pageContent); // .md > .html for local links $pageContent = preg_replace('##', '', $pageContent); // Add header and footer to HTML ob_start(); ?> <?php if (isset($title) AND !is_null($title)) echo $title . " ยท " . $config['siteTitle']; else echo $config['siteTitle']; ?>
"; } else { echo "
"; } echo $pageContent; if ($config['centerIndex'] AND $pathParts['filename'] === "index") { echo ""; } else { echo "
"; } echo "
"; if (file_exists(SITE . "/end.inc.html")) require SITE . "/end.inc.html"; echo ""; file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".html", ob_get_contents()); ob_end_clean(); // Gzip compression exec(GZIP . " --keep --fast --force " . $pathParts['dirname'] . "/" . $pathParts['filename'] . ".html"); } exec(GZIP . " --keep --fast --force " . SITE . "/css/" . CSS_FILENAME);