1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 09:26:52 +08:00

使id特殊字符不会出bug,整理输出缩进对齐与代码风格(书目页面目录缩进对齐还没做)

This commit is contained in:
A.C.Sukazyo Eyre 2021-11-25 03:36:59 +08:00
parent b994cbc78b
commit a948c81c6b
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
14 changed files with 108 additions and 34 deletions

View File

@ -1,6 +1,6 @@
# URL Rewrite # URL Rewrite
RewriteEngine On RewriteEngine On
RewriteCond $0 !^index.php.* RewriteCond $0 !index.php.*
RewriteCond $0 !^debug.php.* RewriteCond $0 !debug.php.*
RewriteCond $0 !^assets.* RewriteCond $0 !assets.*
RewriteRule .* index.php?p=$0 [QSA] RewriteRule .* index.php?p=$0 [QSA]

View File

@ -2,6 +2,6 @@
const APP_NAME = "ph-Bookshelf"; const APP_NAME = "ph-Bookshelf";
const VERSION = "0.3.0.11"; const VERSION = "0.3.0.12";
const CHANNEL = "suk-ws"; const CHANNEL = "suk-ws";
const BRANCH = "master"; const BRANCH = "master";

View File

@ -24,9 +24,15 @@ try {
if (sizeof($uri) > 0 && $uri[0] != null) { if (sizeof($uri) > 0 && $uri[0] != null) {
// 非主页面,判定当前定义的 book // 非主页面,判定当前定义的 book
$tmp = SiteMeta::getBookshelf()->getBook($uri[0]); if ($uri[0] == "%root") {
if ($tmp == null) throw new RequestNotExistException("Book required \"$uri[0]\" not found!"); PageMeta::$book = SiteMeta::getBookshelf()->getRootBook();
PageMeta::$book = $tmp->getContentedNode(); } else {
$tmp = SiteMeta::getBookshelf()->getBook($uri[0]);
if ($tmp == null)
throw new RequestNotExistException("Book required \"$uri[0]\" not found!");
PageMeta::$book = $tmp->getContentedNode();
}
// 判定当前页面 // 判定当前页面
if (sizeof($uri) > 1 && $uri[1] != null) { if (sizeof($uri) > 1 && $uri[1] != null) {
$tmp = PageMeta::$book->getPage($uri[1]); $tmp = PageMeta::$book->getPage($uri[1]);

View File

@ -54,8 +54,20 @@ class Book {
return $this->parent; return $this->parent;
} }
public function getHtml (): string { public function getHtml (int $indent = 0): string {
return "<a id='book/$this->id' book-id='$this->id' class='no-style menu-item" . (PageMeta::$book->getId()==$this->id?" current":"") . "' href='/$this->id'" . ">$this->name</a>"; return sprintf(<<<EOF
%s<a id='book/%s' book-id='%s'
%s class='no-style menu-item%s'
%s href='%s'" . ">%s</a>
EOF,
str_repeat("\t", $indent), $this->id, $this->id,
str_repeat("\t", $indent), PageMeta::$book->getId()==$this->id ? " current" : "",
str_repeat("\t", $indent), PageMeta::$book->getId()==$this->id ? "javascript:void(0)" : $this->encodeUrl(), $this->name
);
}
public function encodeUrl (): string {
return "/" . urlencode($this->id);
} }
/** /**

View File

@ -73,13 +73,24 @@ class BookCollection {
return $this->parent; return $this->parent;
} }
public function getHtml (): string { public function getHtml (int $indent = 0): string {
$str = ""; $str = "";
if ($this->name != self::ROOT) $str .= "<div class='menu-item-parent" . ($this->getBook(PageMeta::$book->getId())==null?"":" active") . "'><a class='no-style menu-item'>$this->name</a><div class='children'>"; $isRoot = $this->name == self::ROOT;
if (!$isRoot) $str .= sprintf(<<<EOL
%s<div class='menu-item-parent%s'>
%s<a class='no-style menu-item'>%s</a>
%s<div class='children'>
EOL,
str_repeat("\t", $indent), $this->getBook(PageMeta::$book->getId())==null?"":" active",
str_repeat("\t", $indent), $this->name,
str_repeat("\t", $indent)
);
$str .= "\n";
foreach ($this->array as $node) { foreach ($this->array as $node) {
$str .= $node->getHtml(); $str .= $node->getHtml($isRoot ? $indent : $indent + 2);
$str .= "\n";
} }
if ($this->name != self::ROOT) $str .= "</div></div>"; if (!$isRoot) $str .= str_repeat("\t", $indent) . "</div></div>";
return $str; return $str;
} }

View File

@ -68,7 +68,14 @@ class Chapter {
public function getSummaryHtml (): string { public function getSummaryHtml (): string {
$str = ""; $str = "";
if ($this->parent != null) $str .= "<div class='menu-item-parent" . ($this->getPage(PageMeta::$page->getId())==null?"":" active") . "'><a class='no-style menu-item' href='javascript:'>$this->name</a><div class='children'>"; if ($this->parent != null) $str .= sprintf(<<<EOL
<div class='menu-item-parent%s'>
<a class='no-style menu-item' href='javascript:'>%s</a>
<div class='children'>
EOL,
$this->getPage(PageMeta::$page->getId())==null?"":" active",
$this->name
);
foreach ($this->childs as $node) { foreach ($this->childs as $node) {
$str .= $node->getSummaryHtml(); $str .= $node->getSummaryHtml();
} }

View File

@ -85,11 +85,27 @@ class Page {
// } // }
// $str .= "</li>"; // $str .= "</li>";
// return $str; // return $str;
return "<a id='page/$this->id' page-id='$this->id' class='no-style menu-item" . (PageMeta::$page->getId()==$this->id?" current":"") . "' href='/".PageMeta::$book->getId()."/$this->id'" . ">$this->name</a>"; return sprintf(<<<EOF
<a id='page/%s' page-id='%s'
class='no-style menu-item%s'
href='%s'>%s</a>
EOF,
$this->id, $this->id,
PageMeta::$page->getId()==$this->id ? " current" : "",
PageMeta::$page->getId()==$this->id ? "#" : $this->encodeUrl(),
$this->name
);
}
public function encodeUrl (): string {
return str_replace(
"%2F", "/",
sprintf("/%s/%s", urlencode(PageMeta::$book->getId()), urlencode($this->id))
);
} }
public function getMarkdownContent (): string { public function getMarkdownContent (): string {
return file_get_contents("./data/".PageMeta::$book->getId()."/".$this->id.".md"); return file_get_contents(sprintf("./data/%s/%s.md", PageMeta::$book->getId(), $this->id));
} }
} }

View File

@ -52,8 +52,12 @@ class Link {
return $this->parent; return $this->parent;
} }
public function getHtml (): string { public function getHtml (int $indent = 0): string {
return "<a class='no-style menu-item' href='$this->href' target='_blank'>$this->name</a>"; return sprintf(
"%s<a class='no-style menu-item' href='%s' target='_blank'>%s</a>",
str_repeat("\t", $indent),
$this->href, $this->name
);
} }
} }

View File

@ -72,13 +72,24 @@ class LinkCollection {
return $this->parent; return $this->parent;
} }
public function getHtml (): string { public function getHtml (int $indent = 0): string {
$str = ""; $str = "";
if ($this->name != self::ROOT) $str .= "<div class='menu-item-parent'><a class='no-style menu-item' href='javascript:'>$this->name</a><div class='children'>"; $isRoot = $this->name == self::ROOT;
if (!$isRoot) $str .= sprintf(<<<EOL
%s<div class='menu-item-parent'>
%s<a class='no-style menu-item' href='javascript:'>%s</a>
%s<div class='children'>
EOL,
str_repeat("\t", $indent),
str_repeat("\t", $indent), $this->name,
str_repeat("\t", $indent)
);
$str .= "\n";
foreach ($this->array as $node) { foreach ($this->array as $node) {
$str .= $node->getHtml(); $str .= $node->getHtml($isRoot ? $indent : $indent + 2);
$str .= "\n";
} }
if ($this->name != self::ROOT) $str .= "</div></div>"; if (!$isRoot) $str .= str_repeat("\t", $indent) . "</div></div>";
return $str; return $str;
} }

View File

@ -1,20 +1,20 @@
<?php require_once "./src/Data/SiteMeta.php" ?> <?php require_once "./src/Data/SiteMeta.php" ?>
<?php require_once "./src/Data/PageMeta.php" ?> <?php require_once "./src/Data/PageMeta.php" ?>
<!-- Assets(js) --> <!-- Assets(js) --><?php
<?php
foreach (SiteMeta::getJavascriptList() as $item) { foreach (SiteMeta::getJavascriptList() as $item) {
if ($item==null) continue; if ($item==null) continue;
echo "\n\t\t";
echo "<script src=\"$item\"></script>"; echo "<script src=\"$item\"></script>";
} }
echo "\n";
?> ?>
<script><?= SiteMeta::getCustomScriptContent("custom") ?></script> <script><?= SiteMeta::getCustomScriptContent("custom") ?></script>
<script> <script>
bookCurrentId = "<?= PageMeta::$book->getId() ?>"; bookCurrentId = "<?= PageMeta::$book->getId() ?>";
pageCurrentId = "<?= PageMeta::$page->getId() ?>"; pageCurrentId = "<?= PageMeta::$page->getId() ?>";
<?php if (!(PageMeta::getConfigurationLevelPage("customization.article.codeblock.highlightjs")=="false")) : ?> <?php if (!(PageMeta::getConfigurationLevelPage("customization.article.codeblock.highlightjs")=="false")) :
hljs.highlightAll(); ?>hljs.highlightAll();<?php endif; ?>
<?php endif; ?>
</script> </script>
</body> </body>

View File

@ -15,12 +15,13 @@
<link rel="shortcut icon" href="<?= SiteMeta::getGlobalIcon() ?>"> <link rel="shortcut icon" href="<?= SiteMeta::getGlobalIcon() ?>">
<title><?= PageMeta::getPageTitle() ?></title> <title><?= PageMeta::getPageTitle() ?></title>
<meta name="description" content="<?= PageMeta::getDescription() ?>"> <meta name="description" content="<?= PageMeta::getDescription() ?>">
<!-- Assets(css) --> <!-- Assets(css) --><?php
<?php
foreach (SiteMeta::getStylesheetsList() as $item) { foreach (SiteMeta::getStylesheetsList() as $item) {
if ($item==null) continue; if ($item==null) continue;
echo "\n\t\t";
echo "<link rel=\"stylesheet\" href=\"$item\">"; echo "<link rel=\"stylesheet\" href=\"$item\">";
} }
echo "\n";
?> ?>
<!-- Customs(css) --> <!-- Customs(css) -->
<style> <style>

View File

@ -3,6 +3,11 @@
<button id="sidebar-show"></button> <button id="sidebar-show"></button>
</div></div> </div></div>
<article id="article"> <article id="article">
<?php require "./template/raw-article.php" ?>
<?php require "./template/raw-article.php" ?>
</article> </article>
</main> </main>

View File

@ -7,14 +7,14 @@
<div id="menu-metas" class="menu"> <div id="menu-metas" class="menu">
<div class="menu-item-parent"> <div class="menu-item-parent">
<a class="no-style menu-item" href="javascript:">Links</a> <a class="no-style menu-item" href="javascript:">Links</a>
<div class="children"> <div class="children"><?=
<?= SiteMeta::getBookshelf()->getLinks()->getHtml() ?> SiteMeta::getBookshelf()->getLinks()->getHtml(7) ?>
</div> </div>
</div> </div>
<div class="menu-item-parent"> <div class="menu-item-parent">
<a class="no-style menu-item" href="javascript:">Books</a> <a class="no-style menu-item" href="javascript:">Books</a>
<div class="children"> <div class="children"><?=
<?= SiteMeta::getBookshelf()->getBooks()->getHtml() ?> SiteMeta::getBookshelf()->getBooks()->getHtml(7) ?>
</div> </div>
</div> </div>
</div> </div>

View File

@ -18,6 +18,7 @@ if (PageMeta::compatibilityOldTitlePolicy()) {
} else if ($pageMarkdownContent[$i] == '#' && $pageMarkdownContent[$i+1] != '#') { } else if ($pageMarkdownContent[$i] == '#' && $pageMarkdownContent[$i+1] != '#') {
break; break;
} }
echo "<!-- compatibility old-title policy triggered -->\n";
echo "<h1 id='phb-page-".PageMeta::$page->getId()."'>".PageMeta::$page->getName()."</h1>\n"; echo "<h1 id='phb-page-".PageMeta::$page->getId()."'>".PageMeta::$page->getName()."</h1>\n";
break; break;
} }