Huge additions to finbrook.co; add json headers to top of md files

This commit is contained in:
John Alanbrook 2022-11-09 23:27:55 +00:00
parent 89c5ea41f4
commit 06de890360

View file

@ -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'];