MadelineProto/build_docs_index.php

84 lines
3.3 KiB
PHP
Raw Normal View History

<?php
2018-03-23 16:39:58 +01:00
$index = '';
$files = glob('docs/docs/*md');
foreach ($files as $file) {
$base = basename($file, '.md');
if ($base === 'CREATING_A_CLIENT') {
$orderedfiles[0] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'LOGIN') {
$orderedfiles[1] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'FEATURES') {
$orderedfiles[2] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'REQUIREMENTS') {
$orderedfiles[3] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'INSTALLATION') {
$orderedfiles[4] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'UPDATES') {
$orderedfiles[5] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'SETTINGS') {
$orderedfiles[6] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'SELF') {
$orderedfiles[7] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'EXCEPTIONS') {
$orderedfiles[8] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'FLOOD_WAIT') {
$orderedfiles[9] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'LOGGING') {
$orderedfiles[10] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'USING_METHODS') {
$orderedfiles[11] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'FILES') {
$orderedfiles[12] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'CHAT_INFO') {
$orderedfiles[13] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'DIALOGS') {
$orderedfiles[14] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'INLINE_BUTTONS') {
$orderedfiles[15] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'CALLS') {
$orderedfiles[16] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'SECRET_CHATS') {
$orderedfiles[17] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'LUA') {
$orderedfiles[18] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'PROXY') {
2018-03-20 15:47:34 +01:00
$orderedfiles[19] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'CONTRIB') {
2018-03-20 15:47:34 +01:00
$orderedfiles[20] = $file;
2018-03-23 16:39:58 +01:00
} elseif ($base === 'TEMPLATES') {
2018-03-20 22:18:19 +01:00
$orderedfiles[21] = $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-23 16:39:58 +01:00
while (end($lines) === '' || strpos(end($lines), 'Next')) {
unset($lines[count($lines) - 1]);
2018-03-20 15:51:22 +01:00
}
2018-03-23 16:39:58 +01:00
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';
2018-03-21 10:53:02 +01:00
$lines[count($lines)] = "\n<form action=\"$prevfile\"><input type=\"submit\" value=\"Previous section\" /></form><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);
2018-03-23 16:39:58 +01:00
$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];
2018-03-23 16:39:58 +01:00
$url = $file.'#'.$matches[3][$key];
$index .= "$spaces* [$name]($url)\n";
}
}
}
echo $index;