This commit is contained in:
wangjinlei
2022-04-06 18:02:49 +08:00
parent e34f87de36
commit c1885928ff
262 changed files with 18633 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types = 1);
namespace hg\apidoc\parseApi;
use think\facade\App;
use hg\apidoc\Utils;
use think\facade\Config;
class ParseMarkdown
{
protected $config = [];
public function __construct()
{
$this->config = Config::get('apidoc')?Config::get('apidoc'):Config::get('apidoc.');
}
/**
* 获取md文档菜单
* @return array
*/
public function getDocsMenu(): array
{
$config = $this->config;
$docData = [];
if (!empty($config['docs']) && !empty($config['docs']['menus']) && count($config['docs']['menus']) > 0) {
$docData = $this->handleDocsMenuData($config['docs']['menus']);
}
return $docData;
}
/**
* 处理md文档菜单数据
* @param array $menus
* @return array
*/
protected function handleDocsMenuData(array $menus): array
{
$list = [];
foreach ($menus as $item) {
if (!empty($item['items']) && count($item['items']) > 0) {
$item['items'] = $this->handleDocsMenuData($item['items']);
$item['group'] = 'markdown_doc';
$item['menu_key'] = "md_group_" . mt_rand(10000, 99999);
$list[] = $item;
} else {
$item['type'] = 'md';
$item['menu_key'] = "md_" . mt_rand(10000, 99999);
$list[] = $item;
}
}
return $list;
}
/**
* 获取md文档内容
* @param string $appKey
* @param string $path
* @return string
*/
public function getContent(string $appKey, string $path): string
{
$currentApps = (new Utils())->getCurrentApps($appKey);
$mdPath = (new Utils())->replaceCurrentAppTemplate($path, $currentApps);
$filePath = App::getRootPath() . $mdPath . '.md';
$contents = Utils::getFileContent($filePath);
return $contents;
}
}