diff --git a/assets/gitbook-fix.js b/assets/gitbook-fix.js index d8f1f11..b64674b 100644 --- a/assets/gitbook-fix.js +++ b/assets/gitbook-fix.js @@ -1,6 +1,6 @@ const WITH_SUMMARY_CLASS = "with-summary" -var bookRoot; +let bookRoot; function summaryOnOrOff () { diff --git a/index.php b/index.php index 475b64b..46771b5 100644 --- a/index.php +++ b/index.php @@ -6,9 +6,32 @@ require_once "./src/Data/PageMeta.php"; try { SiteMeta::load(); - PageMeta::$book = SiteMeta::getBookshelf()->getRootBook(); - PageMeta::$page = PageMeta::$book->getChilds()->getChilds()[0]; - PageMeta::$isMainPage = true; + + // 格式化所给链接,并将链接转化为路径字符串数组 + $tmp = $_GET['p']; + if (strlen($tmp) > 0 && $tmp[strlen($tmp) - 1] === '/') + $tmp = substr($tmp, 0, -1); + $uri = explode("/", $tmp, 2); + + if (sizeof($uri) > 0 && $uri[0] != null) { + // 非主页面,判定当前定义的 book + $tmp = SiteMeta::getBookshelf()->getBook($uri[0]); + if ($tmp == null) throw new Exception("Book required \"$uri[0]\" not found!"); + PageMeta::$book = $tmp->getContentedNode(); + // 判定当前页面 + if (sizeof($uri) > 1 && $uri[1] != null) { + $tmp = PageMeta::$book->getPage($uri[1]); + if ($tmp == null) throw new Exception("Page required \"$uri[1]\" not found on book \"$uri[0]\"!"); + PageMeta::$page = $tmp; + } else { + PageMeta::$page = PageMeta::$book->getChilds()->getChilds()[0]; + } + } else { + // 主页面 + PageMeta::$book = SiteMeta::getBookshelf()->getRootBook(); + PageMeta::$page = PageMeta::$book->getChilds()->getChilds()[0]; + PageMeta::$isMainPage = true; + } require "./template/header.php"; @@ -21,22 +44,7 @@ try {
diff --git a/src/Data/PageMeta.php b/src/Data/PageMeta.php index 7df9bea..add6c7e 100644 --- a/src/Data/PageMeta.php +++ b/src/Data/PageMeta.php @@ -7,7 +7,7 @@ class PageMeta { public static BookContented $book; public static Page $page; - public static bool $isMainPage; + public static bool $isMainPage = false; public static function getPageTitle (): string { return self::$page->getName()." - ".self::$book->getName(); diff --git a/src/Element/Book.php b/src/Element/Book.php index f45687a..03e2f98 100644 --- a/src/Element/Book.php +++ b/src/Element/Book.php @@ -1,6 +1,7 @@ $this->name"; + return "
  • $this->name
  • "; + } + + /** + * @throws Exception + */ + public function getContentedNode (): BookContented { + return BookContented::parseString(file_get_contents("./data/$this->id/book.xml")); } } \ No newline at end of file diff --git a/src/Element/BookCollection.php b/src/Element/BookCollection.php index 23299ce..7c3a2be 100644 --- a/src/Element/BookCollection.php +++ b/src/Element/BookCollection.php @@ -72,7 +72,7 @@ class BookCollection { public function getHtml (): string { $str = ""; - if ($this->name != self::ROOT) $str .= "
  • $this->name