2020-08-02 14:15:06 +02:00
|
|
|
<?php
|
2021-09-15 23:15:48 +02:00
|
|
|
if (php_sapi_name() === "cli") {
|
|
|
|
define("SITE", $argv[1]);
|
|
|
|
define("DESTINATION", $argv[2]);
|
2020-08-02 14:15:06 +02:00
|
|
|
|
|
|
|
require "bibli/parsedown/Parsedown.php";
|
2021-04-05 18:32:22 +02:00
|
|
|
require "bibli/parsedown-extra/ParsedownExtra.php";
|
2021-09-15 23:15:48 +02:00
|
|
|
$nomsPages = array_diff(scandir(SITE . "/md"), array('..', '.'));
|
2021-04-05 18:32:22 +02:00
|
|
|
|
2021-09-15 23:15:48 +02:00
|
|
|
require "inc/url.php";
|
|
|
|
require SITE . "/pages.inc.php";
|
2021-04-05 18:32:22 +02:00
|
|
|
|
|
|
|
foreach ($nomsPages as $pageId) {
|
|
|
|
$pageId = basename($pageId, ".md");
|
|
|
|
|
2021-09-15 23:15:48 +02:00
|
|
|
if (!file_exists("temp/" . SITE))
|
|
|
|
mkdir("temp/" . SITE, 555);
|
2020-08-02 14:15:06 +02:00
|
|
|
|
2021-09-18 19:09:11 +02:00
|
|
|
// Convert Gemtext to Markdown
|
|
|
|
$gmilines = explode("\n", file_get_contents(SITE . "/md/" . $pageId . ".md"));
|
|
|
|
foreach ($gmilines as $key => $line) {
|
|
|
|
if (substr($line, 0, 2) === "=>") {
|
|
|
|
preg_match("/=> +(.[^ ]+)/", $line, $url);
|
|
|
|
preg_match("/=> +.[^ ]+ +(.+)/", $line, $title);
|
|
|
|
$mdSpecial = array("[", "]", "(", ")");
|
|
|
|
$htmlEntities = array("[", "]", "(", ")");
|
|
|
|
$url[1] = str_replace($mdSpecial, $htmlEntities, $url[1]);
|
|
|
|
if (isset($title[1])) {
|
|
|
|
$title[1] = str_replace($mdSpecial, $htmlEntities, $title[1]);
|
|
|
|
$gmilines[$key] = "[" . $title[1] . "](" . $url[1] . ")";
|
|
|
|
} else {
|
|
|
|
$gmilines[$key] = "[" . $url[1] . "](" . $url[1] . ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$code = "";
|
|
|
|
foreach ($gmilines as $line) {
|
|
|
|
$code = $code . "\n" . $line;
|
|
|
|
}
|
|
|
|
|
2020-08-02 14:15:06 +02:00
|
|
|
// pages/exemple.md > temp/exemple.temp
|
2021-04-05 18:32:22 +02:00
|
|
|
// Exécute le PHP vers du HTML
|
2020-08-02 14:15:06 +02:00
|
|
|
ob_start();
|
2021-09-18 19:09:11 +02:00
|
|
|
eval("?>" . $code);
|
|
|
|
//require SITE . "/md/" . $pageId . ".md";
|
2021-09-15 23:15:48 +02:00
|
|
|
file_put_contents("temp/" . SITE . "/" . $pageId . ".temp", ob_get_contents());
|
2020-08-02 14:15:06 +02:00
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
// temp/exemple.temp > temp2/exemple.temp2
|
2021-04-05 18:32:22 +02:00
|
|
|
// Compile le Markdown vers du HTML
|
2021-09-15 23:15:48 +02:00
|
|
|
$contenuPage = file_get_contents("temp/" . SITE . "/" . $pageId . ".temp");
|
2021-04-05 18:32:22 +02:00
|
|
|
|
2021-09-18 19:08:26 +02:00
|
|
|
$Parsedown = new ParsedownExtra;
|
2021-04-05 18:32:22 +02:00
|
|
|
$Parsedown = $Parsedown->setUrlsLinked(false);
|
|
|
|
$Parsedown = $Parsedown->setMarkupEscaped(false);
|
|
|
|
$Parsedown = $Parsedown->setBreaksEnabled(true);
|
|
|
|
$contenuPage = $Parsedown->text($contenuPage);
|
|
|
|
|
2021-09-15 23:15:48 +02:00
|
|
|
file_put_contents("temp/" . SITE . "/" . $pageId . ".temp2", $contenuPage);
|
2020-08-02 14:15:06 +02:00
|
|
|
|
|
|
|
// temp2/exemple.temp2 > exemple.html
|
2021-04-05 18:32:22 +02:00
|
|
|
// Ajoute header et footer au HTML
|
2020-08-02 14:15:06 +02:00
|
|
|
ob_start();
|
2021-04-05 18:32:22 +02:00
|
|
|
|
|
|
|
$pageMetas = getPageMetas($pageId);
|
|
|
|
|
2020-08-02 14:15:06 +02:00
|
|
|
require "inc/debut.php";
|
2021-04-05 18:32:22 +02:00
|
|
|
if ($pageMetas['type'] == "article") {
|
|
|
|
echo "<h1>" . $pageMetas['h1'] . "</h1>";
|
2020-08-02 14:15:06 +02:00
|
|
|
echo "<article>";
|
2021-04-05 18:32:22 +02:00
|
|
|
} else if ($pageMetas['type'] == "centré") {
|
2020-08-02 14:15:06 +02:00
|
|
|
echo "<div class='centre'>";
|
|
|
|
}
|
2021-09-15 23:15:48 +02:00
|
|
|
require "temp/" . SITE . "/" . $pageId . ".temp2";
|
2021-04-05 18:32:22 +02:00
|
|
|
if ($pageMetas['type'] == "article") {
|
2020-08-02 14:15:06 +02:00
|
|
|
echo "</article>";
|
2021-04-05 18:32:22 +02:00
|
|
|
} else if ($pageMetas['type'] == "centré") {
|
2020-08-02 14:15:06 +02:00
|
|
|
echo "</div>";
|
|
|
|
}
|
|
|
|
require "inc/footer.php";
|
2021-09-15 23:15:48 +02:00
|
|
|
file_put_contents(SITE . "/" . $pageId . ".html", ob_get_contents());
|
2020-08-02 14:15:06 +02:00
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// exemple.html > exemple.html.gz
|
2021-04-05 18:32:22 +02:00
|
|
|
// Compresse les fichiers textes statiques HTML & CSS
|
2021-09-15 23:15:48 +02:00
|
|
|
exec('/usr/local/bin/static-compress -c zopfli "' . SITE . '/*.html" "' . SITE . '/*.js" "' . SITE . '/css/*.css"');
|
2020-08-02 14:15:06 +02:00
|
|
|
} else {
|
2021-09-15 23:15:48 +02:00
|
|
|
exit("Must be run from CLI");
|
2020-08-02 14:15:06 +02:00
|
|
|
}
|