$filename) { $lines = explode("\n", file_get_contents($filename)); while (end($lines) === '' || strpos(end($lines), "Next")) { unset($lines[count($lines)-1]); } if (isset($orderedfiles[$key+1])) { $nextfile = "https://docs.madelineproto.xyz/docs/".basename($orderedfiles[$key+1], '.md').".html"; $prevfile = $key === 0 ? "https://docs.madelineproto.xyz" : "https://docs.madelineproto.xyz/docs/".basename($orderedfiles[$key-1], '.md').".html"; $lines[count($lines)] = "\n
"; } else { $lines[count($lines)] = "\n"; } file_put_contents($filename, implode("\n", $lines)); preg_match('|^# (.*)|', $file = file_get_contents($filename), $matches); $title = $matches[1]; preg_match_all('|( *)\* \[(.*)\]\(#(.*)\)|', $file, $matches); $file = "https://docs.madelineproto.xyz/docs/".basename($filename, '.md').".html"; $index .= "* [$title]($file)\n"; if (basename($filename) !== 'FEATURES.md') { foreach ($matches[1] as $key => $match) { $spaces = " $match"; $name = $matches[2][$key]; $url = $file."#".$matches[3][$key]; $index .= "$spaces* [$name]($url)\n"; } } } echo $index;