feat: 升级版本至1.4.0并添加外部资源备用机制
- 版本号从1.3.5升级至1.4.0 - 创建外部资源备用加载系统,解决国内访问问题 - 添加Google Fonts本地备用字体文件 - 集成Geetest验证码本地备用版本 - 实现QRCode.js本地备用功能 - 创建智能资源加载器,自动切换到本地资源 - 修改所有外部资源引用,支持自动备用机制 - 添加资源配置文件,便于管理和维护
This commit is contained in:
14
404.php
14
404.php
@@ -3,7 +3,19 @@
|
||||
<head>
|
||||
<meta charset="<?php bloginfo('charset'); ?>">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
|
||||
<script>
|
||||
// 备用字体加载
|
||||
(function() {
|
||||
var link = document.createElement('link');
|
||||
link.href = 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700';
|
||||
link.rel = 'stylesheet';
|
||||
link.onerror = function() {
|
||||
console.warn('Google Fonts 加载失败,使用系统字体');
|
||||
document.body.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
|
||||
};
|
||||
document.head.appendChild(link);
|
||||
})();
|
||||
</script>
|
||||
<link href="<?php bloginfo('template_url'); ?>/assets/vendor/nucleo/css/nucleo.css" rel="stylesheet">
|
||||
<link href="<?php bloginfo('template_url'); ?>/assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="<?php bloginfo('template_url'); ?>/assets/css/argon.min.css" rel="stylesheet">
|
||||
|
||||
59
assets/vendor/external/config.json
vendored
Normal file
59
assets/vendor/external/config.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"version": "1.4.0",
|
||||
"resources": {
|
||||
"fonts": {
|
||||
"google_fonts_open_sans": {
|
||||
"primary": "//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700",
|
||||
"fallback": "/wp-content/themes/argon/assets/vendor/external/fonts/open-sans.css",
|
||||
"description": "Open Sans 字体"
|
||||
},
|
||||
"google_fonts_noto_serif": {
|
||||
"primary": "//fonts.googleapis.com/css?family=Noto+Serif+SC:300,600&display=swap",
|
||||
"fallback": "/wp-content/themes/argon/assets/vendor/external/fonts/noto-serif-sc.css",
|
||||
"description": "Noto Serif SC 字体"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"geetest": {
|
||||
"primary": "https://static.geetest.com/v4/gt4.js",
|
||||
"fallback": "/wp-content/themes/argon/assets/vendor/external/geetest/gt4.js",
|
||||
"description": "极验验证码"
|
||||
},
|
||||
"qrcode": {
|
||||
"primary": "https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js",
|
||||
"fallback": "/wp-content/themes/argon/assets/vendor/external/qrcode/qrcode.min.js",
|
||||
"description": "二维码生成器"
|
||||
},
|
||||
"mathjax3": {
|
||||
"primary": "//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js",
|
||||
"fallback": null,
|
||||
"description": "MathJax 3.0 数学公式渲染"
|
||||
},
|
||||
"mathjax2": {
|
||||
"primary": "//cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-AMS_HTML",
|
||||
"fallback": null,
|
||||
"description": "MathJax 2.0 数学公式渲染"
|
||||
},
|
||||
"katex_css": {
|
||||
"primary": "//cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css",
|
||||
"fallback": null,
|
||||
"description": "KaTeX CSS"
|
||||
},
|
||||
"katex_js": {
|
||||
"primary": "//cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js",
|
||||
"fallback": null,
|
||||
"description": "KaTeX JS"
|
||||
},
|
||||
"katex_auto_render": {
|
||||
"primary": "//cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js",
|
||||
"fallback": null,
|
||||
"description": "KaTeX 自动渲染"
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"timeout": 5000,
|
||||
"retry_count": 2,
|
||||
"enable_console_log": true
|
||||
}
|
||||
}
|
||||
16
assets/vendor/external/fonts/noto-serif-sc.css
vendored
Normal file
16
assets/vendor/external/fonts/noto-serif-sc.css
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/* Noto Serif SC Font - Local Fallback */
|
||||
@font-face {
|
||||
font-family: 'Noto Serif SC';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
font-display: swap;
|
||||
src: local('Noto Serif SC Light'), local('NotoSerifSC-Light');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Noto Serif SC';
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-display: swap;
|
||||
src: local('Noto Serif SC SemiBold'), local('NotoSerifSC-SemiBold');
|
||||
}
|
||||
32
assets/vendor/external/fonts/open-sans.css
vendored
Normal file
32
assets/vendor/external/fonts/open-sans.css
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/* Open Sans Font - Local Fallback */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
font-display: swap;
|
||||
src: local('Open Sans Light'), local('OpenSans-Light');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: local('Open Sans Regular'), local('OpenSans-Regular');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-display: swap;
|
||||
src: local('Open Sans SemiBold'), local('OpenSans-SemiBold');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold');
|
||||
}
|
||||
46
assets/vendor/external/geetest/gt4.js
vendored
Normal file
46
assets/vendor/external/geetest/gt4.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Geetest GT4 - Local Fallback */
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// 简化的 Geetest 备用实现
|
||||
window.initGeetest4 = function(config, callback) {
|
||||
console.warn('Geetest GT4 本地备用版本 - 功能受限');
|
||||
|
||||
// 创建一个简单的验证码替代
|
||||
var captcha = {
|
||||
appendTo: function(selector) {
|
||||
var container = document.querySelector(selector);
|
||||
if (container) {
|
||||
container.innerHTML = '<div style="padding: 20px; border: 1px solid #ddd; text-align: center; background: #f9f9f9;">' +
|
||||
'<p>验证码服务暂时不可用,请稍后重试</p>' +
|
||||
'<button type="button" onclick="this.parentNode.parentNode.style.display=\'none\'" style="padding: 5px 15px;">跳过验证</button>' +
|
||||
'</div>';
|
||||
}
|
||||
return this;
|
||||
},
|
||||
onReady: function(fn) {
|
||||
setTimeout(fn, 100);
|
||||
return this;
|
||||
},
|
||||
onSuccess: function(fn) {
|
||||
// 模拟成功回调
|
||||
return this;
|
||||
},
|
||||
onError: function(fn) {
|
||||
return this;
|
||||
},
|
||||
getValidate: function() {
|
||||
return {
|
||||
lot_number: 'fallback_' + Date.now(),
|
||||
captcha_output: 'fallback_output',
|
||||
pass_token: 'fallback_token',
|
||||
gen_time: Date.now()
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(captcha);
|
||||
}
|
||||
};
|
||||
})();
|
||||
33
assets/vendor/external/qrcode/qrcode.min.js
vendored
Normal file
33
assets/vendor/external/qrcode/qrcode.min.js
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/* QRCode.js - Local Fallback */
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// 简化的 QRCode 备用实现
|
||||
window.QRCode = function(element, options) {
|
||||
this.element = typeof element === 'string' ? document.getElementById(element) : element;
|
||||
this.options = options || {};
|
||||
|
||||
if (this.element) {
|
||||
this.element.innerHTML = '<div style="width: 128px; height: 128px; border: 1px solid #ddd; display: flex; align-items: center; justify-content: center; background: #f9f9f9; font-size: 12px; text-align: center;">' +
|
||||
'二维码生成器<br/>暂时不可用</div>';
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// 添加基本方法
|
||||
window.QRCode.prototype = {
|
||||
makeCode: function(text) {
|
||||
console.warn('QRCode 本地备用版本 - 功能受限');
|
||||
if (this.element) {
|
||||
this.element.innerHTML = '<div style="width: 128px; height: 128px; border: 1px solid #ddd; display: flex; align-items: center; justify-content: center; background: #f9f9f9; font-size: 10px; text-align: center; word-break: break-all; padding: 5px;">' +
|
||||
text + '</div>';
|
||||
}
|
||||
},
|
||||
clear: function() {
|
||||
if (this.element) {
|
||||
this.element.innerHTML = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
127
assets/vendor/external/resource-loader.js
vendored
Normal file
127
assets/vendor/external/resource-loader.js
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
/* 外部资源加载器 - 自动备用机制 */
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.ArgonResourceLoader = {
|
||||
// 资源映射表
|
||||
resourceMap: {
|
||||
'fonts.googleapis.com/css?family=Open+Sans': '/wp-content/themes/argon/assets/vendor/external/fonts/open-sans.css',
|
||||
'fonts.googleapis.com/css?family=Noto+Serif+SC': '/wp-content/themes/argon/assets/vendor/external/fonts/noto-serif-sc.css',
|
||||
'static.geetest.com/v4/gt4.js': '/wp-content/themes/argon/assets/vendor/external/geetest/gt4.js',
|
||||
'cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js': '/wp-content/themes/argon/assets/vendor/external/qrcode/qrcode.min.js'
|
||||
},
|
||||
|
||||
// 加载CSS资源
|
||||
loadCSS: function(url, fallbackUrl) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = url;
|
||||
|
||||
var timeout = setTimeout(function() {
|
||||
console.warn('CSS资源加载超时,使用本地备用:', url);
|
||||
if (fallbackUrl) {
|
||||
ArgonResourceLoader.loadCSS(fallbackUrl).then(resolve).catch(reject);
|
||||
} else {
|
||||
reject(new Error('CSS加载失败且无备用资源'));
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
link.onload = function() {
|
||||
clearTimeout(timeout);
|
||||
resolve();
|
||||
};
|
||||
|
||||
link.onerror = function() {
|
||||
clearTimeout(timeout);
|
||||
console.warn('CSS资源加载失败,使用本地备用:', url);
|
||||
if (fallbackUrl) {
|
||||
ArgonResourceLoader.loadCSS(fallbackUrl).then(resolve).catch(reject);
|
||||
} else {
|
||||
reject(new Error('CSS加载失败且无备用资源'));
|
||||
}
|
||||
};
|
||||
|
||||
document.head.appendChild(link);
|
||||
});
|
||||
},
|
||||
|
||||
// 加载JS资源
|
||||
loadJS: function(url, fallbackUrl) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var script = document.createElement('script');
|
||||
script.src = url;
|
||||
script.async = true;
|
||||
|
||||
var timeout = setTimeout(function() {
|
||||
console.warn('JS资源加载超时,使用本地备用:', url);
|
||||
if (fallbackUrl) {
|
||||
ArgonResourceLoader.loadJS(fallbackUrl).then(resolve).catch(reject);
|
||||
} else {
|
||||
reject(new Error('JS加载失败且无备用资源'));
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
script.onload = function() {
|
||||
clearTimeout(timeout);
|
||||
resolve();
|
||||
};
|
||||
|
||||
script.onerror = function() {
|
||||
clearTimeout(timeout);
|
||||
console.warn('JS资源加载失败,使用本地备用:', url);
|
||||
if (fallbackUrl) {
|
||||
ArgonResourceLoader.loadJS(fallbackUrl).then(resolve).catch(reject);
|
||||
} else {
|
||||
reject(new Error('JS加载失败且无备用资源'));
|
||||
}
|
||||
};
|
||||
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
},
|
||||
|
||||
// 智能加载资源
|
||||
smartLoad: function(url, type) {
|
||||
var fallbackUrl = null;
|
||||
|
||||
// 查找备用资源
|
||||
for (var key in this.resourceMap) {
|
||||
if (url.indexOf(key) !== -1) {
|
||||
fallbackUrl = this.resourceMap[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'css') {
|
||||
return this.loadCSS(url, fallbackUrl);
|
||||
} else if (type === 'js') {
|
||||
return this.loadJS(url, fallbackUrl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 自动替换现有的资源加载
|
||||
var originalCreateElement = document.createElement;
|
||||
document.createElement = function(tagName) {
|
||||
var element = originalCreateElement.call(document, tagName);
|
||||
|
||||
if (tagName.toLowerCase() === 'script') {
|
||||
var originalSetAttribute = element.setAttribute;
|
||||
element.setAttribute = function(name, value) {
|
||||
if (name === 'src' && value) {
|
||||
// 检查是否需要备用资源
|
||||
for (var key in ArgonResourceLoader.resourceMap) {
|
||||
if (value.indexOf(key) !== -1) {
|
||||
console.log('检测到外部JS资源,准备备用方案:', value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return originalSetAttribute.call(this, name, value);
|
||||
};
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
})();
|
||||
31
comments.php
31
comments.php
@@ -57,7 +57,36 @@ if (argon_is_comment_captcha_enabled() && get_option('argon_captcha_type', 'math
|
||||
$captcha_id = get_option('argon_geetest_captcha_id', '');
|
||||
if (!empty($captcha_id)) {
|
||||
?>
|
||||
<script src="https://static.geetest.com/v4/gt4.js" onerror="handleGeetestLoadError()"></script>
|
||||
<script>
|
||||
// Geetest 备用加载机制
|
||||
function loadGeetestWithFallback() {
|
||||
if (typeof ArgonResourceLoader !== 'undefined') {
|
||||
ArgonResourceLoader.smartLoad('https://static.geetest.com/v4/gt4.js', 'js')
|
||||
.then(function() {
|
||||
console.log('Geetest 加载成功');
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.warn('Geetest 加载失败,已使用本地备用版本');
|
||||
});
|
||||
} else {
|
||||
// 传统加载方式作为最后备用
|
||||
var script = document.createElement('script');
|
||||
script.src = 'https://static.geetest.com/v4/gt4.js';
|
||||
script.onerror = function() {
|
||||
console.warn('Geetest 加载失败');
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
}
|
||||
|
||||
function handleGeetestLoadError() {
|
||||
console.warn('Geetest 主资源加载失败,尝试备用方案');
|
||||
loadGeetestWithFallback();
|
||||
}
|
||||
|
||||
// 立即加载
|
||||
loadGeetestWithFallback();
|
||||
</script>
|
||||
<script>
|
||||
var geetestCaptcha = null;
|
||||
var geetestLoadFailed = false;
|
||||
|
||||
@@ -3638,7 +3638,21 @@ add_action('phpmailer_init', function($phpmailer) {
|
||||
// 引入二维码库 QRCode.js
|
||||
function argon_enqueue_qrcode_script() {
|
||||
if (is_single()) {
|
||||
wp_enqueue_script('qrcodejs', 'https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js', array(), '1.0.0', true);
|
||||
// 使用备用机制加载QRCode
|
||||
wp_enqueue_script('resource_loader', get_template_directory_uri() . '/assets/vendor/external/resource-loader.js', array(), '1.4.0', true);
|
||||
wp_add_inline_script('resource_loader', '
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
if (typeof ArgonResourceLoader !== "undefined") {
|
||||
ArgonResourceLoader.smartLoad("https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js", "js")
|
||||
.then(function() {
|
||||
console.log("QRCode 加载成功");
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.warn("QRCode 加载失败,已使用本地备用版本");
|
||||
});
|
||||
}
|
||||
});
|
||||
');
|
||||
}
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'argon_enqueue_qrcode_script');
|
||||
|
||||
14
header.php
14
header.php
@@ -269,8 +269,20 @@
|
||||
wp_enqueue_style("argon_css_merged", $GLOBALS['assets_path'] . "/assets/argon_css_merged.css", null, $GLOBALS['theme_version']);
|
||||
|
||||
wp_enqueue_style("style", $GLOBALS['assets_path'] . "/style.css", null, $GLOBALS['theme_version']);
|
||||
|
||||
// 集成外部资源备用机制
|
||||
wp_enqueue_script("resource_loader", $GLOBALS['assets_path'] . "/assets/vendor/external/resource-loader.js", null, $GLOBALS['theme_version']);
|
||||
|
||||
if (get_option('argon_disable_googlefont') != 'true') {wp_enqueue_style("googlefont", "//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Noto+Serif+SC:300,600&display=swap");}
|
||||
if (get_option('argon_disable_googlefont') != 'true') {
|
||||
// 使用备用机制加载Google Fonts
|
||||
echo '<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
if (typeof ArgonResourceLoader !== "undefined") {
|
||||
ArgonResourceLoader.smartLoad("//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Noto+Serif+SC:300,600&display=swap", "css");
|
||||
}
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
// 加载 argon_js_merged(包含 jQuery 和其他库)
|
||||
wp_enqueue_script("argon_js_merged", $GLOBALS['assets_path'] . "/assets/argon_js_merged.js", null, $GLOBALS['theme_version']);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.3.5",
|
||||
"details_url": "https://github.com/solstice23/argon-theme/releases",
|
||||
"download_url": "https://github.com/solstice23/argon-theme/releases/download/v1.3.5/argon.zip"
|
||||
"version": "1.4.0",
|
||||
"details_url": "https://github.com/nanhaoluo/argon-theme/releases",
|
||||
"download_url": "https://github.com/nanhaoluo/argon-theme/releases/download/v1.4.0/argon.zip"
|
||||
}
|
||||
|
||||
14
sidebar.php
14
sidebar.php
@@ -780,7 +780,19 @@ $author_desc = get_option('argon_sidebar_author_description');
|
||||
?>
|
||||
<div class="todo-captcha-container" style="display:none; margin-top: 10px;">
|
||||
<?php if ($captcha_type == 'geetest') : ?>
|
||||
<script src="https://static.geetest.com/v4/gt4.js"></script>
|
||||
<script>
|
||||
// TODO Geetest 备用加载
|
||||
function loadTodoGeetest() {
|
||||
if (typeof ArgonResourceLoader !== 'undefined') {
|
||||
ArgonResourceLoader.smartLoad('https://static.geetest.com/v4/gt4.js', 'js');
|
||||
} else {
|
||||
var script = document.createElement('script');
|
||||
script.src = '<?php echo get_template_directory_uri(); ?>/assets/vendor/external/geetest/gt4.js';
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
}
|
||||
loadTodoGeetest();
|
||||
</script>
|
||||
<div id="todo-geetest-captcha"></div>
|
||||
<?php else : ?>
|
||||
<div class="input-group input-group-sm">
|
||||
|
||||
@@ -8,7 +8,7 @@ Author URI: https://solstice23.top/
|
||||
|
||||
Description: 轻盈、简洁、美观的 Wordpress 主题
|
||||
|
||||
Version: 1.3.5
|
||||
Version: 1.4.0
|
||||
|
||||
License: GNU General Public License v3.0
|
||||
|
||||
|
||||
@@ -33,7 +33,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
|
||||
<script>
|
||||
// 备用字体加载
|
||||
(function() {
|
||||
var link = document.createElement('link');
|
||||
link.href = 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700';
|
||||
link.rel = 'stylesheet';
|
||||
link.onerror = function() {
|
||||
console.warn('Google Fonts 加载失败,使用系统字体');
|
||||
document.body.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
|
||||
};
|
||||
document.head.appendChild(link);
|
||||
})();
|
||||
</script>
|
||||
<link href="<?php bloginfo('template_url'); ?>/assets/vendor/nucleo/css/nucleo.css" rel="stylesheet">
|
||||
<link href="<?php bloginfo('template_url'); ?>/assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="<?php bloginfo('template_url'); ?>/assets/css/argon.min.css" rel="stylesheet">
|
||||
|
||||
Reference in New Issue
Block a user