diff --git a/router.php b/router.php index 771f464..f4ed95d 100644 --- a/router.php +++ b/router.php @@ -26,6 +26,23 @@ load_page($tryuri); /* HELPER FUNCTIONS START */ + /* Grab json from top */ + $c = file_get_contents($parsef); + if ($c[0] == '{') { + $json = substr($c, 0, strpos($c, '}')+1); + $c = substr($c, strpos($c, '}')+1); + + $obj = json_decode($json); + } + $parse = $pd->text($c); + +function get_md_jsonhead($md) { + $c = file_get_contents($md); + + if ($c[0] != '{') return false; + + return substr($c, 0, strpos($c, '}')+1); +} function get_path_content($path) { $fs = scandir($path); @@ -34,8 +51,15 @@ function get_path_content($path) { for ($i = 2; $i < count($fs); $i++) { $f = "$path/$fs[$i]"; if (!is_dir($f)) { - if (pathinfo($f, PATHINFO_EXTENSION) == "json") { + $ext = substr($f, strrpos($f, '.')+1); + if ($ext == "json") { $titles[] = ["c" => json_decode(file_get_contents($f), true), "link" => uri_from_file($f)]; + } else if ($ext == "md") { + $json = get_md_jsonhead($f); + + if ($json) { + $titles[] = ["c" => json_decode($json, true), "link" => uri_from_file($f)]; + } } } else { $fy = "$f/index.json"; @@ -52,10 +76,7 @@ function uri_from_file($file) { return substr($file, 0, -strlen($name)-1); } - if (!strcmp(substr($file, strrpos($file, '.')+1), "json")) { - - return substr($file, 0, -5); - } + return substr($file, 0, strrpos($file, '.')); } function load_page($tryuri) { @@ -118,7 +139,16 @@ $obj = json_decode($file); if (!empty($parsef)) { $pd = new Parsedown(); - $parse = $pd->text(file_get_contents($parsef)); + + /* Grab json from top */ + $c = file_get_contents($parsef); + if ($c[0] == '{') { + $json = substr($c, 0, strpos($c, '}')+1); + $c = substr($c, strpos($c, '}')+1); + + $obj = json_decode($json); + } + $parse = $pd->text($c); } $page['title'] = $obj->title ?? $site['title'];