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 .= "