Add support for Gemtext

This commit is contained in:
Miraty 2021-09-18 19:09:11 +02:00
parent faeaa742ac
commit 04b15ae80d
1 changed files with 24 additions and 1 deletions

View File

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