MadelineProto/build_docs_index.php

85 lines
3.1 KiB
PHP
Raw Normal View History

<?php
$index = '';
$files = glob('docs/docs/*md');
foreach ($files as $file) {
$base = basename($file, '.md');
if ($base === 'CREATING_A_CLIENT') {
$orderedfiles[0] = $file;
} else if ($base === 'LOGIN') {
$orderedfiles[1] = $file;
} else if ($base === 'FEATURES') {
$orderedfiles[2] = $file;
} else if ($base === 'REQUIREMENTS') {
$orderedfiles[3] = $file;
} else if ($base === 'INSTALLATION') {
$orderedfiles[4] = $file;
} else if ($base === 'UPDATES') {
$orderedfiles[5] = $file;
} else if ($base === 'SETTINGS') {
$orderedfiles[6] = $file;
} else if ($base === 'SELF') {
$orderedfiles[7] = $file;
} else if ($base === 'EXCEPTIONS') {
$orderedfiles[8] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'FLOOD_WAIT') {
$orderedfiles[9] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'LOGGING') {
$orderedfiles[10] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'USING_METHODS') {
$orderedfiles[11] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'FILES') {
$orderedfiles[12] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'CHAT_INFO') {
$orderedfiles[13] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'DIALOGS') {
$orderedfiles[14] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'INLINE_BUTTONS') {
$orderedfiles[15] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'CALLS') {
$orderedfiles[16] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'SECRET_CHATS') {
$orderedfiles[17] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'LUA') {
$orderedfiles[18] = $file;
2018-03-20 15:47:34 +01:00
} else if ($base === 'PROXY') {
$orderedfiles[19] = $file;
} else if ($base === 'CONTRIBUTING') {
$orderedfiles[20] = $file;
} else {
$orderedfiles[] = $file;
}
2018-03-20 15:47:34 +01:00
ksort($orderedfiles);
}
ksort($orderedfiles);
2018-03-20 15:51:22 +01:00
foreach ($orderedfiles as $key => $filename) {
2018-03-20 15:47:34 +01:00
$lines = explode("\n", file_get_contents($filename));
2018-03-20 20:43:11 +01:00
while (end($lines) === '') {
unset($lines[count($lines)-1]);
}
2018-03-20 15:51:22 +01:00
if (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";
2018-03-20 17:36:07 +01:00
$lines[count($lines)] = "\n<form action=\"$nextfile\"><input type=\"submit\" value=\"Next section\" /></form>";
2018-03-20 20:43:11 +01:00
} else {
$lines[count($lines)] = "\n<form action=\"https://docs.madelineproto.xyz/#very-complex-and-complete-examples\"><input type=\"submit\" value=\"Next section\" /></form>";
2018-03-20 15:51:22 +01:00
}
file_put_contents($filename, implode("\n", $lines));
2018-03-20 15:47:34 +01:00
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;