1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 01:16:53 +08:00

连接旧后端(取消书目录内的 Segment 支持)

This commit is contained in:
A.C.Sukazyo Eyre 2021-11-22 22:53:02 +08:00
parent 669c3034a3
commit 40f6ebcfdf
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
15 changed files with 102 additions and 115 deletions

View File

@ -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";

View File

@ -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");
}

View File

@ -1,5 +1,6 @@
<?php
require_once "./src/Data/PageMeta.php";
require_once "./src/Element/BookCollection.php";
require_once "./src/Element/BookContent/BookContented.php";
@ -54,7 +55,7 @@ class Book {
}
public function getHtml (): string {
return "<li id='book/$this->id' book-id='$this->id' class='link link-book" . (PageMeta::$book->getId()==$this->id?" active":"") . "'><a class='link' " . (PageMeta::$book->getId()==$this->id?"":" href='/$this->id'") . ">$this->name</a></li>";
return "<a id='book/$this->id' book-id='$this->id' class='no-style menu-item" . (PageMeta::$book->getId()==$this->id?" current":"") . "' href='/$this->id'" . ">$this->name</a>";
}
/**

View File

@ -1,5 +1,6 @@
<?php
require_once "./src/Data/PageMeta.php";
require_once "./src/Element/Book.php";
class BookCollection {
@ -72,11 +73,11 @@ class BookCollection {
public function getHtml (): string {
$str = "";
if ($this->name != self::ROOT) $str .= "<li class='book-collection fold" . ($this->getBook(PageMeta::$book->getId())==null?"":" on") . "'><a class='book-collection'>$this->name<i class='exc-trigger fa'></i></a><ul class='book-collection summary'>";
if ($this->name != self::ROOT) $str .= "<div class='menu-item-parent" . ($this->getBook(PageMeta::$book->getId())==null?"":" active") . "'><a class='no-style menu-item'>$this->name</a><div class='children'>";
foreach ($this->array as $node) {
$str .= $node->getHtml();
}
if ($this->name != self::ROOT) $str .= "</ul></li>";
if ($this->name != self::ROOT) $str .= "</div></div>";
return $str;
}

View File

@ -64,7 +64,7 @@ class BookContented {
}
public function getSummaryHtml (): string {
return "<div id='in-book-nav-container'>" . $this->childs->getSummaryHtml() . "</div>";
return $this->childs->getSummaryHtml();
}
public function getPage (string $id): ?Page {

View File

@ -66,11 +66,11 @@ class Chapter {
public function getSummaryHtml (): string {
$str = "";
if ($this->parent != null) $str .= "<li class='chapter fold" . ($this->getPage(PageMeta::$page->getId())==null?"":" on") . "'><a class='page-chapter'>$this->name<i class='exc-trigger fa'></i></a><ul class='page-chapter summary'>";
if ($this->parent != null) $str .= "<div class='menu-item-parent" . ($this->getPage(PageMeta::$page->getId())==null?"":" active") . "'><a class='no-style menu-item' href='javascript:'>$this->name</a><div class='children'>";
foreach ($this->childs as $node) {
$str .= $node->getSummaryHtml();
}
if ($this->parent != null) $str .= "</ul></li>";
if ($this->parent != null) $str .= "</div></div>";
return $str;
}

View File

@ -1,22 +1,19 @@
<?php
require_once "./src/Data/PageMeta.php";
require_once "./src/Element/BookContent/Chapter.php";
require_once "./src/Element/BookContent/Segment.php";
class Page {
private string $id;
private string $name;
/** @var Segment[] */
private array $segues;
private Chapter $parent;
public function __construct (string $id, string $name, Chapter $parent, array $childs = array()) {
public function __construct (string $id, string $name, Chapter $parent) {
$this->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 =
"<li id='page/$this->id' page-id='$this->id' class='page-contented chapter link-page " .
(PageMeta::$page->getId()==$this->id?" active":"") .
"'><a class='page-contented' " .
(
PageMeta::$page->getId()==$this->id ?
"" :
"href='/".PageMeta::$book->getId()."/".$this->id."' "
) .
">$this->name</a>";
if (sizeof($this->segues) > 0) {
$str .= "<ul class='page-contented summary'>";
foreach ($this->segues as $node) {
$str .= $node->getSummaryHtml();
}
$str .= "</ul>";
}
$str .= "</li>";
return $str;
// $str =
// "<li id='page/$this->id' page-id='$this->id' class='page-contented chapter link-page " .
// (PageMeta::$page->getId()==$this->id?" active":"") .
// "'><a class='page-contented' " .
// (
// PageMeta::$page->getId()==$this->id ?
// "" :
// "href='/".PageMeta::$book->getId()."/".$this->id."' "
// ) .
// ">$this->name</a>";
// if (sizeof($this->segues) > 0) {
// $str .= "<ul class='page-contented summary'>";
// foreach ($this->segues as $node) {
// $str .= $node->getSummaryHtml();
// }
// $str .= "</ul>";
// }
// $str .= "</li>";
// return $str;
return "<a id='page/$this->id' page-id='$this->id' class='no-style menu-item" . (PageMeta::$page->getId()==$this->id?" current":"") . "' href='/".PageMeta::$book->getId()."/$this->id'" . ">$this->name</a>";
}
public function getMarkdownContent (): string {

View File

@ -1,56 +0,0 @@
<?php
require_once "./src/Element/BookContent/Page.php";
class Segment {
private string $id;
private string $name;
private Page $parent;
public function __construct (string $id, string $name, Page $parent) {
$this->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 "<li class='page-segment chapter'><a href='" . (PageMeta::$page->getId()==$this->parent->getId()?"":"/".PageMeta::$book->getId()."/".$this->parent->getId()."") . "#$this->id'>$this->name</a></li>";
}
}

View File

@ -70,16 +70,6 @@ class Bookshelf {
return $this->rootBook;
}
public function getHtml (): string {
$str = $this->links->getHtml();
$str .= "<li class='divider block-start'></li><div class='summary-container" . (PageMeta::$isMainPage?" on":"") . "'>";
$str .= $this->books->getHtml();
$str .= "</div><li class='divider block-end'></li>";
$str .= PageMeta::$book->getSummaryHtml();
$str .= "";
return $str;
}
public function getBook (string $id): ?Book {
return $this->books->getBook($id);
}

View File

@ -53,7 +53,7 @@ class Link {
}
public function getHtml (): string {
return "<li class='link'><a class='link' href='$this->href' target='_blank'>$this->name</a></li>";
return "<a class='no-style menu-item' href='$this->href' target='_blank'>$this->name</a>";
}
}

View File

@ -72,11 +72,11 @@ class LinkCollection {
public function getHtml (): string {
$str = "";
if ($this->name != self::ROOT) $str .= "<li class='link-collection fold'><a class='link-collection chapter'>$this->name<i class='exc-trigger fa'></i></a><ul class='link-collection articles'>";
if ($this->name != self::ROOT) $str .= "<div class='menu-item-parent'><a class='no-style menu-item' href='javascript:'>$this->name</a><div class='children'>";
foreach ($this->array as $node) {
$str .= $node->getHtml();
}
if ($this->name != self::ROOT) $str .= "</ul></li>";
if ($this->name != self::ROOT) $str .= "</div></div>";
return $str;
}

8
template/main.php Normal file
View File

@ -0,0 +1,8 @@
<main id="main">
<div id="page-tools">
<button id="sidebar-show"></button>
</div>
<article id="article">
<?php require "./template/raw-article.php" ?>
</article>
</main>

40
template/nav.php Normal file
View File

@ -0,0 +1,40 @@
<?php require_once "./src/Data/SiteMeta.php" ?>
<?php require_once "./src/Data/PageMeta.php" ?>
<div id="nav-container" class="prevent-animation"><nav id="sidebar">
<noscript id="noscript-warn">For now, javascript must be enabled to view this site!!</noscript>
<address id="site-title"><?= SiteMeta::getBookshelf()->getSiteName() ?></address>
<div id="menu-container" class="menu-container sidebar-card">
<div id="menu-metas" class="menu">
<div class="menu-item-parent">
<a class="no-style menu-item" href="javascript:">Links</a>
<div class="children">
<?= SiteMeta::getBookshelf()->getLinks()->getHtml() ?>
</div>
</div>
<div class="menu-item-parent">
<a class="no-style menu-item" href="javascript:">Books</a>
<div class="children">
<?= SiteMeta::getBookshelf()->getBooks()->getHtml() ?>
</div>
</div>
</div>
<div id="menu-pages" class="menu">
<?= PageMeta::$book->getSummaryHtml() ?>
</div>
<div id="menu-about" class="menu">
<!-- <a class="no-style menu-item" href="https://sukazyo.cc" target="_blank">-->
<!-- <span>hosted by Sukazyo Workshop</span><br>-->
<!-- <small>&nbsp;| @author A.C.Sukazyo Eyre</small><br>-->
<!-- <small>&nbsp;<object><a class="no-style" href="https://laple.me/">| @author Lapis Apple</a></object></small><br>-->
<!-- <small>&nbsp;| @author github contributors&~&</small><br>-->
<!-- <small>&nbsp;| CC BY-NC-SA</small><br>-->
<!-- <small>&nbsp;| CC statement just for testing</small>-->
<!-- </a>-->
<a class="no-style menu-item" href="https://github.com/suk-ws/ph-Bookshelf" target="_blank">
<span>published with ph-Bookshelf</span><br>
<small><?=SiteMeta::getProgramVersion()?></small><br>
<small>with BreadCardUI</small>
</a>
</div>
</div>
</nav></div>

12
template/raw-article.php Normal file
View File

@ -0,0 +1,12 @@
<?php
require_once "./src/Utils/ParsedownExtend.php";
require_once "./src/Data/PageMeta.php";
$parser = new ParsedownExtend();
$parser->setMarkupEscaped(false);
$parser->setSafeMode(false);
echo "<h1 id='phb-page-".PageMeta::$page->getId()."'>".PageMeta::$page->getName()."</h1>\n";
echo $parser->text(PageMeta::$page->getMarkdownContent());

View File

@ -0,0 +1,5 @@
<?php
require_once "./src/Data/PageMeta.php";
PageMeta::$page->getSummaryHtml();