Browse Source

add author and publish, update time

master
filesite 4 weeks ago
parent
commit
7ca9a508e5
  1. 12
      themes/manual/controller/SiteController.php
  2. 11
      themes/manual/controller/ViewController.php
  3. 24
      themes/manual/views/site/index.php
  4. 26
      themes/manual/views/view/index.php
  5. 1
      www/content/README_author.txt
  6. 1
      www/css/manual.css

12
themes/manual/controller/SiteController.php

@ -12,12 +12,14 @@ Class SiteController extends Controller { @@ -12,12 +12,14 @@ Class SiteController extends Controller {
$titles = array();
$content = '';
$html = '';
$author = '';
$publishTime = $updateTime = 0;
$scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
$readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) {
$titles = $scanner->getMDTitles($readmeFile['id']);
$content = file_get_contents($readmeFile['realpath']);
@ -25,11 +27,17 @@ Class SiteController extends Controller { @@ -25,11 +27,17 @@ Class SiteController extends Controller {
$Parsedown = new Parsedown();
$html = $Parsedown->text($content);
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
$publishTime = min($readmeFile['fstat']['ctime'], $readmeFile['fstat']['atime']);
$updateTime = $readmeFile['fstat']['mtime'];
if (!empty($readmeFile['author'])) {
$author = $readmeFile['author'];
}
}
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
$viewName = 'index';
$params = compact('titles', 'content', 'html');
$params = compact('titles', 'content', 'html', 'author', 'publishTime', 'updateTime');
return $this->render($viewName, $params, $pageTitle);
}

11
themes/manual/controller/ViewController.php

@ -8,7 +8,6 @@ require_once __DIR__ . '/../../../plugins/Parsedown.php'; @@ -8,7 +8,6 @@ require_once __DIR__ . '/../../../plugins/Parsedown.php';
Class ViewController extends Controller {
public function actionIndex() {
$fileId = $this->get('id', '');
if (!empty($fileId)) {
$fileId = preg_replace('/\W/', '', $fileId);
@ -18,6 +17,8 @@ Class ViewController extends Controller { @@ -18,6 +17,8 @@ Class ViewController extends Controller {
$titles = array();
$content = '';
$html = '';
$author = '';
$publishTime = $updateTime = 0;
$scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']);
@ -32,13 +33,19 @@ Class ViewController extends Controller { @@ -32,13 +33,19 @@ Class ViewController extends Controller {
$Parsedown = new Parsedown();
$html = $Parsedown->text($content);
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
$publishTime = min($readmeFile['fstat']['ctime'], $readmeFile['fstat']['atime']);
$updateTime = $readmeFile['fstat']['mtime'];
if (!empty($readmeFile['author'])) {
$author = $readmeFile['author'];
}
}else {
throw new Exception("404 - 文件编号 {$fileId} 找不到", 404);
}
$pageTitle = !empty($titles) ? $titles[0]['name'] : "No title, 无标题";
$viewName = 'index';
$params = compact('titles', 'content', 'html');
$params = compact('titles', 'content', 'html', 'author', 'publishTime', 'updateTime');
return $this->render($viewName, $params, $pageTitle);
}

24
themes/manual/views/site/index.php

@ -1,16 +1,28 @@ @@ -1,16 +1,28 @@
<div class="indexes">
<?php
if (!empty($viewData['titles'])) {
foreach($viewData['titles'] as $title) {
$link = urlencode($title['name']);
echo <<<eof
<{$title['heading']}><a href="#{$link}">{$title['name']}</a></{$title['heading']}>
foreach($viewData['titles'] as $title) {
$link = urlencode($title['name']);
echo <<<eof
<{$title['heading']}><a href="#{$link}">{$title['name']}</a></{$title['heading']}>
eof;
}
}
}
?>
<div class="author">
<?php
if (!empty($viewData['author'])) {
echo <<<eof
作者:<small>{$viewData['author']}</small>
<br>
eof;
}
?>
发布:<small><?php echo date('Y-m-d H:i:s', $viewData['publishTime']); ?></small>
<br>修改:<small><?php echo date('Y-m-d H:i:s', $viewData['updateTime']); ?></small>
</div>
</div>
<div class="content markdown-body">
<?php echo $viewData['html']; ?>
<?php echo $viewData['html']; ?>
</div>

26
themes/manual/views/view/index.php

@ -1,17 +1,29 @@ @@ -1,17 +1,29 @@
<div class="indexes">
<p><a href="javascript:history.back(-1);">&lt;&lt;返回</a></p>
<p><a href="javascript:history.back(-1);">&lt;&lt;返回</a></p>
<?php
if (!empty($viewData['titles'])) {
foreach($viewData['titles'] as $title) {
$link = urlencode($title['name']);
echo <<<eof
<{$title['heading']}><a href="#{$link}">{$title['name']}</a></{$title['heading']}>
foreach($viewData['titles'] as $title) {
$link = urlencode($title['name']);
echo <<<eof
<{$title['heading']}><a href="#{$link}">{$title['name']}</a></{$title['heading']}>
eof;
}
}
}
?>
<div class="author">
<?php
if (!empty($viewData['author'])) {
echo <<<eof
作者:<small>{$viewData['author']}</small>
<br>
eof;
}
?>
发布:<small><?php echo date('Y-m-d H:i:s', $viewData['publishTime']); ?></small>
<br>修改:<small><?php echo date('Y-m-d H:i:s', $viewData['updateTime']); ?></small>
</div>
</div>
<div class="content markdown-body">
<?php echo $viewData['html']; ?>
<?php echo $viewData['html']; ?>
</div>

1
www/content/README_author.txt

@ -0,0 +1 @@ @@ -0,0 +1 @@
FileSite.io

1
www/css/manual.css

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
.indexes h5{font-size:0.9em}
.indexes h6{font-size:0.8em}
.indexes a{background-color:transparent;color:#0969da;text-decoration:none}
.author{margin-top:1em;padding:.5em;border:1px solid #EEE}
@media (max-width: 640px) {
.header{position: static}
.indexes{position:static;width:auto;padding-bottom:0.5em;margin-bottom:0.5em;margin-top: 0}

Loading…
Cancel
Save