feat(域名切换): 添加官方站点切换组件及配置支持

在配置文件中添加officialSites字段支持多种格式的官方站点配置
创建DomainSwitcher组件用于显示和切换不同站点
更新布局脚本使用动态配置而非硬编码域名
This commit is contained in:
二叉树树
2025-11-27 09:30:35 +08:00
parent 8d53f6426a
commit aa0c33c775
5 changed files with 142 additions and 38 deletions

View File

@@ -291,7 +291,7 @@ var _hmt = _hmt || [];
<div id="page-height-extend" class="hidden h-[300vh]"></div>
<!-- 域名检测脚本 -->
<script is:inline define:vars={{officialSites: ["https://2x.nz", "https://blog.2b2x.cn", "https://b.2.f.f.0.7.4.0.1.0.0.2.ip6.arpa"]}}>
<script is:inline define:vars={{officialSites: siteConfig.officialSites || []}}>
// 域名检测功能
function checkDomain() {
try {
@@ -303,7 +303,8 @@ var _hmt = _hmt || [];
// 获取所有官方域名
const officialDomains = officialSites.map(site => {
try {
return new URL(site).hostname;
const url = typeof site === 'string' ? site : site.url;
return new URL(url).hostname;
} catch (e) {
return null;
}
@@ -329,7 +330,9 @@ var _hmt = _hmt || [];
if (shouldRedirect) {
// 构建官方网站的对应页面URL使用第一个官方网站
const currentPath = window.location.pathname + window.location.search + window.location.hash;
const officialPageUrl = officialSites[0] + currentPath;
const firstSite = officialSites[0];
const firstUrl = typeof firstSite === 'string' ? firstSite : firstSite.url;
const officialPageUrl = firstUrl + currentPath;
// 跳转到官方网站
window.location.href = officialPageUrl;
}