filesite
3 years ago
4 changed files with 71 additions and 14 deletions
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
<?php |
||||
/** |
||||
* View Controller |
||||
*/ |
||||
require_once __DIR__ . '/../../../lib/DirScanner.php'; |
||||
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); |
||||
} |
||||
|
||||
//获取数据 |
||||
$titles = []; |
||||
$content = ''; |
||||
$html = ''; |
||||
|
||||
$scanner = new DirScanner(); |
||||
$scanner->setWebRoot('/content/'); |
||||
$dirTree = $scanner->scan(__DIR__ . '/../../../www/content/', 4); |
||||
|
||||
$scanResults = $scanner->getScanResults(); |
||||
if (!empty($scanResults[$fileId])) { |
||||
$readmeFile = $scanResults[$fileId]; |
||||
$titles = $scanner->getMDTitles($readmeFile['id']); |
||||
$content = file_get_contents($readmeFile['realpath']); |
||||
|
||||
$Parsedown = new Parsedown(); |
||||
$html = $Parsedown->text($content); |
||||
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html); |
||||
}else { |
||||
throw new Exception("404 - 文件编号 {$fileId} 找不到", 404); |
||||
} |
||||
|
||||
$pageTitle = !empty($titles) ? $titles[0]['name'] : "404 - 文件找不到"; |
||||
$viewName = 'index'; |
||||
$params = compact('titles', 'content', 'html'); |
||||
return $this->render($viewName, $params, $pageTitle); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
<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']}> |
||||
eof; |
||||
} |
||||
} |
||||
?> |
||||
</div> |
||||
|
||||
<div class="content markdown-body"> |
||||
<?php echo $viewData['html']; ?> |
||||
</div> |
@ -1,15 +1,15 @@
@@ -1,15 +1,15 @@
|
||||
/* for theme manual */ |
||||
*,html,body{padding:0:;margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"} |
||||
.indexes{width:23%;position:fixed;padding-left:0.5em;padding-top:1em} |
||||
.indexes{width:23%;position:fixed;text-align:left;padding-left:0.5em;padding-top:1em} |
||||
.content{margin-left:23.8%;padding:0.5em} |
||||
.footer{margin:1em auto;text-align:center} |
||||
.indexes h1,.indexes h2,.indexes h3,.indexes h4,.indexes h5,.indexes h6{font-size:1.2em;font-weight:normal;margin-bottom:0.35em} |
||||
.indexes h1{display:none} |
||||
.indexes h2{margin-top:1em} |
||||
.indexes h2{margin-top:1em;} |
||||
.indexes h3{text-indent:1em} |
||||
.indexes a{background-color:transparent;color:#0969da;text-decoration: none} |
||||
@media (max-width: 640px) { |
||||
.indexes{position:static;width:auto} |
||||
.indexes h1{display:block;padding-bottom:0.3em;text-align:center;font-size:2em;border-bottom:1px solid hsla(210,18%,87%,1)} |
||||
.indexes{position:static;width:auto;padding-bottom:0.5em;margin-bottom:0.5em;border-bottom:1px solid hsla(210,18%,87%,1)} |
||||
.indexes h1{display:block;padding-left:0;padding-bottom:0.3em;text-align:center;font-size:2em;border-bottom:1px solid hsla(210,18%,87%,1)} |
||||
.content{margin-left:0;} |
||||
} |
Loading…
Reference in new issue