setMarkupEscaped(true); } $output = $input; $output = fix_indentation($output); $output = expand_wikilinks($output); $output = $parser->text($output); return $output; } function page_breadcrumb($page, $sidebar) { $title = preg_quote(page_title($page), '!'); $lines = explode("\n", $sidebar); $index = $level = null; foreach ($lines as $line_no => $line) { if (preg_match('![\[\*\|]' . $title . '[\]\*]!', $line)) { $index = $line_no; $level = strpos($line, '* '); break; } } if (!$index) return []; for ($i = $index - 1; $i > 0; $i--) { $line = $lines[$i]; if (strpos($line, '* ') < $level) { $level = strpos($line, '* '); if (preg_match('|(\[\[[^\]]+\]\])|', $line, $matches)) { list($page, $title) = parse_wikilink($matches[1]); $breadcrumb[] = [$title, $page]; } else if (preg_match('|\* \*\*([^\*]+)\*\*|', $line, $matches)) { $breadcrumb[] = [$matches[1], null]; } } if (!$level) break; } $breadcrumb[] = ['Home', 'Home']; return array_reverse($breadcrumb); } $sidebar = render_markdown(file_get_contents('_Sidebar.md')); $footer = render_markdown(file_get_contents('_Footer.md')); $matched = preg_match('|^/([0-9A-Za-z&-]+)$|', $_SERVER['REQUEST_URI'], $matches); $timestamp = time(); $page = null; $title = null; $breadcrumb = []; if ($matched && file_exists($matches[1] . '.md')) { $page = $matches[1]; $filename = $page . '.md'; if (is_link($filename)) { $filename = readlink($filename); http_response_code(301); header('Location: /' . str_replace('.md', '', $filename)); return; } else if ($page == 'Home') { $breadcrumb = []; $timestamp = time(); $title = null; $content = render_markdown(file_get_contents($filename)); } else { $breadcrumb = page_breadcrumb($page, file_get_contents('_Sidebar.md')); $timestamp = filemtime($filename); $title = page_title($page); $content = render_markdown(file_get_contents($filename)); $content = "