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 <<