Files
wordpress-kratos-yang/inc/theme-custom-code.php
T
laoyang 4f0d19fb91 版本号 3.2.4 -> 3.2.5(修 Prism 报错,项目地址改为自建 Git)
## 修 Prism is not defined

首页控制台报 `Uncaught ReferenceError: Prism is not defined`,来源是
wp-editormd 插件(不是本主题):它在 Prism 脚本加载之前就无条件执行了
`Prism.plugins.autoloader.languages_path = "..."`。

线上页面里的真实顺序:
    第 668 行  该赋值语句
    第 695 行  prism-core.min.js
    第 696 行  prism-autoloader.min.js

在 `wp_head` 优先级 0 垫一个最小空壳 `window.Prism`(含 plugins.autoloader
这条访问链路),让那句赋值有地方可写。已核对 prism-core.min.js 源码:它开头
只读 `u.Prism.manual` 与 `u.Prism.disableWorkerMessageHandler`,结尾
`global.Prism = Prism` 整体覆盖 —— 空壳必定被真实对象替换,不承担持久职责,
只为吸收那条过早的赋值。已用 jsdom 验证:去掉空壳重现原始报错,加上后消失,
且之后 `Prism.highlightAll` 仍可正常调用。

## 项目地址统一到 code.yangyq.net

原作者署名、原主题地址、README、语言包、JS 里的控制台横幅全部换成自建仓库地址。
LICENSE 文件保持原样不动(MIT 要求保留原始版权声明)。

## CDN 分支改成拿不到就回退本地

原来的 `g_cdn` 分支指向 `cdn.jsdelivr.net/gh/vtrois/kratos`,本仓库在自建
Gitea 上,jsDelivr 只认 github/npm/wordpress,实测该地址 404。现改为仅在
`YANG_THEME_CDN_REPO` 常量存在时才走 CDN,否则一律用
`get_template_directory_uri()`。留一个 404 的地址比留空更危险:页面能开、
样式全丢,极难排查。

## 顺带

- `.gitattributes` 补 `*.mo binary`:原来是靠"含 NUL"启发式判定,不是契约
- `update.json` 的版本号跟进到 3.2.5
- `kratos.min.js` / `kratos.min.css` 用压缩器重新生成,不手工改产物
2026-10-23 12:55:41 +08:00

68 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 自定义代码(CSS / JS)
*
* 这两段代码存在主题选项里(数据库 wp_options 的 kratos 项),不存主题目录。
* 原因:WordPress 升级/更新主题时会**清空整个主题目录**再解压
* (wp-admin/includes/class-theme-upgrader.php 里 clear_destination = true,
* 随后 delete_old_theme() 递归删除),写在主题目录里的任何自定义文件都会丢。
* 放进选项表就与主题文件解耦,升级、重装、换主题目录名都不影响。
*
* @author Yongquan Yang <yangyq.net>
* @license MIT License
*/
/**
* 默认自定义 CSS。
*
* 历史沿革:这些规则原本放在主题目录下的一个 custom 子目录里,是该主题早期的
* 「自定义样式」入口。改成配置项后,把它作为默认值,保证切换瞬间站点外观
* 完全不变;同时 `恢复默认` 也能拿回这套样式。
*
* 想彻底清掉:在后台把「自定义 CSS」清空保存即可(空值会覆盖这里的默认值)。
*/
function yang_default_custom_css()
{
return <<<'CSS'
.article .content p{ text-indent:2em }
.k-main .details .article .content h2 {
margin: 16px -16px;
padding: 0 10px;
border-left: 5px solid #00a2ff;
background-color: rgba(243, 243, 243, 0.7);
font-size: 20px;
line-height: 41px;
}
ul{
margin-left:2em;
}
ol{
margin-left:2em;
}
ol > li{
line-height: 1.8;
}
ul > li{
line-height: 1.8;
}
CSS;
}
/**
* 取自定义 CSS(未设置时回退到默认值)
*/
function yang_custom_css()
{
$css = kratos_option('g_custom_css', yang_default_custom_css());
return is_string($css) ? $css : '';
}
/**
* 取自定义 JS(未设置时为空)
*/
function yang_custom_js()
{
$js = kratos_option('g_custom_js', '');
return is_string($js) ? $js : '';
}