文档生成


需求分析

  • 将markdown文档,导入到数据库中

软件设计

composer require symfony/dom-crawler
php artisan make:command DocBuild
php artisan make:listener DocBuildListener
php artisan make:event DocBuild

编码

private function getDirs($dirs)
{
    foreach ($dirs as $dir) {
        $subDirs = Storage::disk('docs')->directories($dir);
        $this->getFiles($dir);
        $subDirs && $this->getDirs($subDirs);
    }
}

public function getTitle($html)
{
    $crawler = new Crawler($html);
    $title = $crawler->filterXPath('//h1');
    !count($title) && $title = $crawler->filterXPath('//h2');
    return count($title) ? $title->text() : null;
}