MadelineProto/build_docs_index.php

84 lines
3.1 KiB
PHP
Raw Normal View History

<?php
2018-03-23 16:39:58 +01:00
$index = '';
2018-04-01 13:33:36 +02:00
$files = glob('docs/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-04-01 13:55:16 +02:00
$lines[count($lines)] = "\n<a href=\"$nextfile\">Next section</a>";
2018-03-20 20:43:11 +01:00
} else {
2018-04-01 13:55:16 +02:00
$lines[count($lines)] = "\n<a href=\"https://docs.madelineproto.xyz/#very-complex-and-complete-examples\">Next section</a>";
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;