From 57915682ee0de67e5fcb2c572b12f9f5c17c382c Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 24 Nov 2021 14:24:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A7=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E5=85=BC=E5=AE=B9=E3=80=82=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20=E4=B9=A6=E6=9E=B6/=E4=B9=A6=E7=9B=AE/=E9=A1=B5=E9=9D=A2=20?= =?UTF-8?q?=E4=B8=89=E7=BA=A7=E9=85=8D=E7=BD=AE=E8=AF=BB=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E4=B8=BA=E4=B8=80=E4=BA=9B=E5=85=BC=E5=AE=B9=E5=8C=96=E5=92=8C?= =?UTF-8?q?=E4=B8=AA=E6=80=A7=E5=8C=96=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为旧的标题策略做出兼容: 当这个功能开启时,如果输出检测到markdown内没有填入一级标题,则会自动以 book.xml 中声明的页面标题生成一级标题。 添加的配置: - 旧的页面标题策略兼容 : 默认 false,可选 true - 代码块背景色 : 默认跟随样式表fallback,可填任意 css 支持颜色 - 代码块 highlight.js 高亮 : 默认 true,可选 false - highlight.js 主题 : 默认 atom-one-dark,可填任意字符串(但是没有对应主题会无法使用 - 彩虹列表标记效果 : 默认 false,可选 true --- constant.php | 2 +- src/Data/PageMeta.php | 27 +++++++++++++++ src/Data/SiteMeta.php | 19 +++++++--- src/Element/BookContent/BookContented.php | 8 +++++ src/Element/BookContent/Page.php | 8 +++++ src/Element/Bookshelf.php | 42 +++++++++++++++++++++++ template/footer.php | 8 +++-- template/header.php | 10 ++++-- template/raw-article.php | 18 ++++++++-- 9 files changed, 130 insertions(+), 12 deletions(-) diff --git a/constant.php b/constant.php index e9f2681..4ea100c 100644 --- a/constant.php +++ b/constant.php @@ -2,6 +2,6 @@ const APP_NAME = "ph-Bookshelf"; -const VERSION = "0.3.0.9"; +const VERSION = "0.3.0.10"; const CHANNEL = "suk-ws"; const BRANCH = "master"; diff --git a/src/Data/PageMeta.php b/src/Data/PageMeta.php index add6c7e..70fdf4c 100644 --- a/src/Data/PageMeta.php +++ b/src/Data/PageMeta.php @@ -1,5 +1,6 @@ getConfiguration($key); + if ($valueAttr != null) $value = $valueAttr; + return $value; + } + + public static function getConfigurationLevelPage (string $key): ?string { + $value = self::getConfigurationLevelBook($key); + $valueAttr = self::$page->getConfiguration($key); + if ($valueAttr != null) $value = $valueAttr; + return $value; + } + + public static function compatibilityOldTitlePolicy (): bool { + if (self::getConfigurationLevelPage("compatibility.article.title.oldversion") == "true") + return true; + return false; + } + + public static function highlightJsTheme (): string { + $theme = trim(self::getConfigurationLevelPage("customization.article.codeblock.highlightjs.theme")); + if (empty($theme)) return "atom-one-dark"; + return $theme; + } + } diff --git a/src/Data/SiteMeta.php b/src/Data/SiteMeta.php index a3fb68d..5f81b8e 100644 --- a/src/Data/SiteMeta.php +++ b/src/Data/SiteMeta.php @@ -1,5 +1,6 @@ getConfiguration($key); + } + } diff --git a/src/Element/BookContent/BookContented.php b/src/Element/BookContent/BookContented.php index 6a3383b..412cbab 100644 --- a/src/Element/BookContent/BookContented.php +++ b/src/Element/BookContent/BookContented.php @@ -1,6 +1,7 @@ id = $id; $this->name = $name; @@ -32,6 +35,7 @@ class BookContented { else $id = $attrId->nodeValue; $node = new BookContented($id, $name); $node->childs = Chapter::parse($xmlData, null); + Bookshelf::parseConfigurationAttr($xmlData->attributes, $node->configurations, array("name", "id")); } else throw new Exception("No child or attribute found on BookWithContent"); return $node; @@ -71,4 +75,8 @@ class BookContented { return $this->childs->getPage($id); } + public function getConfiguration (string $key): ?string { + return @$this->configurations[$key]; + } + } diff --git a/src/Element/BookContent/Page.php b/src/Element/BookContent/Page.php index ee08a42..592cc1c 100644 --- a/src/Element/BookContent/Page.php +++ b/src/Element/BookContent/Page.php @@ -1,6 +1,7 @@ id = $id; $this->name = $name; @@ -33,6 +36,7 @@ class Page { if ($attrId == null) throw new Exception("Page xml data named \"$name\" missing attribute \"id\""); else $id = $attrId->nodeValue; $node = new Page($id, $name, $parent); + Bookshelf::parseConfigurationAttr($xmlData->attributes, $node->configurations, array("name", "id")); } else throw new Exception("Book xml data missing attributes"); for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) { @@ -57,6 +61,10 @@ class Page { return $this->parent; } + public function getConfiguration (string $key): ?string { + return @$this->configurations[$key]; + } + public function getSummaryHtml (): string { // $str = // "