|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
#!/usr/bin/php |
|
|
|
|
<?php |
|
|
|
|
if (php_sapi_name() !== "cli") |
|
|
|
|
exit("Must be run from CLI"); |
|
|
|
|
exit("Must be run from CLI"); |
|
|
|
|
|
|
|
|
|
// Initialization |
|
|
|
|
|
|
|
|
@ -11,224 +11,219 @@ define("GZIP", "/usr/bin/gzip"); |
|
|
|
|
define("ROOT", dirname($_SERVER['SCRIPT_FILENAME'])); |
|
|
|
|
|
|
|
|
|
if (isset($argv[1])) |
|
|
|
|
define("SITE", $argv[1]); |
|
|
|
|
define("SITE", $argv[1]); |
|
|
|
|
else |
|
|
|
|
define("SITE", getcwd()); |
|
|
|
|
define("SITE", getcwd()); |
|
|
|
|
|
|
|
|
|
if (isset($argv[2])) |
|
|
|
|
define("DESTINATION", $argv[2]); |
|
|
|
|
define("DESTINATION", $argv[2]); |
|
|
|
|
else |
|
|
|
|
define("DESTINATION", "local"); |
|
|
|
|
define("DESTINATION", "local"); |
|
|
|
|
|
|
|
|
|
if (file_exists(SITE . "/config.ini")) |
|
|
|
|
$config = parse_ini_file(SITE . "/config.ini"); |
|
|
|
|
$config = parse_ini_file(SITE . "/config.ini"); |
|
|
|
|
|
|
|
|
|
if (!isset($config['css'])) |
|
|
|
|
$config['css'] = true; |
|
|
|
|
$config['css'] = true; |
|
|
|
|
|
|
|
|
|
if (!isset($config['header'])) |
|
|
|
|
$config['header'] = true; |
|
|
|
|
$config['header'] = true; |
|
|
|
|
|
|
|
|
|
if (!isset($config['centerIndex'])) |
|
|
|
|
$config['centerIndex'] = false; |
|
|
|
|
$config['centerIndex'] = false; |
|
|
|
|
|
|
|
|
|
if (!isset($config['defaultLang'])) |
|
|
|
|
$config['defaultLang'] = ""; |
|
|
|
|
$config['defaultLang'] = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Less > CSS |
|
|
|
|
|
|
|
|
|
// Create CSS output directory if needed |
|
|
|
|
if (!file_exists(SITE . "/css")) |
|
|
|
|
mkdir(SITE . "/css", 0755); |
|
|
|
|
mkdir(SITE . "/css", 0755); |
|
|
|
|
|
|
|
|
|
require ROOT . "/less.php/lib/Less/Autoloader.php"; |
|
|
|
|
Less_Autoloader::register(); |
|
|
|
|
|
|
|
|
|
$colorScheme = array( |
|
|
|
|
"darkColor" => "black", |
|
|
|
|
"lightColor" => "white", |
|
|
|
|
"mainColor" => "red", |
|
|
|
|
"darkColor" => "black", |
|
|
|
|
"lightColor" => "white", |
|
|
|
|
"mainColor" => "red", |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$options = array( |
|
|
|
|
'cache_dir' => SITE . '/css', |
|
|
|
|
'compress' => true, |
|
|
|
|
'cache_dir' => SITE . '/css', |
|
|
|
|
'compress' => true, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (file_exists(SITE . "/style.less")) |
|
|
|
|
$lessFiles = array(ROOT . '/style.less' => '', SITE . '/style.less' => ''); |
|
|
|
|
$lessFiles = array(ROOT . '/style.less' => '', SITE . '/style.less' => ''); |
|
|
|
|
else |
|
|
|
|
$lessFiles = array(ROOT . '/style.less' => ''); |
|
|
|
|
$lessFiles = array(ROOT . '/style.less' => ''); |
|
|
|
|
|
|
|
|
|
define("CSS_FILENAME", Less_Cache::Get($lessFiles, $options, $colorScheme)); |
|
|
|
|
|
|
|
|
|
// 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"; |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
if (DESTINATION === "onion") { |
|
|
|
|
return $onionUrl; |
|
|
|
|
} else { |
|
|
|
|
return $clearnetUrl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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("\n", 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 . "\n" . $line; |
|
|
|
|
} |
|
|
|
|
file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".md", $code); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compile Markdown to HTML with Parsedown |
|
|
|
|
$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 <title> |
|
|
|
|
else |
|
|
|
|
$title = NULL; |
|
|
|
|
require_once ROOT . "/parsedown/Parsedown.php"; |
|
|
|
|
require_once ROOT . "/parsedown-extra/ParsedownExtra.php"; |
|
|
|
|
$Parsedown = new ParsedownExtra; |
|
|
|
|
$Parsedown = $Parsedown->setUrlsLinked(false); |
|
|
|
|
$Parsedown = $Parsedown->setMarkupEscaped(false); |
|
|
|
|
$Parsedown = $Parsedown->setBreaksEnabled(true); |
|
|
|
|
$pageContent = $Parsedown->text($markdown); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// .md > .html for local links |
|
|
|
|
$pageContent = preg_replace('#<a href="(?!.*:)(.*)\.md">#', '<a href="$1.html">', $pageContent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add header and footer to HTML |
|
|
|
|
|
|
|
|
|
$urlPath = str_replace(SITE, "", $pathParts['dirname']); |
|
|
|
|
$relativePathToRoot = ""; |
|
|
|
|
for ($i = substr_count($urlPath, "/") ; $i > 0 ; $i--) |
|
|
|
|
$relativePathToRoot .= "../"; |
|
|
|
|
|
|
|
|
|
ob_start(); |
|
|
|
|
|
|
|
|
|
?> |
|
|
|
|
<!DOCTYPE html> |
|
|
|
|
<html lang="<?php |
|
|
|
|
|
|
|
|
|
preg_match("#\.([a-zA-Z-]{2,5})\.#", $pathParts['basename'], $lang); |
|
|
|
|
if (isset($lang[1])) { |
|
|
|
|
echo $lang[1]; |
|
|
|
|
} else { |
|
|
|
|
preg_match("#/([a-z]{2})(/|$)#", $pathParts['dirname'], $lang); |
|
|
|
|
if (isset($lang[1])) |
|
|
|
|
echo $lang[1]; |
|
|
|
|
else |
|
|
|
|
echo $config['defaultLang']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
?>"> |
|
|
|
|
<head> |
|
|
|
|
<meta charset="UTF-8"> |
|
|
|
|
<?php |
|
|
|
|
if (isset($title) AND !is_null($title) AND isset($config['siteTitle'])) |
|
|
|
|
echo "<title>" . $title . " · " . $config['siteTitle'] . "</title>"; |
|
|
|
|
else if (isset($title) AND !is_null($title)) |
|
|
|
|
echo "<title>" . $title . "</title>"; |
|
|
|
|
else if (isset($config['siteTitle'])) |
|
|
|
|
echo "<title>" . $config['siteTitle'] . "</title>"; |
|
|
|
|
?> |
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
|
|
|
<?php if ($config['css']) { ?> |
|
|
|
|
<link rel="stylesheet" media="screen" href="<?= $relativePathToRoot ?>css/<?= CSS_FILENAME ?>">
|
|
|
|
|
<?php } ?> |
|
|
|
|
<?php |
|
|
|
|
if (file_exists(SITE . "/head.inc.html")) |
|
|
|
|
echo file_get_contents(SITE . "/head.inc.html"); |
|
|
|
|
?> |
|
|
|
|
</head> |
|
|
|
|
|
|
|
|
|
<body> |
|
|
|
|
<?php |
|
|
|
|
if ($config['header']) { |
|
|
|
|
?> |
|
|
|
|
<header> |
|
|
|
|
<a id="lienHeader" href="./<?= $relativePathToRoot ?>">
|
|
|
|
|
<?php |
|
|
|
|
if (file_exists(SITE . "/img/logo.webp")) |
|
|
|
|
echo '<img src="img/logo.webp" ' . getimagesize(SITE . "/img/logo.webp")[3] . ' alt="' . $config['siteTitle'] . '" />'; |
|
|
|
|
else |
|
|
|
|
echo $config['siteTitle']; |
|
|
|
|
?> |
|
|
|
|
</a> |
|
|
|
|
</header> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
?> |
|
|
|
|
|
|
|
|
|
<?php |
|
|
|
|
if ($config['centerIndex'] AND $pathParts['filename'] === "index") { |
|
|
|
|
echo '<div class="centered">'; |
|
|
|
|
} else { |
|
|
|
|
echo "<main>"; |
|
|
|
|
} |
|
|
|
|
echo $pageContent; |
|
|
|
|
if ($config['centerIndex'] AND $pathParts['filename'] === "index") { |
|
|
|
|
echo "</div>"; |
|
|
|
|
} else { |
|
|
|
|
echo "</main>"; |
|
|
|
|
} |
|
|
|
|
if (file_exists(SITE . "/end.inc.html")) |
|
|
|
|
require SITE . "/end.inc.html"; |
|
|
|
|
echo "</body></html>"; |
|
|
|
|
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"); |
|
|
|
|
$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("\n", 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 . "\n" . $line; |
|
|
|
|
} |
|
|
|
|
file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".md", $code); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compile Markdown to HTML with Parsedown |
|
|
|
|
$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 <title> |
|
|
|
|
else |
|
|
|
|
$title = NULL; |
|
|
|
|
require_once ROOT . "/parsedown/Parsedown.php"; |
|
|
|
|
require_once ROOT . "/parsedown-extra/ParsedownExtra.php"; |
|
|
|
|
$Parsedown = new ParsedownExtra; |
|
|
|
|
$Parsedown = $Parsedown->setUrlsLinked(false); |
|
|
|
|
$Parsedown = $Parsedown->setMarkupEscaped(false); |
|
|
|
|
$Parsedown = $Parsedown->setBreaksEnabled(true); |
|
|
|
|
$pageContent = $Parsedown->text($markdown); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// .md > .html for local links |
|
|
|
|
$pageContent = preg_replace('#<a href="(?!.*:)(.*)\.md">#', '<a href="$1.html">', $pageContent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add header and footer to HTML |
|
|
|
|
|
|
|
|
|
$urlPath = str_replace(SITE, "", $pathParts['dirname']); |
|
|
|
|
$relativePathToRoot = ""; |
|
|
|
|
for ($i = substr_count($urlPath, "/") ; $i > 0 ; $i--) |
|
|
|
|
$relativePathToRoot .= "../"; |
|
|
|
|
|
|
|
|
|
ob_start(); |
|
|
|
|
|
|
|
|
|
?> |
|
|
|
|
<!DOCTYPE html> |
|
|
|
|
<html lang="<?php |
|
|
|
|
|
|
|
|
|
preg_match("#\.([a-zA-Z-]{2,5})\.#", $pathParts['basename'], $lang); |
|
|
|
|
if (isset($lang[1])) { |
|
|
|
|
echo $lang[1]; |
|
|
|
|
} else { |
|
|
|
|
preg_match("#/([a-z]{2})(/|$)#", $pathParts['dirname'], $lang); |
|
|
|
|
if (isset($lang[1])) |
|
|
|
|
echo $lang[1]; |
|
|
|
|
else |
|
|
|
|
echo $config['defaultLang']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
?>"> |
|
|
|
|
<head> |
|
|
|
|
<meta charset="UTF-8"> |
|
|
|
|
<?php |
|
|
|
|
if (isset($title) AND !is_null($title) AND isset($config['siteTitle'])) |
|
|
|
|
echo "<title>" . $title . " · " . $config['siteTitle'] . "</title>"; |
|
|
|
|
else if (isset($title) AND !is_null($title)) |
|
|
|
|
echo "<title>" . $title . "</title>"; |
|
|
|
|
else if (isset($config['siteTitle'])) |
|
|
|
|
echo "<title>" . $config['siteTitle'] . "</title>"; |
|
|
|
|
?> |
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
|
|
|
<?php |
|
|
|
|
if ($config['css']) { |
|
|
|
|
?> |
|
|
|
|
<link rel="stylesheet" media="screen" href="<?= $relativePathToRoot ?>css/<?= CSS_FILENAME ?>">
|
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (file_exists(SITE . "/head.inc.html")) |
|
|
|
|
echo file_get_contents(SITE . "/head.inc.html"); |
|
|
|
|
?> |
|
|
|
|
</head> |
|
|
|
|
|
|
|
|
|
<body> |
|
|
|
|
<?php |
|
|
|
|
if ($config['header']) { |
|
|
|
|
?> |
|
|
|
|
<header> |
|
|
|
|
<a id="lienHeader" href="./<?= $relativePathToRoot ?>">
|
|
|
|
|
<?php |
|
|
|
|
if (file_exists(SITE . "/img/logo.webp")) |
|
|
|
|
echo '<img src="img/logo.webp" ' . getimagesize(SITE . "/img/logo.webp")[3] . ' alt="' . $config['siteTitle'] . '" />'; |
|
|
|
|
else |
|
|
|
|
echo $config['siteTitle']; |
|
|
|
|
?> |
|
|
|
|
</a> |
|
|
|
|
</header> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($config['centerIndex'] AND $pathParts['filename'] === "index") |
|
|
|
|
echo '<div class="centered">' . $pageContent . "</div>"; |
|
|
|
|
else |
|
|
|
|
echo "<main>" . $pageContent . "</main>"; |
|
|
|
|
if (file_exists(SITE . "/end.inc.html")) |
|
|
|
|
require SITE . "/end.inc.html"; |
|
|
|
|
echo "</body></html>"; |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|