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();