From abcbf71ea3c55fa2c38dbbf7a3324ca5471c4e9f Mon Sep 17 00:00:00 2001 From: filesite Date: Sun, 24 Apr 2022 10:10:08 +0800 Subject: [PATCH] add description and cate readme support --- lib/DirScanner.php | 16 ++++------------ test/DirScannerTest.php | 2 +- .../googleimage/controller/ListController.php | 18 ++++++++++++++---- .../googleimage/controller/SiteController.php | 19 +++++++++++++++---- themes/googleimage/views/site/index.php | 16 +++++++++++++++- www/content/README.md | 2 +- www/css/googleimage.css | 2 ++ 7 files changed, 52 insertions(+), 23 deletions(-) diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 1c7bc5f..cad32fd 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -679,11 +679,11 @@ Class DirScanner { } //获取指定目录下名称为README.md的文件 - public function getDefaultReadme($dirpath = '') { + public function getDefaultReadme($dirid = '') { $readme = null; $md = null; - if (empty($dirpath) && !empty($this->tree)) { + if (empty($dirid) && !empty($this->tree)) { foreach($this->tree as $id => $file) { if (!empty($file['extension']) && $file['extension'] == 'md') { $md = $file; @@ -694,19 +694,11 @@ Class DirScanner { } } }else if (!empty($this->scanResults)) { - $dir_realpath = realpath("{$this->rootDir}/{$dirpath}"); - $directory = null; - foreach($this->scanResults as $id => $file) { - if (!empty($file['directory']) && $dir_realpath == $file['realpath']) { - $directory = $file; - break; - } - } - + $directory = $this->scanResults[$dirid]; if (!empty($directory) && !empty($directory['files'])) { foreach($directory['files'] as $id => $file) { if (!empty($file['extension']) && $file['extension'] == 'md') { - $md = $file; + if (empty($md)) {$md = $file;} //取第一个md文件 if (strtoupper($file['filename']) == 'README') { $readme = $file; break; diff --git a/test/DirScannerTest.php b/test/DirScannerTest.php index 52673e7..792d5c6 100644 --- a/test/DirScannerTest.php +++ b/test/DirScannerTest.php @@ -82,7 +82,7 @@ echo "\n"; exit; -//$readmeFile = $scanner->getDefaultReadme('favs/'); +//$readmeFile = $scanner->getDefaultReadme('目录id'); $readmeFile = $scanner->getDefaultReadme(); if (!empty($readmeFile)) { $readme_id = $readmeFile['id']; diff --git a/themes/googleimage/controller/ListController.php b/themes/googleimage/controller/ListController.php index 0439719..d60e316 100644 --- a/themes/googleimage/controller/ListController.php +++ b/themes/googleimage/controller/ListController.php @@ -19,27 +19,37 @@ Class ListController extends Controller { $cateId = $this->get('id', $menus[0]['id']); $titles = []; - $html = ''; + $htmlReadme = ''; $readmeFile = $scanner->getDefaultReadme(); if (!empty($readmeFile)) { $titles = $scanner->getMDTitles($readmeFile['id']); $Parsedown = new Parsedown(); $content = file_get_contents($readmeFile['realpath']); - $html = $Parsedown->text($content); - $html = $scanner->fixMDUrls($readmeFile['realpath'], $html); + $htmlReadme = $Parsedown->text($content); + $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); } //获取目录面包屑 $subcate = $scanResults[$cateId]; $breadcrumbs = $this->getBreadcrumbs($menus, $subcate); + //获取当前目录下的readme + $htmlCateReadme = ''; + $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); + } + $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; if (!empty($subcate)) { $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; } $viewName = '//site/index'; //共享视图 - $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html', 'breadcrumbs'); + $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme'); return $this->render($viewName, $params, $pageTitle); } diff --git a/themes/googleimage/controller/SiteController.php b/themes/googleimage/controller/SiteController.php index 74a4696..0080a69 100644 --- a/themes/googleimage/controller/SiteController.php +++ b/themes/googleimage/controller/SiteController.php @@ -19,24 +19,35 @@ Class SiteController extends Controller { $cateId = $this->get('id', $menus[0]['id']); $titles = []; - $html = ''; + $htmlReadme = ''; $readmeFile = $scanner->getDefaultReadme(); if (!empty($readmeFile)) { $titles = $scanner->getMDTitles($readmeFile['id']); $Parsedown = new Parsedown(); $content = file_get_contents($readmeFile['realpath']); - $html = $Parsedown->text($content); - $html = $scanner->fixMDUrls($readmeFile['realpath'], $html); + $htmlReadme = $Parsedown->text($content); + $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); } $subcate = $scanResults[$cateId]; + + //获取当前目录下的readme + $htmlCateReadme = ''; + $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); + } + $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; if (!empty($subcate)) { $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; } $viewName = 'index'; - $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html'); + $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); return $this->render($viewName, $params, $pageTitle); } diff --git a/themes/googleimage/views/site/index.php b/themes/googleimage/views/site/index.php index 3b36725..7f64964 100644 --- a/themes/googleimage/views/site/index.php +++ b/themes/googleimage/views/site/index.php @@ -45,6 +45,20 @@ eof; $imgExts = ['jpg', 'jpeg', 'png', 'gif']; $category = $viewData['scanResults'][$selectedId]; + //当前目录的描述介绍 + if (!empty($category['description'])) { + echo <<{$category['description']}

+eof; + } + + //当前目录的readme详细介绍 + if (!empty($viewData['htmlCateReadme'])) { + echo <<{$viewData['htmlCateReadme']} +eof; + } + if (!empty($category['directories'])) { //两级目录支持 foreach($category['directories'] as $dir) { echo <<
\ No newline at end of file diff --git a/www/content/README.md b/www/content/README.md index af77604..042eda7 100644 --- a/www/content/README.md +++ b/www/content/README.md @@ -45,7 +45,7 @@ filesite使用非常简单,一旦部署好之后,以后只需将本地最新 * 待续 4. 图片站 -* 待续 +* GoogleImage.Filesite.io 5. 视频站 * 待续 diff --git a/www/css/googleimage.css b/www/css/googleimage.css index 4881c32..ec3f680 100644 --- a/www/css/googleimage.css +++ b/www/css/googleimage.css @@ -24,6 +24,8 @@ a{color: #aaadb2;text-decoration: none} .img-item{display: inline-block;margin-left: 10px;margin-right: 10px;margin-bottom: 20px;cursor: pointer;} .img-item img{height: 180px;object-fit: cover;} .img-item strong{display: block;color: #bdc1c6;font-family: Roboto,Arial,sans-serif;font-size: 12px;letter-spacing: .2px;line-height: 20px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;} +.catedesc{padding: 0 10px} +.cateinfo{margin-bottom: 1em;padding: 5px 10px 10px 10px} /* for mobile */ @media only screen and (max-width: 767px) {