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 {
} }
//获取指定目录下名称为README.md的文件 //获取指定目录下名称为README.md的文件
public function getDefaultReadme($dirpath = '') { public function getDefaultReadme($dirid = '') {
$readme = null; $readme = null;
$md = null; $md = null;
if (empty($dirpath) && !empty($this->tree)) { if (empty($dirid) && !empty($this->tree)) {
foreach($this->tree as $id => $file) { foreach($this->tree as $id => $file) {
if (!empty($file['extension']) && $file['extension'] == 'md') { if (!empty($file['extension']) && $file['extension'] == 'md') {
$md = $file; $md = $file;
@ -694,19 +694,11 @@ Class DirScanner {
} }
} }
}else if (!empty($this->scanResults)) { }else if (!empty($this->scanResults)) {
$dir_realpath = realpath("{$this->rootDir}/{$dirpath}"); $directory = $this->scanResults[$dirid];
$directory = null;
foreach($this->scanResults as $id => $file) {
if (!empty($file['directory']) && $dir_realpath == $file['realpath']) {
$directory = $file;
break;
}
}
if (!empty($directory) && !empty($directory['files'])) { if (!empty($directory) && !empty($directory['files'])) {
foreach($directory['files'] as $id => $file) { foreach($directory['files'] as $id => $file) {
if (!empty($file['extension']) && $file['extension'] == 'md') { if (!empty($file['extension']) && $file['extension'] == 'md') {
$md = $file; if (empty($md)) {$md = $file;} //取第一个md文件
if (strtoupper($file['filename']) == 'README') { if (strtoupper($file['filename']) == 'README') {
$readme = $file; $readme = $file;
break; break;

2
test/DirScannerTest.php

@ -82,7 +82,7 @@ echo "\n";
exit; exit;
//$readmeFile = $scanner->getDefaultReadme('favs/'); //$readmeFile = $scanner->getDefaultReadme('目录id');
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
$readme_id = $readmeFile['id']; $readme_id = $readmeFile['id'];

18
themes/googleimage/controller/ListController.php

@ -19,27 +19,37 @@ Class ListController extends Controller {
$cateId = $this->get('id', $menus[0]['id']); $cateId = $this->get('id', $menus[0]['id']);
$titles = []; $titles = [];
$html = ''; $htmlReadme = '';
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
$content = file_get_contents($readmeFile['realpath']); $content = file_get_contents($readmeFile['realpath']);
$html = $Parsedown->text($content); $htmlReadme = $Parsedown->text($content);
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html); $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme);
} }
//获取目录面包屑 //获取目录面包屑
$subcate = $scanResults[$cateId]; $subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate); $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开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
if (!empty($subcate)) { if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}";
} }
$viewName = '//site/index'; //共享视图 $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); return $this->render($viewName, $params, $pageTitle);
} }

19
themes/googleimage/controller/SiteController.php

@ -19,24 +19,35 @@ Class SiteController extends Controller {
$cateId = $this->get('id', $menus[0]['id']); $cateId = $this->get('id', $menus[0]['id']);
$titles = []; $titles = [];
$html = ''; $htmlReadme = '';
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
$content = file_get_contents($readmeFile['realpath']); $content = file_get_contents($readmeFile['realpath']);
$html = $Parsedown->text($content); $htmlReadme = $Parsedown->text($content);
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html); $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme);
} }
$subcate = $scanResults[$cateId]; $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开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
if (!empty($subcate)) { if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}";
} }
$viewName = 'index'; $viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);
} }

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

@ -45,6 +45,20 @@ eof;
$imgExts = ['jpg', 'jpeg', 'png', 'gif']; $imgExts = ['jpg', 'jpeg', 'png', 'gif'];
$category = $viewData['scanResults'][$selectedId]; $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'])) { //两级目录支持 if (!empty($category['directories'])) { //两级目录支持
foreach($category['directories'] as $dir) { foreach($category['directories'] as $dir) {
echo <<<eof echo <<<eof
@ -100,7 +114,7 @@ eof;
</div> </div>
<div class="hr"></div> <div class="hr"></div>
<div class="modal-body markdown-body"> <div class="modal-body markdown-body">
<?php echo $viewData['html']; ?> <?php echo $viewData['htmlReadme']; ?>
</div> </div>
</div> </div>
</div> </div>

2
www/content/README.md

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

2
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{display: inline-block;margin-left: 10px;margin-right: 10px;margin-bottom: 20px;cursor: pointer;}
.img-item img{height: 180px;object-fit: cover;} .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;} .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 */ /* for mobile */
@media only screen and (max-width: 767px) { @media only screen and (max-width: 767px) {

Loading…
Cancel
Save