1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 09:26:52 +08:00

.tex 简单支持,测试性质的资源(图片)文件获取支持

This commit is contained in:
A.C.Sukazyo Eyre 2023-01-25 13:03:58 +08:00
parent c02929c7b1
commit 8dcd83c78d
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
6 changed files with 66 additions and 4 deletions

View File

@ -23,6 +23,7 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-fileinfo": "*", "ext-fileinfo": "*",
"league/commonmark": ">=2.3.8", "league/commonmark": ">=2.3.8",
"gregwar/rst": "^1.0" "gregwar/rst": "^1.0",
"xemlock/php-latex": "dev-master"
} }
} }

View File

@ -2,6 +2,6 @@
const APP_NAME = "ph-Bookshelf"; const APP_NAME = "ph-Bookshelf";
const VERSION = "0.3.2"; const VERSION = "0.3.3";
const CHANNEL = "suk-ws"; const CHANNEL = "suk-ws";
const BRANCH = "master"; const BRANCH = "master";

View File

@ -52,8 +52,22 @@ try {
// 页面寻找失败,寻找资源文件 // 页面寻找失败,寻找资源文件
if (!is_file($resLoc = "./data/%assets/$req")) { // 全局文件夹的资源文件 if ( // 搜索全局资源文件夹的指定文件
throw $e; file_exists($resLoc = "./data/%assets/$req")
) {} else if ( // 搜索原始路径上的文件
file_exists($resLoc = "./data/$req")
) {} else if ( // 搜索可能存在的书籍资源文件夹中的指定文件
sizeof($uri) > 1 && ($resBook = (SiteMeta::getBookshelf()->getBook($uri[0]))) != null &&
file_exists($resLoc = "./data/{$resBook->getId()}/%assets/$uri[1]")
) {} else if ( // 上面的 %root 兼容
sizeof($uri) > 1 && ($resBook = $uri[0]) == "%root" &&
file_exists($resLoc = "./data/$resBook/%assets/$uri[1]")
) {} else if ( // 搜索以root书为根目录的原始路径上的文件
file_exists($resLoc = "./data/%root/$req")
) {} else if ( // 搜索root书中的书籍资源文件夹中的文件
file_exists($resLoc = "./data/%root/%assets/$req")
) {} else {
throw $e; // 找不到资源文件
} }
PageParse::outputBinaryFile($resLoc); PageParse::outputBinaryFile($resLoc);

19
src/Utils/HTML/HTML.php Normal file
View File

@ -0,0 +1,19 @@
<?php
namespace SukWs\Bookshelf\Utils\HTML;
use SukWs\Bookshelf\Utils\PageContentType;
class HTML implements PageContentType {
public const type = array("html", "htm");
public function type (): array {
return self::type;
}
public function parse (string $raw): string {
return $raw;
}
}

24
src/Utils/LaTeX/LaTeX.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace SukWs\Bookshelf\Utils\LaTeX;
use PhpLatex_Parser;
use PhpLatex_Renderer_Html;
use SukWs\Bookshelf\Utils\PageContentType;
class LaTeX implements PageContentType {
public const type = array("tex");
/**
* @return string[]
*/
public function type (): array {
return self::type;
}
public function parse (string $raw): string {
return (new PhpLatex_Renderer_Html())->render((new PhpLatex_Parser())->parse($raw));
}
}

View File

@ -1,6 +1,8 @@
<?php <?php
use SukWs\Bookshelf\Data\PageMeta; use SukWs\Bookshelf\Data\PageMeta;
use SukWs\Bookshelf\Utils\HTML\HTML;
use SukWs\Bookshelf\Utils\LaTeX\LaTeX;
use SukWs\Bookshelf\Utils\Markdown\Markdown; use SukWs\Bookshelf\Utils\Markdown\Markdown;
use SukWs\Bookshelf\Utils\ReST\ReST; use SukWs\Bookshelf\Utils\ReST\ReST;
@ -25,7 +27,9 @@ if (PageMeta::compatibilityOldTitlePolicy() && PageMeta::$page->hasContent(Markd
} }
$parsers = array( $parsers = array(
new HTML(),
new Markdown(), new Markdown(),
new LaTeX(),
new ReST() new ReST()
); );