From 6dd180542e15c45b922c188eedb6b8cfec435186 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 11 Apr 2018 14:18:03 +0200 Subject: [PATCH] Improve documentation builder --- README.md | 4 ++-- build_docs_index.php | 38 +++++++++++++++++++++++++++++++++----- docs | 2 +- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cdd389d1..80674e17 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,6 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [Simple (manual)](https://docs.madelineproto.xyz/docs/INSTALLATION.html#simple-manual) * [Composer from scratch](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-scratch) * [Composer from existing project](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project) - * [Git](https://docs.madelineproto.xyz/docs/INSTALLATION.html#git) * [Handling updates](https://docs.madelineproto.xyz/docs/UPDATES.html) * [Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#event-driven) * [Event driven multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#event-driven-multithreaded) @@ -78,7 +77,9 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [Avoiding FLOOD_WAITs](https://docs.madelineproto.xyz/docs/FLOOD_WAIT.html) * [Logging](https://docs.madelineproto.xyz/docs/LOGGING.html) * [Using methods](https://docs.madelineproto.xyz/docs/USING_METHODS.html) + * [FULL API Documentation with descriptions](https://docs.madelineproto.xyz/API_docs/methods) * [Peers](https://docs.madelineproto.xyz/docs/USING_METHODS.html#peers) + * [Files](https://docs.madelineproto.xyz/docs/FILES.html) * [Secret chats](https://docs.madelineproto.xyz/docs/USING_METHODS.html#secret-chats) * [Entities (Markdown & HTML)](https://docs.madelineproto.xyz/docs/USING_METHODS.html#entities) * [reply_markup (keyboards & inline keyboards)](https://docs.madelineproto.xyz/docs/USING_METHODS.html#reply_markup) @@ -132,7 +133,6 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [Credits](https://docs.madelineproto.xyz/docs/CONTRIB.html#credits) * [Web templates for `$MadelineProto->start()`](https://docs.madelineproto.xyz/docs/TEMPLATES.html) - ## Very complex and complete examples You can find examples for nearly every MadelineProto function in diff --git a/build_docs_index.php b/build_docs_index.php index ce0bcfdc..fd513284 100644 --- a/build_docs_index.php +++ b/build_docs_index.php @@ -57,6 +57,19 @@ foreach ($orderedfiles as $key => $filename) { while (end($lines) === '' || strpos(end($lines), 'Next')) { unset($lines[count($lines) - 1]); } + 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', '---'); + 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'; @@ -66,18 +79,33 @@ foreach ($orderedfiles as $key => $filename) { } file_put_contents($filename, implode("\n", $lines)); - preg_match('|^# (.*)|', $file = file_get_contents($filename), $matches); - $title = $matches[1]; - preg_match_all('|( *)\* \[(.*)\]\(#(.*)\)|', $file, $matches); + $file = file_get_contents($filename); + + 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]; + $url = $matches[3][$key][0] === '#' ? $file.$matches[3][$key] : $matches[3][$key]; $index .= "$spaces* [$name]($url)\n"; } } } -echo $index; + +$readme = explode("## ", file_get_contents('README.md')); +foreach ($readme as &$section) { + if (explode("\n", $section)[0] === 'Documentation') { + $section = "Documentation\n\n".$index."\n"; + } +} +$readme = implode("## ", $readme); + +file_put_contents('README.md', $readme); +file_put_contents('docs/docs/index.md', "--- +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 +--- +".$readme); diff --git a/docs b/docs index d7fb09c3..b6152298 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit d7fb09c3cae7e41d66d4ce86e0cfc48255b27122 +Subproject commit b6152298e377fe696e67971d889833fa1f36da8e