Files
wordpress-kratos-yang/inc/theme-setting.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

131 lines
4.0 KiB
PHP

<?php
/**
* 站点相关函数
* @author Yongquan Yang <yangyq.net>
* @license MIT License
* @version 2020.08.04
*/
// 标题配置
function title($title, $sep)
{
global $paged, $page;
if (is_feed()) {
return $title;
}
$title .= get_bloginfo('name');
$site_description = get_bloginfo('description', 'display');
if ($site_description && (is_home() || is_front_page())) {
$title = "{$title} {$sep} {$site_description}";
}
if ($paged >= 2 || $page >= 2) {
$title = "{$title} {$sep} " . sprintf(__('第 %s 页', 'kratos'), max($paged, $page));
}
return $title;
}
add_filter('wp_title', 'title', 10, 2);
// Keywords 配置
function keywords()
{
global $post;
$keywords = '';
if (is_home()) {
$keywords = kratos_option('seo_keywords');
} elseif (is_single()) {
$keywords = get_post_meta($post->ID, "seo_keywords_value", true);
if ($keywords == '') {
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag) {
$keywords = $keywords . $tag->name . ",";
}
$keywords = rtrim($keywords, ',');
}
} elseif (is_page()) {
$keywords = get_post_meta($post->ID, "seo_keywords_value", true);
if ($keywords == '') {
$keywords = kratos_option('seo_keywords');
}
} else {
$keywords = single_tag_title('', false);
}
return trim(strip_tags($keywords));
}
// Description 配置
function description()
{
global $post;
$description = '';
if (is_home()) {
$description = kratos_option('seo_description');
} elseif (is_single()) {
$description = get_post_meta($post->ID, "seo_description_value", true);
if ($description == '') {
$description = get_the_excerpt();
}
if ($description == '') {
$description = str_replace("\n", "", mb_strimwidth(strip_tags($post->post_content), 0, 200, "…", 'utf-8'));
}
} elseif (is_category()) {
$description = category_description();
} elseif (is_tag()) {
$description = tag_description();
} elseif (is_page()) {
$description = get_post_meta($post->ID, "seo_description_value", true);
if ($description == '') {
$description = kratos_option('seo_description');
}
}
return trim(strip_tags($description));
}
// robots.txt 配置
add_filter('robots_txt', function ($output, $public) {
if ('0' == $public) {
return "User-agent: *\nDisallow: /\n";
} else {
if (!empty(kratos_option('seo_robots'))) {
$output = esc_attr(strip_tags(kratos_option('seo_robots')));
}
return $output;
}
}, 10, 2);
// 哀悼黑白站点
function mourning()
{
if (is_home() && kratos_option('g_rip', false)) {
echo '<style type="text/css">html{filter: grayscale(100%);-webkit-filter: grayscale(100%);-moz-filter: grayscale(100%);-ms-filter: grayscale(100%);-o-filter: grayscale(100%);filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);filter: gray;-webkit-filter: grayscale(1); } </style>';
}
}
// 抓取图片链接(搜索引擎或者社交工具分享时抓取图片的链接)
/*
function share_thumbnail_url()
{
global $post;
if (has_post_thumbnail($post->ID)) {
$post_thumbnail_id = get_post_thumbnail_id($post);
$img = wp_get_attachment_image_src($post_thumbnail_id, 'full');
$img = $img[0];
} else {
$content = $post->post_content;
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?); ?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
if (!empty($strResult[1])) {
$img = $strResult[1][0];
} else {
$img = kratos_option('seo_shareimg', ASSET_PATH . '/assets/img/default.jpg');
}
}
return $img;
}
*/
// 支持上传 svg
add_filter('upload_mimes', 'upload_svg');
function upload_svg($existing_mimes = array())
{
$existing_mimes['svg'] = 'image/svg+xml';
return $existing_mimes;
}