mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2025-01-19 07:22:26 +08:00
后端大改 progress-1
This commit is contained in:
parent
2a72004b7b
commit
25a208b273
@ -51,12 +51,11 @@ function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
document.getElementById("sidebar-show").onclick = sidebarToggle;
|
||||
function sidebarToggle() {
|
||||
itemSidebar.parentElement.classList.toggle("show-sidebar");
|
||||
}
|
||||
if (window.innerWidth > 1000) { sidebarToggle(); }
|
||||
|
||||
document.getElementById("sidebar-show").onclick = sidebarToggle;
|
||||
EventUtil.bindEvent(itemSidebar, 'swipeleft', sidebarToggle)
|
||||
// EventUtil.bindEvent(document.body, 'swipeleft', function () { if (itemSidebar.parentElement.classList.contains("show-sidebar")) { sidebarToggle(); } });
|
||||
// EventUtil.bindEvent(document.body, 'swiperight', function () { if (!itemSidebar.parentElement.classList.contains("show-sidebar")) { sidebarToggle(); } });
|
@ -17,7 +17,7 @@
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"php": ">=8.2",
|
||||
"ext-xml": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-mbstring": "*",
|
||||
@ -25,6 +25,7 @@
|
||||
"league/commonmark": ">=2.3.8",
|
||||
"symfony/yaml": ">=4.0",
|
||||
"gregwar/rst": "^1.0",
|
||||
"xemlock/php-latex": "dev-master"
|
||||
"xemlock/php-latex": "dev-master",
|
||||
"ext-simplexml": "*"
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
const APP_NAME = "ph-Bookshelf";
|
||||
|
||||
const VERSION = "0.5.0-alpha1";
|
||||
const VERSION = "0.5.0-alpha2";
|
||||
const CHANNEL = "suk-ws";
|
||||
const BRANCH = "master";
|
||||
|
||||
const ON_DEVELOPMENT = true;
|
||||
|
16
index.php
16
index.php
@ -3,11 +3,18 @@
|
||||
require "./constant.php";
|
||||
require "./vendor/autoload.php";
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use SukWs\Bookshelf\Data\SiteConfig\RobotsPolicy;
|
||||
use SukWs\Bookshelf\Data\SiteMeta;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
use SukWs\Bookshelf\SiteConfig\RobotsPolicy;
|
||||
use SukWs\Bookshelf\SiteMeta;
|
||||
use SukWs\Bookshelf\Utils\PageParse;
|
||||
use SukWs\Bookshelf\Utils\RequestNotExistException;
|
||||
use SukWs\Bookshelf\Web\HtmlPage;
|
||||
|
||||
$page = new HtmlPage();
|
||||
|
||||
echo $page->build()->document->saveHTML();
|
||||
|
||||
exit();
|
||||
|
||||
try {
|
||||
|
||||
@ -107,3 +114,6 @@ try {
|
||||
echo "<h1>ERROR</h1><p>" . $e->getMessage() . "</p>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
67
src/Data/Bookshelf/NodeBookshelf.php
Normal file
67
src/Data/Bookshelf/NodeBookshelf.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\Bookshelf;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMNode;
|
||||
use Exception;
|
||||
use SukWs\Bookshelf\Utils\DOMXMLTools;
|
||||
use SukWs\Bookshelf\Web\WebWarn;
|
||||
|
||||
class NodeBookshelf {
|
||||
|
||||
public readonly ?string $_Attr_version;
|
||||
|
||||
public readonly string $_site_name;
|
||||
|
||||
public readonly array $_configurations;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(DOMElement $node_Bookshelf) {
|
||||
|
||||
/* "" version "" */
|
||||
$this->_Attr_version = $node_Bookshelf->attributes->getNamedItem("version")?->nodeValue;
|
||||
// configure version check
|
||||
if ($this->_Attr_version == null) WebWarn::output("bookshelf.xml:: file version is not declared.\n - the current ph-bookshelf uses version 2.0");
|
||||
else if ($this->_Attr_version != "2.0") throw new Exception("-0I{@EI[AID"); // todo throw exception
|
||||
|
||||
/* @var DOMNode $dom_child */
|
||||
$dom_child = $node_Bookshelf->firstChild;
|
||||
|
||||
/* == site_name == */
|
||||
if (!$dom_child->nodeName == "site_name") throw new Exception("O*R*OIArlAIWR"); // todo throw exception that site_name unavailable.
|
||||
$this->_site_name = $dom_child->nodeValue;
|
||||
$dom_child = $dom_child->nextSibling;
|
||||
|
||||
/* == configurations == */
|
||||
if ($dom_child->nodeName == "configurations") {
|
||||
$my_configurations = array();
|
||||
/* @var DOMElement $configNode */
|
||||
foreach ($dom_child->childNodes as $configNode) {
|
||||
if (DOMXMLTools::isEmpty($configNode)) continue;
|
||||
$my_configurations[$configNode->nodeName] = $configNode->nodeValue;
|
||||
}
|
||||
$this->_configurations = $my_configurations;
|
||||
$dom_child = $dom_child->nextSibling;
|
||||
}
|
||||
|
||||
// todo elements.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function __load_from_xml(string $xml_string): NodeBookshelf {
|
||||
$dom_tree = new DOMDocument();
|
||||
$dom_tree->loadXML($xml_string); // todo if load failed
|
||||
$dom = $dom_tree->firstChild;
|
||||
if ($dom instanceof DOMElement)
|
||||
return new nodeBookshelf($dom);
|
||||
throw new Exception("*@YUpoAWUIDP"); // todo if no root element
|
||||
}
|
||||
|
||||
}
|
6
src/Data/Configuration/ConfigurationManager.php
Normal file
6
src/Data/Configuration/ConfigurationManager.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\Configuration;
|
||||
|
||||
class ConfigurationManager {
|
||||
}
|
9
src/Data/Configuration/ConfigurationScope.php
Normal file
9
src/Data/Configuration/ConfigurationScope.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\Configuration;
|
||||
|
||||
enum ConfigurationScope {
|
||||
case Shelf;
|
||||
case Book;
|
||||
case Page;
|
||||
}
|
16
src/Data/Configuration/ConfigurationType.php
Normal file
16
src/Data/Configuration/ConfigurationType.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\Configuration;
|
||||
|
||||
readonly class ConfigurationType {
|
||||
|
||||
public string $id;
|
||||
|
||||
public ConfigurationScope $scope;
|
||||
|
||||
public function __construct (string $id, ConfigurationScope $scope) {
|
||||
$this->id = $id;
|
||||
$this->scope = $scope;
|
||||
}
|
||||
|
||||
}
|
23
src/Data/Configuration/ConfigurationTypesScopeShelf.php
Normal file
23
src/Data/Configuration/ConfigurationTypesScopeShelf.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\Configuration;
|
||||
|
||||
class ConfigurationTypesScopeShelf {
|
||||
|
||||
public static array $scope_shelf = array();
|
||||
public static array $scope_page = array();
|
||||
|
||||
}
|
||||
|
||||
ConfigurationTypesScopeShelf::$scope_shelf[] = new ConfigurationType("site.robots", ConfigurationScope::Shelf);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("old.title.gen", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("highlightjs", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("highlightjs.language", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("highlightjs.theme", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("codeblock.bg-color", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("codeblock.fg-color", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("codeblock.tab-size", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("regex.highlight", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("listing.marker.rainbow", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("title.permalink.flash", ConfigurationScope::Page);
|
||||
ConfigurationTypesScopeShelf::$scope_page[] = new ConfigurationType("web-title.rolling", ConfigurationScope::Page);
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace SukWs\Bookshelf\Element;
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use DOMNode;
|
||||
use SukWs\Bookshelf\Element\BookContent\BookContented;
|
||||
use Exception;
|
||||
use SukWs\Bookshelf\Element\BookContent\BookContented;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
|
||||
class Book {
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace SukWs\Bookshelf\Element;
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use DOMNode;
|
||||
use Exception;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
|
||||
class BookCollection {
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace SukWs\Bookshelf\Element\BookContent;
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use DOMNode;
|
||||
use Exception;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
|
||||
class Chapter {
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
namespace SukWs\Bookshelf\Element\BookContent;
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use DOMNode;
|
||||
use SukWs\Bookshelf\Element\Bookshelf;
|
||||
use Exception;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
|
||||
class Page {
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data;
|
||||
namespace SukWs\Bookshelf;
|
||||
|
||||
use SukWs\Bookshelf\Data\SiteConfig\ConfigName;
|
||||
use SukWs\Bookshelf\Element\BookContent\BookContented;
|
||||
use SukWs\Bookshelf\Element\BookContent\Page;
|
||||
use SukWs\Bookshelf\SiteConfig\ConfigName;
|
||||
|
||||
class PageMeta {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\SiteConfig;
|
||||
namespace SukWs\Bookshelf\SiteConfig;
|
||||
|
||||
class ConfigName {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data\SiteConfig;
|
||||
namespace SukWs\Bookshelf\SiteConfig;
|
||||
|
||||
enum RobotsPolicy {
|
||||
case allow;
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Data;
|
||||
namespace SukWs\Bookshelf;
|
||||
|
||||
use Exception;
|
||||
use SukWs\Bookshelf\Data\SiteConfig\ConfigName;
|
||||
use SukWs\Bookshelf\Data\SiteConfig\RobotsPolicy;
|
||||
use SukWs\Bookshelf\Element\Bookshelf;
|
||||
use SukWs\Bookshelf\SiteConfig\ConfigName;
|
||||
use SukWs\Bookshelf\SiteConfig\RobotsPolicy;
|
||||
|
||||
class SiteMeta {
|
||||
|
37
src/Utils/DOMHtml.php
Normal file
37
src/Utils/DOMHtml.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Utils;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMImplementation;
|
||||
|
||||
class DOMHtml {
|
||||
|
||||
public static function createHtmlDocument (): DOMDocument {
|
||||
$dom = new DOMImplementation();
|
||||
return $dom->createDocument(null, 'html', $dom->createDocumentType('html'));
|
||||
}
|
||||
|
||||
public static function createHeaderMeta (DOMDocument $root, array $metas): DOMElement {
|
||||
$element = $root->createElement("meta");
|
||||
foreach ($metas as $name => $value) {
|
||||
$element->setAttribute($name, $value);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
public static function createStylesheetRef (DOMDocument $root, string $href): DOMElement {
|
||||
$element = $root->createElement("link");
|
||||
$element->setAttribute("rel", "stylesheet");
|
||||
$element->setAttribute("href", $href);
|
||||
return $element;
|
||||
}
|
||||
|
||||
public static function createScriptRef (DOMDocument $root, string $href): DOMElement {
|
||||
$element = $root->createElement("script");
|
||||
$element->setAttribute("src", $href);
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
19
src/Utils/DOMXMLTools.php
Normal file
19
src/Utils/DOMXMLTools.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Utils;
|
||||
|
||||
use DOMElement;
|
||||
|
||||
class DOMXMLTools {
|
||||
|
||||
public static function isEmpty (DOMElement $element, bool $allow_empty_text = true, bool $allow_cdata = false): bool {
|
||||
if ($element->nodeName == "#comment")
|
||||
return true;
|
||||
if ($allow_empty_text && $element->nodeName == "#text" && empty(trim($element->nodeValue)))
|
||||
return true;
|
||||
if ($allow_cdata && $element->nodeName == "#cdata" && empty(trim($element->nodeValue)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
15
src/Utils/Resources.php
Normal file
15
src/Utils/Resources.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Utils;
|
||||
|
||||
use Nette\Utils\Random;
|
||||
|
||||
class Resources {
|
||||
|
||||
public static function webResPath(string $type, string $id, string $version = null): string {
|
||||
$version = ON_DEVELOPMENT ? null : $version;
|
||||
$version = $version == null ? Random::generate() : $version;
|
||||
return "/assets/web/$id.$type?v=" . $version;
|
||||
}
|
||||
|
||||
}
|
59
src/Web/Html/Body.php
Normal file
59
src/Web/Html/Body.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\Html;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Web\Html\Sidebar\Sidebar;
|
||||
use SukWs\Bookshelf\Web\HtmlPage;
|
||||
use SukWs\Bookshelf\Web\WebWarn;
|
||||
|
||||
class Body {
|
||||
|
||||
public HtmlPage $root;
|
||||
|
||||
public DOMElement $__self;
|
||||
|
||||
public Sidebar $_sidebar;
|
||||
|
||||
public function __construct (HtmlPage $root) {
|
||||
|
||||
$this->root = $root;
|
||||
$this->__self = $root->document->createElement("body");
|
||||
|
||||
$this->_sidebar = new Sidebar($this);
|
||||
|
||||
}
|
||||
|
||||
public function build (): DOMElement {
|
||||
|
||||
$this->__self->appendChild($this->_sidebar->build());
|
||||
|
||||
foreach ($this->root->res_manager->getJavascriptLazyloadsDOM($this->root->document) as $script)
|
||||
$this->__self->appendChild($script);
|
||||
|
||||
// output the warnings message at the end.
|
||||
$this->__self->appendChild(WebWarn::getWarningsAsJsLog()->build($this->root->document));
|
||||
|
||||
return $this->__self;
|
||||
|
||||
}
|
||||
|
||||
private static function getMain (DOMDocument $root): DOMElement {
|
||||
|
||||
/* @var */ $main = $root->createElement("main");
|
||||
$main->setAttribute("id", "main");
|
||||
|
||||
/* @var */ $main_heading = $main->appendChild($root->createElement("div"));
|
||||
$main_heading->setAttribute("id", "main-heading");
|
||||
|
||||
/* @var */ $page_tools = $main_heading->appendChild($root->createElement("div"));
|
||||
$page_tools->setAttribute("id", "page-tools");
|
||||
/* @var */ $tool_sidebar_show = $page_tools->appendChild($root->createElement("button", "☰"));
|
||||
$tool_sidebar_show->setAttribute("id", "sidebar-show");
|
||||
|
||||
return $main;
|
||||
|
||||
}
|
||||
|
||||
}
|
50
src/Web/Html/Head.php
Normal file
50
src/Web/Html/Head.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\Html;
|
||||
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Utils\DOMHtml;
|
||||
use SukWs\Bookshelf\Web\HtmlPage;
|
||||
|
||||
class Head {
|
||||
|
||||
public readonly HtmlPage $root;
|
||||
|
||||
public DOMElement $__self;
|
||||
|
||||
public readonly array $standard_headers;
|
||||
|
||||
public function __construct (HtmlPage $root) {
|
||||
|
||||
$this->root = $root;
|
||||
|
||||
$this->__self = $root->document->createElement("head");
|
||||
|
||||
$this->standard_headers = array(
|
||||
DOMHtml::createHeaderMeta($root->document, array("charset" => "UTF-8")),
|
||||
DOMHtml::createHeaderMeta($root->document, array("content" => "text/html; charset=UTF-8", "http-equiv" => "Content-Type")),
|
||||
DOMHtml::createHeaderMeta($root->document, array("name" => "HandheldFriendly", "content" => "true")),
|
||||
DOMHtml::createHeaderMeta($root->document, array("name" => "viewport", "content" => "width=device-width, initial-scale=1")),
|
||||
DOMHtml::createHeaderMeta($root->document, array("name" => "apple-mobile-web-app-capable", "content" => "yes")),
|
||||
DOMHtml::createHeaderMeta($root->document, array("name" => "apple-mobile-web-app-status-bar-style", "content" => "black")),
|
||||
DOMHtml::createHeaderMeta($root->document, array("name" => "generator", "content" => "ph-Bookshelf ".VERSION))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function build (): DOMElement {
|
||||
|
||||
foreach ($this->standard_headers as $meta)
|
||||
$this->__self->appendChild($meta);
|
||||
|
||||
// todo maybe css js manager?
|
||||
foreach ($this->root->res_manager->getStylesheetsDOM($this->root->document) as $style)
|
||||
$this->__self->appendChild($style);
|
||||
foreach ($this->root->res_manager->getJavascriptPreloadsDOM($this->root->document) as $script)
|
||||
$this->__self->appendChild($script);
|
||||
|
||||
return $this->__self;
|
||||
|
||||
}
|
||||
|
||||
}
|
70
src/Web/Html/Sidebar/Sidebar.php
Normal file
70
src/Web/Html/Sidebar/Sidebar.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\Html\Sidebar;
|
||||
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Web\Html\Body;
|
||||
use SukWs\Bookshelf\Web\HtmlPage;
|
||||
use SukWs\Bookshelf\Web\WebWarn;
|
||||
|
||||
class Sidebar {
|
||||
|
||||
public HtmlPage $root;
|
||||
|
||||
public Body $parent;
|
||||
|
||||
public DOMElement $_sidebar_container;
|
||||
public DOMElement $_sidebar;
|
||||
|
||||
public DOMElement $_sidebar_site_title_node;
|
||||
public ?string $_sidebar_site_title_value;
|
||||
|
||||
public bool $show_sidebar;
|
||||
|
||||
public function __construct (Body $parent) {
|
||||
|
||||
$this->parent = $parent;
|
||||
$this->root = $parent->root;
|
||||
|
||||
$this->_sidebar_container = $this->root->document->createElement('div');
|
||||
$this->_sidebar_container->setAttribute('id', 'nav-container');
|
||||
|
||||
$this->_sidebar = $this->root->document->createElement('nav');
|
||||
$this->_sidebar->setAttribute('id', 'sidebar');
|
||||
$this->show_sidebar = false;
|
||||
|
||||
$this->_sidebar_site_title_node = $this->root->document->createElement('a');
|
||||
$this->_sidebar_site_title_node->setAttribute('id','site-title');
|
||||
$this->_sidebar_site_title_node->setAttribute('class', 'no-style');
|
||||
$this->_sidebar_site_title_node->setAttribute('href', "/");
|
||||
$this->_sidebar_site_title_value = null;
|
||||
|
||||
}
|
||||
|
||||
public function toggleSidebarShow (?bool $show = null): void {
|
||||
if ($show === null) $show = !$this->show_sidebar;
|
||||
$this->show_sidebar = $show;
|
||||
}
|
||||
|
||||
public function setSiteTitle (string $title): void {
|
||||
$this->_sidebar_site_title_value = $title;
|
||||
}
|
||||
|
||||
public function build (): DOMElement {
|
||||
|
||||
if ($this->_sidebar_site_title_value == null) {
|
||||
$this->_sidebar_site_title_value = "...not set";
|
||||
WebWarn::output("[Web]<sidebar>: Site Title not set yet.");
|
||||
}
|
||||
$this->_sidebar_site_title_node->appendChild(
|
||||
$this->root->document->createTextNode($this->_sidebar_site_title_value));
|
||||
$this->_sidebar->appendChild($this->_sidebar_site_title_node);
|
||||
|
||||
$this->_sidebar_container->appendChild($this->_sidebar);
|
||||
if ($this->show_sidebar)
|
||||
$this->_sidebar_container->setAttribute('class', 'show-sidebar');
|
||||
return $this->_sidebar_container;
|
||||
|
||||
}
|
||||
|
||||
}
|
45
src/Web/HtmlPage.php
Normal file
45
src/Web/HtmlPage.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Utils\DOMHtml;
|
||||
use SukWs\Bookshelf\Web\Html\Body;
|
||||
use SukWs\Bookshelf\Web\Html\Head;
|
||||
|
||||
class HtmlPage {
|
||||
|
||||
public DOMDocument $document;
|
||||
|
||||
public WebResManager $res_manager;
|
||||
|
||||
public DOMElement $_html_html;
|
||||
|
||||
public Head $_html_head;
|
||||
public Body $_html_body;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
/* == var == */
|
||||
/* @var */ $document = DOMHtml::createHtmlDocument();
|
||||
$this->document = $document;
|
||||
/* @var */ $dom_html = $document->documentElement;
|
||||
$this->_html_html = $dom_html;
|
||||
|
||||
$this->res_manager = new WebResManager();
|
||||
|
||||
/* @var */ $html_head = new Head($this);
|
||||
$this->_html_head = $html_head;
|
||||
/* @var */ $html_body = new Body($this);
|
||||
$this->_html_body = $html_body;
|
||||
|
||||
}
|
||||
|
||||
public function build(): self {
|
||||
$this->_html_html->appendChild($this->_html_head->build());
|
||||
$this->_html_html->appendChild($this->_html_body->build());
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
73
src/Web/WebResManager.php
Normal file
73
src/Web/WebResManager.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Utils\Resources;
|
||||
use SukWs\Bookshelf\Web\WebResource\JavascriptRaw;
|
||||
use SukWs\Bookshelf\Web\WebResource\JavascriptRef;
|
||||
use SukWs\Bookshelf\Web\WebResource\StylesheetsRef;
|
||||
|
||||
class WebResManager {
|
||||
|
||||
public HtmlPage $root;
|
||||
|
||||
/* @var StylesheetsRef[] */ public array $stylesheets;
|
||||
/* @var JavascriptRef|JavascriptRaw[] */ public array $javascript_preload;
|
||||
/* @var JavascriptRef|JavascriptRaw[] */ public array $javascript_lazyload;
|
||||
|
||||
public function __construct() {
|
||||
$this->stylesheets = self::getBasicCssList();
|
||||
$this->javascript_preload = array();
|
||||
$this->javascript_lazyload = self::getBasicJsLazyloadList();
|
||||
}
|
||||
|
||||
/** @return DOMElement[] */
|
||||
public function getStylesheetsDOM (DOMDocument $root): array {
|
||||
$return = array();
|
||||
foreach ($this->stylesheets as $item) {
|
||||
$return[] = $item->build($root);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** @return DOMElement[] */
|
||||
public function getJavascriptPreloadsDOM (DOMDocument $root): array {
|
||||
$return = array();
|
||||
foreach ($this->javascript_preload as $item) {
|
||||
$return[] = $item->build($root);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** @return DOMElement[] */
|
||||
public function getJavascriptLazyloadsDOM (DOMDocument $root): array {
|
||||
$return = array();
|
||||
foreach ($this->javascript_lazyload as $item) {
|
||||
$return[] = $item->build($root);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** @return StylesheetsRef[] */
|
||||
public static function getBasicCssList (): array {
|
||||
return array(
|
||||
new StylesheetsRef(Resources::webResPath('css', "main", 1)),
|
||||
new StylesheetsRef(Resources::webResPath('css', "bread-card-markdown", 1)),
|
||||
new StylesheetsRef(Resources::webResPath('css', "bread-card-markdown-footnote", 1)),
|
||||
new StylesheetsRef(Resources::webResPath('css', "bread-card-markdown-task-list", 1)),
|
||||
new StylesheetsRef(Resources::webResPath('css', "bread-card-markdown-heading-permalink", 1)),
|
||||
new StylesheetsRef(Resources::webResPath('css', "bread-card-markdown-compat-highlight-js", 1)),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return JavascriptRef[] */
|
||||
public static function getBasicJsLazyloadList (): array {
|
||||
return array(
|
||||
new JavascriptRef(Resources::webResPath('js', "lib/utils-touchscreen-event", 1)),
|
||||
new JavascriptRef(Resources::webResPath('js', "main", 1)),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
12
src/Web/WebResource/IWebResource.php
Normal file
12
src/Web/WebResource/IWebResource.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\WebResource;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
|
||||
interface IWebResource {
|
||||
|
||||
public function build (DOMDocument $root): DOMElement;
|
||||
|
||||
}
|
23
src/Web/WebResource/JavascriptRaw.php
Normal file
23
src/Web/WebResource/JavascriptRaw.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\WebResource;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
|
||||
class JavascriptRaw implements IWebResource {
|
||||
|
||||
public string $javascript_raw_code;
|
||||
|
||||
public function __construct (string $code) {
|
||||
$this->javascript_raw_code = $code;
|
||||
}
|
||||
|
||||
public function build (DOMDocument $root): DOMElement {
|
||||
$dom = $root->createElement('script');
|
||||
$dom_value = $root->createTextNode($this->javascript_raw_code);
|
||||
$dom->appendChild($dom_value);
|
||||
return $dom;
|
||||
}
|
||||
|
||||
}
|
21
src/Web/WebResource/JavascriptRef.php
Normal file
21
src/Web/WebResource/JavascriptRef.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\WebResource;
|
||||
|
||||
use DOMElement;
|
||||
use DOMDocument;
|
||||
use SukWs\Bookshelf\Utils\DOMHtml;
|
||||
|
||||
class JavascriptRef implements IWebResource {
|
||||
|
||||
public string $uri;
|
||||
|
||||
public function __construct(string $uri) {
|
||||
$this->uri = $uri;
|
||||
}
|
||||
|
||||
public function build (DOMDocument $root): DOMElement {
|
||||
return DOMHtml::createScriptRef($root, $this->uri);
|
||||
}
|
||||
|
||||
}
|
21
src/Web/WebResource/StylesheetsRef.php
Normal file
21
src/Web/WebResource/StylesheetsRef.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\WebResource;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Utils\DOMHtml;
|
||||
|
||||
class StylesheetsRef implements IWebResource {
|
||||
|
||||
public string $uri;
|
||||
|
||||
public function __construct(string $uri) {
|
||||
$this->uri = $uri;
|
||||
}
|
||||
|
||||
public function build (DOMDocument $root): DOMElement {
|
||||
return DOMHtml::createStylesheetRef($root, $this->uri);
|
||||
}
|
||||
|
||||
}
|
33
src/Web/WebWarn.php
Normal file
33
src/Web/WebWarn.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web;
|
||||
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Web\WebResource\JavascriptRaw;
|
||||
|
||||
class WebWarn {
|
||||
|
||||
/** @var string[] $warnings */
|
||||
private static array $warnings = array();
|
||||
|
||||
public static function output(string $message): void {
|
||||
self::$warnings[] = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new "script" DOMElement that contains a list
|
||||
* of `console.log` js code to output the warning messages.
|
||||
*
|
||||
* @return JavascriptRaw a fully new "script" object.
|
||||
*/
|
||||
public static function getWarningsAsJsLog (): JavascriptRaw {
|
||||
/* @var */ $js_log_code = "";
|
||||
foreach (self::$warnings as $message) {
|
||||
$message = str_replace("\"", "\\\"", $message);
|
||||
$message = "[ph-Bookshelf] " . $message;
|
||||
$js_log_code .= "console.log(\"$message\");\n";
|
||||
}
|
||||
return new JavascriptRaw($js_log_code);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
<?php use SukWs\Bookshelf\Data\SiteConfig\ConfigName; ?>
|
||||
<?php use SukWs\Bookshelf\Data\SiteMeta; ?>
|
||||
<?php use SukWs\Bookshelf\Data\PageMeta; ?>
|
||||
<?php use SukWs\Bookshelf\PageMeta;
|
||||
use SukWs\Bookshelf\SiteConfig\ConfigName;
|
||||
use SukWs\Bookshelf\SiteMeta; ?>
|
||||
<?php ?>
|
||||
<?php ?>
|
||||
|
||||
<!-- Assets(js) --><?php
|
||||
foreach (SiteMeta::getJavascriptList() as $item) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php use SukWs\Bookshelf\Data\SiteConfig\ConfigName; ?>
|
||||
<?php use SukWs\Bookshelf\Data\SiteMeta; ?>
|
||||
<?php use SukWs\Bookshelf\Data\PageMeta; ?>
|
||||
<?php use SukWs\Bookshelf\SiteConfig\ConfigName; ?>
|
||||
<?php use SukWs\Bookshelf\SiteMeta; ?>
|
||||
<?php use SukWs\Bookshelf\PageMeta; ?>
|
||||
<?php use SukWs\Bookshelf\Web\WebWarn; ?>
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="<?= "" // TODO Page language ?>">
|
||||
<head>
|
||||
@ -35,5 +36,12 @@
|
||||
}
|
||||
</style>
|
||||
<style><?= SiteMeta::getCustomCssContent("custom") ?></style>
|
||||
<?php WebWarn::output("test warn"); ?>
|
||||
<?php
|
||||
$__web_js_warning_log = WebWarn::getWarningsAsJsLog();
|
||||
$__web_js_warning_log_document = new DOMDocument();
|
||||
$__web_js_warning_log_document->appendChild($__web_js_warning_log);
|
||||
echo $__web_js_warning_log_document->saveHTML();
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php use SukWs\Bookshelf\Data\SiteMeta; ?>
|
||||
<?php use SukWs\Bookshelf\Data\PageMeta; ?>
|
||||
<?php use SukWs\Bookshelf\PageMeta;
|
||||
use SukWs\Bookshelf\SiteMeta; ?>
|
||||
<?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>
|
||||
<a id="site-title" class="no-style" href="/"><?= SiteMeta::getBookshelf()->getSiteName() ?></a>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
use SukWs\Bookshelf\Utils\HTML\HTML;
|
||||
use SukWs\Bookshelf\Utils\LaTeX\LaTeX;
|
||||
use SukWs\Bookshelf\Utils\Markdown\Markdown;
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
use SukWs\Bookshelf\Data\PageMeta;
|
||||
use SukWs\Bookshelf\PageMeta;
|
||||
|
||||
PageMeta::$page->getSummaryHtml();
|
||||
|
Loading…
Reference in New Issue
Block a user