diff --git a/compil.php b/compil.php index 99e80cb..b1d83a6 100755 --- a/compil.php +++ b/compil.php @@ -16,10 +16,33 @@ if (php_sapi_name() === "cli") { if (!file_exists("temp/" . SITE)) mkdir("temp/" . SITE, 555); + // 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; + } + // pages/exemple.md > temp/exemple.temp // Exécute le PHP vers du HTML ob_start(); - require SITE . "/md/" . $pageId . ".md"; + eval("?>" . $code); + //require SITE . "/md/" . $pageId . ".md"; file_put_contents("temp/" . SITE . "/" . $pageId . ".temp", ob_get_contents()); ob_end_clean();