1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 01:16:53 +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
RewriteEngine On
RewriteCond $0 !^index.php.*
RewriteCond $0 !^debug.php.*
RewriteCond $0 !^assets.*
RewriteCond $0 !index.php.*
RewriteCond $0 !debug.php.*
RewriteCond $0 !assets.*
RewriteRule .* index.php?p=$0 [QSA]

View File

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

View File

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

View File

@ -54,8 +54,20 @@ class Book {
return $this->parent;
}
public function getHtml (): 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>";
public function getHtml (int $indent = 0): string {
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;
}
public function getHtml (): string {
public function getHtml (int $indent = 0): string {
$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) {
$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;
}

View File

@ -68,7 +68,14 @@ class Chapter {
public function getSummaryHtml (): string {
$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) {
$str .= $node->getSummaryHtml();
}

View File

@ -85,11 +85,27 @@ class Page {
// }
// $str .= "</li>";
// 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 {
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;
}
public function getHtml (): string {
return "<a class='no-style menu-item' href='$this->href' target='_blank'>$this->name</a>";
public function getHtml (int $indent = 0): string {
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;
}
public function getHtml (): string {
public function getHtml (int $indent = 0): string {
$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) {
$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;
}

View File

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

View File

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

View File

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

View File

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

View File

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