From a948c81c6bd1f2a941c155ed78c872cbe1c1af37 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Thu, 25 Nov 2021 03:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BFid=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E5=87=BAbug=EF=BC=8C=E6=95=B4=E7=90=86?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=BC=A9=E8=BF=9B=E5=AF=B9=E9=BD=90=E4=B8=8E?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=EF=BC=88=E4=B9=A6=E7=9B=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9B=AE=E5=BD=95=E7=BC=A9=E8=BF=9B=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=E8=BF=98=E6=B2=A1=E5=81=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .htaccess | 6 +++--- constant.php | 2 +- index.php | 12 +++++++++--- src/Element/Book.php | 16 ++++++++++++++-- src/Element/BookCollection.php | 19 +++++++++++++++---- src/Element/BookContent/Chapter.php | 9 ++++++++- src/Element/BookContent/Page.php | 20 ++++++++++++++++++-- src/Element/Link.php | 8 ++++++-- src/Element/LinkCollection.php | 19 +++++++++++++++---- template/footer.php | 10 +++++----- template/header.php | 5 +++-- template/main.php | 7 ++++++- template/nav.php | 8 ++++---- template/raw-article.php | 1 + 14 files changed, 108 insertions(+), 34 deletions(-) diff --git a/.htaccess b/.htaccess index 068e7a2..a349997 100644 --- a/.htaccess +++ b/.htaccess @@ -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] diff --git a/constant.php b/constant.php index 76df633..6bc618e 100644 --- a/constant.php +++ b/constant.php @@ -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"; diff --git a/index.php b/index.php index 2db5b29..eeee0a2 100644 --- a/index.php +++ b/index.php @@ -24,9 +24,15 @@ try { if (sizeof($uri) > 0 && $uri[0] != null) { // 非主页面,判定当前定义的 book - $tmp = SiteMeta::getBookshelf()->getBook($uri[0]); - if ($tmp == null) throw new RequestNotExistException("Book required \"$uri[0]\" not found!"); - PageMeta::$book = $tmp->getContentedNode(); + 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!"); + PageMeta::$book = $tmp->getContentedNode(); + } + // 判定当前页面 if (sizeof($uri) > 1 && $uri[1] != null) { $tmp = PageMeta::$book->getPage($uri[1]); diff --git a/src/Element/Book.php b/src/Element/Book.php index d6e1d29..da50a7a 100644 --- a/src/Element/Book.php +++ b/src/Element/Book.php @@ -54,8 +54,20 @@ class Book { return $this->parent; } - public function getHtml (): string { - return "$this->name"; + public function getHtml (int $indent = 0): string { + return sprintf(<<%s + 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); } /** diff --git a/src/Element/BookCollection.php b/src/Element/BookCollection.php index 74b03f9..788082e 100644 --- a/src/Element/BookCollection.php +++ b/src/Element/BookCollection.php @@ -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 .= ""; return $str; } diff --git a/src/Element/BookContent/Chapter.php b/src/Element/BookContent/Chapter.php index 8029230..43036b7 100644 --- a/src/Element/BookContent/Chapter.php +++ b/src/Element/BookContent/Chapter.php @@ -68,7 +68,14 @@ class Chapter { public function getSummaryHtml (): string { $str = ""; - if ($this->parent != null) $str .= "