Browse Source

add description and cate readme support

master
filesite 3 years ago
parent
commit
abcbf71ea3
  1. 16
      lib/DirScanner.php
  2. 2
      test/DirScannerTest.php
  3. 18
      themes/googleimage/controller/ListController.php
  4. 19
      themes/googleimage/controller/SiteController.php
  5. 16
      themes/googleimage/views/site/index.php
  6. 2
      www/content/README.md
  7. 2
      www/css/googleimage.css

16
lib/DirScanner.php

@ -679,11 +679,11 @@ Class DirScanner { @@ -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 { @@ -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;

2
test/DirScannerTest.php

@ -82,7 +82,7 @@ echo "\n"; @@ -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'];

18
themes/googleimage/controller/ListController.php

@ -19,27 +19,37 @@ Class ListController extends Controller { @@ -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);
}

19
themes/googleimage/controller/SiteController.php

@ -19,24 +19,35 @@ Class SiteController extends Controller { @@ -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);
}

16
themes/googleimage/views/site/index.php

@ -45,6 +45,20 @@ eof; @@ -45,6 +45,20 @@ eof;
$imgExts = ['jpg', 'jpeg', 'png', 'gif'];
$category = $viewData['scanResults'][$selectedId];
//当前目录的描述介绍
if (!empty($category['description'])) {
echo <<<eof
<p class="catedesc">{$category['description']}</p>
eof;
}
//当前目录的readme详细介绍
if (!empty($viewData['htmlCateReadme'])) {
echo <<<eof
<div class="cateinfo markdown-body">{$viewData['htmlCateReadme']}</div>
eof;
}
if (!empty($category['directories'])) { //两级目录支持
foreach($category['directories'] as $dir) {
echo <<<eof
@ -100,7 +114,7 @@ eof; @@ -100,7 +114,7 @@ eof;
</div>
<div class="hr"></div>
<div class="modal-body markdown-body">
<?php echo $viewData['html']; ?>
<?php echo $viewData['htmlReadme']; ?>
</div>
</div>
</div>

2
www/content/README.md

@ -45,7 +45,7 @@ filesite使用非常简单,一旦部署好之后,以后只需将本地最新 @@ -45,7 +45,7 @@ filesite使用非常简单,一旦部署好之后,以后只需将本地最新
* 待续
4. 图片站
* 待续
* <a href="https://googleimage.filesite.io" target="_blank">GoogleImage.Filesite.io</a>
5. 视频站
* 待续

2
www/css/googleimage.css

@ -24,6 +24,8 @@ a{color: #aaadb2;text-decoration: none} @@ -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) {

Loading…
Cancel
Save