From cc89f394b2a1f8a3b2d1a3313e6a533fc481fea9 Mon Sep 17 00:00:00 2001 From: pololi Date: Fri, 14 Jan 2022 15:35:36 +0800 Subject: [PATCH] feat: codefever-community documentation system --- application/controllers/doc.php | 67 ++++----- application/language/english/base_lang.php | 1 + application/language/zh-cn/base_lang.php | 1 + application/views/doc/detail.php | 150 ++++++++++++++----- application/views/newpage/footer_include.php | 1 + application/views/newpage/header_include.php | 5 +- www/static/css/common.css | 2 + www/static/css/main.css | 149 ++++++++++++++++++ www/static/css/markdown.css | 2 +- www/static/images/logo-community-doc.png | Bin 0 -> 12503 bytes 10 files changed, 296 insertions(+), 82 deletions(-) create mode 100644 www/static/images/logo-community-doc.png diff --git a/application/controllers/doc.php b/application/controllers/doc.php index 6e93827..6720f89 100755 --- a/application/controllers/doc.php +++ b/application/controllers/doc.php @@ -20,8 +20,8 @@ class Doc extends Base } public function index () - { - // doing nothing + { + // doing nothing } public function cn() @@ -57,18 +57,35 @@ class Doc extends Base $docDir = array_slice($segments, 2, -1); } - $menuFile = $rootDir . ($docDir ? implode('/', $docDir) : '') . '/index.md'; + $menuFile = $rootDir . 'index.md'; + $menu = $this->_extractMenu($menuFile); + $menuOptions = $menu; + + foreach ($menu as &$item) { + $menuFile = $rootDir . $item['path'] . '/index.md'; + if (!file_exists($menuFile)) { + continue; + } + + $submenu = $this->_extractMenu($menuFile); + foreach ($submenu as &$item2) { + $item2['path'] = $item['path'] . '/' . $item2['path']; + } + + $item['submenu'] = $submenu; + } if (!preg_match('/\.[a-z0-9]+/i', $docFile)) { - // docFile = /data/www/codefever-community/doc/zh-cn/installation - // menuFile = /data/www/codefever-community/doc/zh-cn/installation/index.md - $menuOptions = $this->_extractMenu($menuFile); - - while ($menuOptions && count($menuOptions) > 0) { + $pathinfo = $_SERVER['PATH_INFO']; + while ($menu && count($menuOptions) > 0) { if (strpos($menuOptions[0]['path'], '.') > 0) { - $docFile .= '/' . $menuOptions[0]['path']; + $pathinfo = rtrim($pathinfo, '/'); + $pathinfo .= '/' . $menuOptions[0]['path']; + header("Location: $pathinfo"); break; } else { + $pathinfo = rtrim($pathinfo, '/'); + $pathinfo .= '/' . $menuOptions[0]['path']; $docFile .= '/' . $menuOptions[0]['path']; $menuOptions = $this->_extractMenu($docFile . '/index.md'); } @@ -77,9 +94,8 @@ class Doc extends Base $this->load->view('doc/detail', [ 'segments' => $segments, - 'menu' => str_replace('`', '\`', file_get_contents($menuFile)), + 'menu' => $menu, 'doc' => str_replace('`', '\`', file_get_contents($docFile)), - 'docName' => $this->_docName($rootDir), ]); } @@ -90,7 +106,7 @@ class Doc extends Base $lines = explode("\n", $data); foreach ($lines as $line) { $matches = []; - if (preg_match('/\[(\S+)\]\((\S+)\)/', $line, $matches)) { + if (preg_match('/\[([^\]]+)\]\(([^\)]+)\)/', $line, $matches)) { array_push($output, ['name' => $matches[1], 'path' => trim($matches[2])]); } } @@ -98,33 +114,6 @@ class Doc extends Base return $output; } - private function _docName(string $rootDir) - { - return function (string $path) use ($rootDir) { - if (!$path) { - return FALSE; - } - - $docDir = substr($path, 8); - $docDir = substr($docDir, 0, strrpos($docDir, '/')); - $indexFile = $rootDir . $docDir . '/index.md'; - - if (!file_exists($indexFile)) { - return FALSE; - } - - $path = str_replace(["/", "."], ["\\/", "\\."], $path); - $data = file_get_contents($indexFile); - - preg_match("/\[(.+)\]\({$path}\)/i", $data, $matches); - if (!$matches) { - return FALSE; - } - - return $matches[1]; - }; - } - private function _assets($path) { if (!file_exists($path)) { diff --git a/application/language/english/base_lang.php b/application/language/english/base_lang.php index 7221104..8f25405 100755 --- a/application/language/english/base_lang.php +++ b/application/language/english/base_lang.php @@ -7,3 +7,4 @@ $lang['base_go_home'] = 'Home'; $lang['base_go_prepage'] = 'Return to previous page'; $lang['base_confirm'] = 'Confirm'; + $lang['base_directory'] = 'Directory'; diff --git a/application/language/zh-cn/base_lang.php b/application/language/zh-cn/base_lang.php index 3ae23ab..d0dc39b 100755 --- a/application/language/zh-cn/base_lang.php +++ b/application/language/zh-cn/base_lang.php @@ -7,3 +7,4 @@ $lang['base_error_message_tips'] = '抱歉,请重新尝试访问网站,或 $lang['base_go_home'] = '返回主页'; $lang['base_go_prepage'] = '返回上一页'; $lang['base_confirm'] = '确定'; +$lang['base_directory'] = '目录'; diff --git a/application/views/doc/detail.php b/application/views/doc/detail.php index 1e30f93..46d6d5d 100755 --- a/application/views/doc/detail.php +++ b/application/views/doc/detail.php @@ -6,59 +6,129 @@ Codefever community - Doc - - - + -
+
-
- +
+

- $show = $show == 'cn' ? lang('base_cn') : $show; - $show = $show == 'en' ? lang('base_en') : $show; - ?> - - + +
-
- - - - - -
-
- -
-
-
- -
-
-
+
+
+

+
+ +
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
- - - + \ No newline at end of file diff --git a/application/views/newpage/footer_include.php b/application/views/newpage/footer_include.php index 4e6a381..2fd31e8 100755 --- a/application/views/newpage/footer_include.php +++ b/application/views/newpage/footer_include.php @@ -5,6 +5,7 @@ +