From 40f6ebcfdf8e413e7e368ea11bed6e1ea9479537 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Mon, 22 Nov 2021 22:53:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=97=A7=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=EF=BC=88=E5=8F=96=E6=B6=88=E4=B9=A6=E7=9B=AE=E5=BD=95=E5=86=85?= =?UTF-8?q?=E7=9A=84=20Segment=20=E6=94=AF=E6=8C=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 9 ++-- src/Data/SiteMeta.php | 1 + src/Element/Book.php | 3 +- src/Element/BookCollection.php | 5 +- src/Element/BookContent/BookContented.php | 2 +- src/Element/BookContent/Chapter.php | 4 +- src/Element/BookContent/Page.php | 56 +++++++++-------------- src/Element/BookContent/Segment.php | 56 ----------------------- src/Element/Bookshelf.php | 10 ---- src/Element/Link.php | 2 +- src/Element/LinkCollection.php | 4 +- template/main.php | 8 ++++ template/nav.php | 40 ++++++++++++++++ template/raw-article.php | 12 +++++ template/raw-book-contents.php | 5 ++ 15 files changed, 102 insertions(+), 115 deletions(-) delete mode 100644 src/Element/BookContent/Segment.php create mode 100644 template/main.php create mode 100644 template/nav.php create mode 100644 template/raw-article.php create mode 100644 template/raw-book-contents.php diff --git a/index.php b/index.php index 6b62c15..2db5b29 100644 --- a/index.php +++ b/index.php @@ -3,15 +3,10 @@ require_once "./src/Data/SiteMeta.php"; require_once "./src/Data/PageMeta.php"; -require_once "./src/Utils/ParsedownExtend.php"; require_once "./src/Utils/PageParse.php"; require_once "./src/Utils/RequestNotExistException.php"; -require_once "./constant.php"; -$parser = new ParsedownExtend(); -$parser->setMarkupEscaped(false); -$parser->setSafeMode(false); try { @@ -60,7 +55,9 @@ try { require "./template/header.php"; - require "./template/demo.html"; + require "./template/nav.php"; + + require "./template/main.php"; require "./template/footer.php"; diff --git a/src/Data/SiteMeta.php b/src/Data/SiteMeta.php index 7698bd9..0b567d7 100644 --- a/src/Data/SiteMeta.php +++ b/src/Data/SiteMeta.php @@ -55,6 +55,7 @@ class SiteMeta { } public static function getCustomScriptContent (string $id): string { + if (!file_exists("./data/$id.js")) return ""; return file_get_contents("./data/$id.js"); } diff --git a/src/Element/Book.php b/src/Element/Book.php index 65c5f25..d6e1d29 100644 --- a/src/Element/Book.php +++ b/src/Element/Book.php @@ -1,5 +1,6 @@ id' book-id='$this->id' class='link link-book" . (PageMeta::$book->getId()==$this->id?" active":"") . "'>getId()==$this->id?"":" href='/$this->id'") . ">$this->name"; + return "$this->name"; } /** diff --git a/src/Element/BookCollection.php b/src/Element/BookCollection.php index da071dd..50ab88a 100644 --- a/src/Element/BookCollection.php +++ b/src/Element/BookCollection.php @@ -1,5 +1,6 @@ name != self::ROOT) $str .= "
  • $this->name
  • "; + if ($this->name != self::ROOT) $str .= ""; return $str; } diff --git a/src/Element/BookContent/BookContented.php b/src/Element/BookContent/BookContented.php index 187cf45..6a3383b 100644 --- a/src/Element/BookContent/BookContented.php +++ b/src/Element/BookContent/BookContented.php @@ -64,7 +64,7 @@ class BookContented { } public function getSummaryHtml (): string { - return "
    " . $this->childs->getSummaryHtml() . "
    "; + return $this->childs->getSummaryHtml(); } public function getPage (string $id): ?Page { diff --git a/src/Element/BookContent/Chapter.php b/src/Element/BookContent/Chapter.php index b8abd8e..0210313 100644 --- a/src/Element/BookContent/Chapter.php +++ b/src/Element/BookContent/Chapter.php @@ -66,11 +66,11 @@ class Chapter { public function getSummaryHtml (): string { $str = ""; - if ($this->parent != null) $str .= "
  • $this->name
  • "; + if ($this->parent != null) $str .= ""; return $str; } diff --git a/src/Element/BookContent/Page.php b/src/Element/BookContent/Page.php index 9e6f8dc..9c79f9a 100644 --- a/src/Element/BookContent/Page.php +++ b/src/Element/BookContent/Page.php @@ -1,22 +1,19 @@ id = $id; $this->name = $name; $this->parent = $parent; - $this->segues = $childs; } /** @@ -40,9 +37,6 @@ class Page { throw new Exception("Book xml data missing attributes"); for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) { switch ($child->nodeName) { - case "Segment": - array_push($node->segues, Segment::parse($child, $node)); - break; case "#text": break; default: @@ -60,37 +54,31 @@ class Page { return $this->name; } - /** - * @return Segment[] - */ - public function getSegments (): array { - return $this->segues; - } - public function getParent (): Chapter { return $this->parent; } public function getSummaryHtml (): string { - $str = - ""; - return $str; +// $str = +// ""; +// return $str; + return "$this->name"; } public function getMarkdownContent (): string { diff --git a/src/Element/BookContent/Segment.php b/src/Element/BookContent/Segment.php deleted file mode 100644 index d8e40dd..0000000 --- a/src/Element/BookContent/Segment.php +++ /dev/null @@ -1,56 +0,0 @@ -id = $id; - $this->name = $name; - $this->parent = $parent; - } - - /** - * @param DOMNode $xmlData - * @param Page $parent - * @return Segment - * @throws Exception - */ - public static function parse (DOMNode $xmlData, Page $parent): Segment { - if ($xmlData->hasAttributes()) { - $attrName = $xmlData->attributes->getNamedItem("name"); - $attrId = $xmlData->attributes->getNamedItem("id"); - if ($attrName == null) - if ($attrId == null) throw new Exception("Segment xml data missing attribute \"name\""); - else throw new Exception("Segment xml data with id \"$attrId->nodeValue\" missing attribute \"name\""); - else $name = $attrName->nodeValue; - if ($attrId == null) throw new Exception("Segment xml data named \"$name\" missing attribute \"id\""); - else $id = $attrId->nodeValue; - } else - throw new Exception("Segment xml data missing attributes"); - if ($xmlData->hasChildNodes()) - throw new Exception("Segment xml named \"$name\" have some children which are not supported"); - return new Segment($id, $name, $parent); - } - - public function getId (): string { - return $this->id; - } - - public function getName (): string { - return $this->name; - } - - public function getParent (): Page { - return $this->parent; - } - - public function getSummaryHtml (): string { - return "
  • $this->name
  • "; - } - -} diff --git a/src/Element/Bookshelf.php b/src/Element/Bookshelf.php index 03a7f4c..cf78aa0 100644 --- a/src/Element/Bookshelf.php +++ b/src/Element/Bookshelf.php @@ -70,16 +70,6 @@ class Bookshelf { return $this->rootBook; } - public function getHtml (): string { - $str = $this->links->getHtml(); - $str .= "
  • "; - $str .= $this->books->getHtml(); - $str .= "
  • "; - $str .= PageMeta::$book->getSummaryHtml(); - $str .= ""; - return $str; - } - public function getBook (string $id): ?Book { return $this->books->getBook($id); } diff --git a/src/Element/Link.php b/src/Element/Link.php index 7323456..e40c02e 100644 --- a/src/Element/Link.php +++ b/src/Element/Link.php @@ -53,7 +53,7 @@ class Link { } public function getHtml (): string { - return ""; + return "$this->name"; } } diff --git a/src/Element/LinkCollection.php b/src/Element/LinkCollection.php index 66ae1b8..08ff67c 100644 --- a/src/Element/LinkCollection.php +++ b/src/Element/LinkCollection.php @@ -72,11 +72,11 @@ class LinkCollection { public function getHtml (): string { $str = ""; - if ($this->name != self::ROOT) $str .= ""; + if ($this->name != self::ROOT) $str .= ""; return $str; } diff --git a/template/main.php b/template/main.php new file mode 100644 index 0000000..087be11 --- /dev/null +++ b/template/main.php @@ -0,0 +1,8 @@ +
    +
    + +
    +
    + +
    +
    diff --git a/template/nav.php b/template/nav.php new file mode 100644 index 0000000..61485ab --- /dev/null +++ b/template/nav.php @@ -0,0 +1,40 @@ + + + diff --git a/template/raw-article.php b/template/raw-article.php new file mode 100644 index 0000000..4a0e86e --- /dev/null +++ b/template/raw-article.php @@ -0,0 +1,12 @@ +setMarkupEscaped(false); +$parser->setSafeMode(false); + +echo "

    ".PageMeta::$page->getName()."

    \n"; +echo $parser->text(PageMeta::$page->getMarkdownContent()); diff --git a/template/raw-book-contents.php b/template/raw-book-contents.php new file mode 100644 index 0000000..817b043 --- /dev/null +++ b/template/raw-book-contents.php @@ -0,0 +1,5 @@ +getSummaryHtml();