1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2025-02-24 23:20:52 +08:00
ph-Bookshelf/src/Data/SiteMeta.php
Eyre_S 4b5a33278f
添加标题permalink链接和指向闪烁功能,添加滚动网页标题插件
- 添加插件 rolling-title 可以使网页标题有滚动向左的效果
  - 默认关闭,使用 enhanced.web.web-title.rolling-title = true 打开
- PHP Markdown 添加 Heading_Permalink 插件
  - 支持了自动为标题生成同名定位标
  - 添加了一个 ⁕ 悬浮的 permalink 按钮
  - 添加了插件 heading-permalink-highlights 使标题被定位时 permalink 按钮会产生闪烁效果
2023-01-27 19:10:05 +08:00

107 lines
3.8 KiB
PHP

<?php
namespace SukWs\Bookshelf\Data;
use Exception;
use SukWs\Bookshelf\Data\SiteConfig\RobotsPolicy;
use SukWs\Bookshelf\Element\Bookshelf;
class SiteMeta {
private static Bookshelf $BOOKSHELF;
static function get_frontpage_generate_version (): string {
return APP_NAME." ".VERSION;
}
public static function getProgramVersion(): string {
return sprintf("%s @%s/%s", VERSION, CHANNEL, BRANCH);
}
/**
* @throws Exception
*/
public static function load (): void {
self::$BOOKSHELF = Bookshelf::parseString(file_get_contents("./data/bookshelf.xml"));
}
public static function getBookshelf(): Bookshelf {
return self::$BOOKSHELF;
}
public static function getGlobalIcon (): string {
return "/favicon.ico"; // TODO ICON
}
public static function getStylesheetsList (): array {
return array(
// "/assets/gitbook/style.css",
// "/assets/gitbook/gitbook-plugin-fontsettings/website.css",
// "/assets/gitbook-fix.css",
// "/assets/ref.css",
(PageMeta::getConfigurationLevelPage("customization.article.codeblock.highlightjs")=="false"?
null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/".PageMeta::highlightJsTheme().".min.css"),
(PageMeta::getConfigurationLevelPage("customization.article.regex.highlight")=="false")?
null:"//cdn.jsdelivr.net/gh/suk-ws/regex-colorizer@master/regex-colorizer-default.min.css",
"/assets/bread-card-markdown.css?ver=1",
"/assets/bread-card-markdown-footnote.css?ver=1",
"/assets/bread-card-markdown-task-list.css?ver=1",
"/assets/bread-card-markdown-heading-permalink.css?ver=1",
(PageMeta::getConfigurationLevelPage("customization.article.listing.rainbow.marker")=="true"?
"/assets/bread-card-markdown-enhanced-listing-rainbow.css?ver=1":null),
"/assets/bread-card-markdown-compat-highlight-js.css?ver=1",
"/assets/main.css?ver=1",
);
}
public static function getJavascriptList (): array {
return array(
// "/assets/gitbook/gitbook.js",
// "/assets/gitbook-fix.js",
// "https://cdn.jsdelivr.net/npm/marked/marked.min.js",
// "/assets/ref.js",
(PageMeta::getConfigurationLevelPage("customization.article.codeblock.highlightjs")=="false"?
null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"),
(PageMeta::getConfigurationLevelPage("customization.article.regex.highlight")=="false"?
null:"//cdn.jsdelivr.net/gh/suk-ws/regex-colorizer@master/regex-colorizer.min.js"),
(PageMeta::getConfigurationLevelPage("enhanced.web.web-title.rolling-title")=="true"?
"/assets/enhanced-rolling-title.js?ver=1":null),
(PageMeta::getConfigurationLevelPage("customization.article.title.permalink.highlight-on-focus")=="true"?
"/assets/bread-card-markdown-heading-permalink-highlight.js?ver=1":null),
"/assets/utils-touchscreen-event.js?ver=1",
"/assets/main.js?ver=1",
);
}
public static function getCustomCssContent (string $id): string {
if (!file_exists("./data/$id.css")) return "";
return file_get_contents("./data/$id.css");
}
public static function getCustomScriptContent (string $id): string {
if (!file_exists("./data/$id.js")) return "";
return file_get_contents("./data/$id.js");
}
public static function getUserThemes (): string {
$fontSize = $_COOKIE['font-size'] ?? 2;
$fontFamily = $_COOKIE['font-family'] ?? 1;
$colorTheme = $_COOKIE['color-theme'] ?? 0;
return "font-size-$fontSize font-family-$fontFamily color-theme-$colorTheme";
}
public static function getConfigurationLevelShelf (string $key): ?string {
return self::$BOOKSHELF->getConfiguration($key);
}
public static function getRobotsPolicy (): RobotsPolicy {
return match (self::getConfigurationLevelShelf("site.robots")) {
"allow", null => RobotsPolicy::allow,
"deny" => RobotsPolicy::deny,
"custom", "file" => RobotsPolicy::file,
default => RobotsPolicy::raw,
};
}
}