MadelineProto/build_docs_index.php

112 lines
4.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-04-11 14:18:03 +02:00
if ($lines[0] === '---') {
array_shift($lines);
while ($lines[0] !== '---') {
array_shift($lines);
}
array_shift($lines);
}
preg_match('|^# (.*)|', $lines[0], $matches);
$title = $matches[1];
$description = $lines[2];
array_unshift($lines, '---', 'title: '.$title, 'description: '.$description, 'image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png', '---');
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
2018-04-11 14:18:03 +02:00
$file = file_get_contents($filename);
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-04-11 14:18:03 +02:00
$url = $matches[3][$key][0] === '#' ? $file.$matches[3][$key] : $matches[3][$key];
$index .= "$spaces* [$name]($url)\n";
}
}
}
2018-04-11 14:18:03 +02:00
2018-04-11 14:18:45 +02:00
$readme = explode('## ', file_get_contents('README.md'));
2018-04-11 14:18:03 +02:00
foreach ($readme as &$section) {
if (explode("\n", $section)[0] === 'Documentation') {
$section = "Documentation\n\n".$index."\n";
}
}
2018-04-11 14:18:45 +02:00
$readme = implode('## ', $readme);
2018-04-11 14:18:03 +02:00
file_put_contents('README.md', $readme);
2018-04-11 14:18:45 +02:00
file_put_contents('docs/docs/index.md', '---
2018-04-11 14:18:03 +02:00
title: MadelineProto documentation
description: PHP client/server for the telegram MTProto protocol (a better tg-cli)
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
2018-04-11 14:18:45 +02:00
'.$readme);