From 6c223a5d426510cd0077c41ce3ad61ed76cef17c Mon Sep 17 00:00:00 2001 From: filesite Date: Sun, 17 Sep 2023 16:26:04 +0800 Subject: [PATCH] tajian list/ done --- themes/tajian/controller/ListController.php | 80 ++++++++++----------- themes/tajian/views/site/index.php | 3 +- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/themes/tajian/controller/ListController.php b/themes/tajian/controller/ListController.php index 2491fbd..7bba910 100644 --- a/themes/tajian/controller/ListController.php +++ b/themes/tajian/controller/ListController.php @@ -45,31 +45,27 @@ Class ListController extends SiteController { $dirTree = $sortedTree['dirTree']; } - //获取目录面包屑 - $cateId = $this->get('id', $menus[0]['id']); - $subcate = $scanResults[$cateId]; - $breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate); - - //获取当前目录下的readme - $cateReadmeFile = $scanner->getDefaultReadme($cateId); - if (!empty($cateReadmeFile)) { - $Parsedown = new Parsedown(); - $content = file_get_contents($cateReadmeFile['realpath']); - $htmlCateReadme = $Parsedown->text($content); - $htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); - } - //获取tags分类 $tags = $this->getTags($dirTree); - //TODO: 根据tag获取相关数据,并传给视图;调整视图兼容tag的数据结构 - + //获取目录面包屑 + $tagId = $cateId = $this->get('id', ''); + $tagItem = $tags[$tagId]; + $breadcrumbs = $this->getBreadcrumbs($scanResults, $tagItem); + + //根据tag获取相关数据,并传给视图;调整视图兼容tag的数据结构 + if (!empty($tags)) { + foreach($tags as $id => $tag) { + $scanResults[$id]['files'] = $this->getTagFiles($tag, $scanResults); + } + } + $pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; - if (!empty($subcate)) { - $pageTitle = "{$subcate['directory']}相关视频,来自{$defaultTitle}"; - if (!empty($subcate['title'])) { - $pageTitle = "{$subcate['title']},来自{$defaultTitle}"; + if (!empty($tagItem)) { + $pageTitle = "{$tagItem['name']}相关视频,来自{$defaultTitle}"; + if (!empty($tagItem['title'])) { + $pageTitle = "{$tagItem['title']},来自{$defaultTitle}"; } } $viewName = '//site/index'; //共享视图 @@ -78,36 +74,32 @@ Class ListController extends SiteController { } //根据目录结构以及当前目录获取面包屑 - protected function getBreadcrumbs($menus, $subcate) { + protected function getBreadcrumbs($menus, $tag) { $breads = array(); - if (!empty($subcate['directory'])) { - array_push($breads, [ - 'id' => $subcate['id'], - 'name' => $subcate['directory'], - 'url' => $subcate['path'], - ]); - }else { //如果是文件 - array_push($breads, [ - 'id' => $subcate['id'], - 'name' => $subcate['filename'], - 'url' => $subcate['path'], - ]); - } - + array_push($breads, [ + 'id' => $tag['id'], + 'name' => $tag['name'], + 'url' => "/list/?id={$tag['id']}", + ]); + + return $breads; + } - $parent = !empty($menus[$subcate['pid']]) ? $menus[$subcate['pid']] : null; - while($parent) { - array_unshift($breads, [ - 'id' => $parent['id'], - 'name' => $parent['directory'], - 'url' => $parent['path'], - ]); + //根据tag的filenames获取它们的files数据,数据结构保持跟原file一致 + protected function getTagFiles($tag, $scanResults) { + $files = array(); + if (empty($tag['files'])) {return $files;} - $parent = !empty($parent['pid']) && !empty($menus[$parent['pid']]) ? $menus[$parent['pid']] : null; + foreach($tag['files'] as $filename) { + foreach($scanResults as $id => $item) { + if (!empty($item['filename']) && $item['filename'] == $filename && $item['extension'] == 'url') { + $files[$id] = $item; + } + } } - return $breads; + return $files; } } diff --git a/themes/tajian/views/site/index.php b/themes/tajian/views/site/index.php index 36b8e18..642e2b0 100644 --- a/themes/tajian/views/site/index.php +++ b/themes/tajian/views/site/index.php @@ -1,7 +1,7 @@