refactor(Footer): 移除未使用的图片资源并优化服务器检测逻辑

删除未使用的图片资源文件,包括 eo.png、cf.webp、cf.svg 和 esa.svg
重构 Footer 组件中的服务器检测逻辑,简化代码并添加缓存机制
使用立即执行函数封装初始化逻辑,避免重复执行
This commit is contained in:
二叉树树
2026-01-11 04:00:20 +08:00
parent a7f644ee70
commit 6456605b3f
5 changed files with 62 additions and 173 deletions

View File

@@ -1,63 +0,0 @@
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1239.3 310.1" style="enable-background:new 0 0 1239.3 310.1;" xml:space="preserve">
<style type="text/css">
.st0{fill:#404041;}
.st1{fill:#FFFFFF;}
.st2{fill:#F38020;}
.st3{fill:#FAAE40;}
</style>
<g>
<g>
<path class="st0" d="M1158.5,187.7c-3.4,0-6.1-2.7-6.1-6.1c0-3.3,2.7-6.1,6.1-6.1c3.3,0,6.1,2.7,6.1,6.1
C1164.6,185,1161.8,187.7,1158.5,187.7 M1158.5,176.7c-2.7,0-4.9,2.2-4.9,4.9c0,2.7,2.2,4.9,4.9,4.9c2.7,0,4.9-2.2,4.9-4.9
C1163.4,178.9,1161.2,176.7,1158.5,176.7 M1161.6,184.8h-1.4l-1.2-2.3h-1.6v2.3h-1.3v-6.7h3.2c1.4,0,2.3,0.9,2.3,2.2
c0,1-0.6,1.7-1.4,2L1161.6,184.8z M1159.2,181.3c0.5,0,1-0.3,1-1c0-0.8-0.4-1-1-1h-2v2L1159.2,181.3L1159.2,181.3z">
</path>
<polygon class="st0" points="523,174.9 538.6,174.9 538.6,217.4 565.7,217.4 565.7,231 523,231 ">
</polygon>
<path class="st0" d="M581.8,203.1V203c0-16.1,13-29.2,30.3-29.2s30.1,12.9,30.1,29v0.2c0,16.1-13,29.2-30.3,29.2
C594.7,232.1,581.8,219.2,581.8,203.1 M626.4,203.1V203c0-8.1-5.8-15.1-14.4-15.1c-8.5,0-14.2,6.9-14.2,15v0.2
c0,8.1,5.8,15.1,14.3,15.1C620.7,218.1,626.4,211.2,626.4,203.1">
</path>
<path class="st0" d="M661.3,206.4v-31.5h15.8v31.2c0,8.1,4.1,11.9,10.3,11.9s10.3-3.7,10.3-11.5v-31.6h15.8V206
c0,18.1-10.3,26-26.3,26C671.3,232.1,661.3,224,661.3,206.4">
</path>
<path class="st0" d="M737.3,174.9H759c20,0,31.7,11.5,31.7,27.7v0.2c0,16.2-11.8,28.2-32,28.2h-21.3L737.3,174.9L737.3,174.9z
M759.2,217.2c9.3,0,15.5-5.1,15.5-14.2v-0.2c0-9-6.2-14.2-15.5-14.2h-6.3v28.5L759.2,217.2L759.2,217.2z">
</path>
<polygon class="st0" points="813.2,174.9 858.1,174.9 858.1,188.6 828.7,188.6 828.7,198.1 855.3,198.1 855.3,211 828.7,211
828.7,231 813.2,231 ">
</polygon>
<polygon class="st0" points="879.7,174.9 895.2,174.9 895.2,217.4 922.4,217.4 922.4,231 879.7,231 ">
</polygon>
<path class="st0" d="M963,174.5h15l23.9,56.5h-16.7l-4.1-10h-21.6l-4,10h-16.3L963,174.5z M976.7,208.9l-6.2-15.9l-6.3,15.9H976.7
z">
</path>
<path class="st0" d="M1021.9,174.9h26.5c8.6,0,14.5,2.2,18.3,6.1c3.3,3.2,5,7.5,5,13.1v0.2c0,8.6-4.6,14.3-11.5,17.2l13.4,19.6
h-18l-11.3-17h-6.8v17h-15.5L1021.9,174.9L1021.9,174.9z M1047.7,201.9c5.3,0,8.3-2.6,8.3-6.6V195c0-4.4-3.2-6.6-8.4-6.6h-10.2
v13.5L1047.7,201.9L1047.7,201.9z">
</path>
<polygon class="st0" points="1094.1,174.9 1139.2,174.9 1139.2,188.2 1109.5,188.2 1109.5,196.6 1136.4,196.6 1136.4,208.9
1109.5,208.9 1109.5,217.8 1139.6,217.8 1139.6,231 1094.1,231 ">
</polygon>
<path class="st0" d="M489,209.7c-2.2,4.9-6.8,8.4-12.8,8.4c-8.5,0-14.3-7.1-14.3-15.1v-0.2c0-8.1,5.7-15,14.2-15
c6.4,0,11.3,3.9,13.3,9.3h16.4c-2.6-13.4-14.4-23.3-29.6-23.3c-17.3,0-30.3,13.1-30.3,29.2v0.2c0,16.1,12.8,29,30.1,29
c14.8,0,26.4-9.6,29.4-22.4L489,209.7L489,209.7z">
</path>
</g>
<g>
<polygon class="st1" points="391.1,169.6 348.2,145 340.8,141.8 165.3,143.1 165.3,232.1 391.1,232.2 ">
</polygon>
<path class="st2" d="M313,224c2.1-7.2,1.3-13.8-2.2-18.7c-3.2-4.5-8.6-7.1-15.1-7.4l-123.1-1.6c-0.8,0-1.5-0.4-1.9-1
c-0.4-0.6-0.5-1.4-0.3-2.2c0.4-1.2,1.6-2.1,2.9-2.2l124.2-1.6c14.7-0.7,30.7-12.6,36.3-27.2l7.1-18.5c0.3-0.8,0.4-1.6,0.2-2.4
c-8-36.2-40.3-63.2-78.9-63.2c-35.6,0-65.8,23-76.6,54.9c-7-5.2-15.9-8-25.5-7.1c-17.1,1.7-30.8,15.4-32.5,32.5
c-0.4,4.4-0.1,8.7,0.9,12.7c-27.9,0.8-50.2,23.6-50.2,51.7c0,2.5,0.2,5,0.5,7.5c0.2,1.2,1.2,2.1,2.4,2.1l227.2,0
c1.3,0,2.5-0.9,2.9-2.2L313,224z">
</path>
<path class="st3" d="M352.2,144.9c-1.1,0-2.3,0-3.4,0.1c-0.8,0-1.5,0.6-1.8,1.4l-4.8,16.7c-2.1,7.2-1.3,13.8,2.2,18.7
c3.2,4.5,8.6,7.1,15.1,7.4l26.2,1.6c0.8,0,1.5,0.4,1.9,1c0.4,0.6,0.5,1.5,0.3,2.2c-0.4,1.2-1.6,2.1-2.9,2.2l-27.3,1.6
c-14.8,0.7-30.7,12.6-36.3,27.2l-2,5.1c-0.4,1,0.3,2,1.4,2h93.8c1.1,0,2.1-0.7,2.4-1.8c1.6-5.8,2.5-11.9,2.5-18.2
C419.5,175,389.4,144.9,352.2,144.9">
</path>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -1,19 +0,0 @@
<svg viewBox="0 0 295.93 37.28" xmlns="http://www.w3.org/2000/svg">
<defs><style>.cls-1{fill:#ff6a00;fill:}</style></defs>
<g data-name="图层 2" id="图层_2"><g data-name="图层 1" id="图层_1-2">
<rect class="cls-1" height="4.49" width="19.92" x="19.94" y="16.3"></rect>
<path class="cls-1" d="M49.84,0H36.66l3.18,4.5,9.61,3a4.15,4.15,0,0,1,2.9,4V25.84h0a4.17,4.17,0,0,1-2.9,4l-9.61,2.94-3.18,4.5H49.84a9.94,9.94,0,0,0,9.95-10V10A10,10,0,0,0,49.84,0Z"></path>
<path class="cls-1" d="M10,0H23.14L20,4.5l-9.61,3a4.16,4.16,0,0,0-2.91,4V25.84h0a4.18,4.18,0,0,0,2.91,4L20,32.78l3.18,4.5H10a10,10,0,0,1-10-10V10A10,10,0,0,1,10,0Z"></path>
<path class="cls-1" d="M221.19,26a5.91,5.91,0,0,1-11.81,0V11.78a5.91,5.91,0,0,1,11.81,0V12h4.52v-.17a10.43,10.43,0,0,0-20.85,0V26a10.42,10.42,0,0,0,20.84,0v-.19h-4.52Z"></path>
<path class="cls-1" d="M244.67,10.69a8.92,8.92,0,0,0-9,8.45v8.73a9,9,0,0,0,17.91,0V19.13A8.9,8.9,0,0,0,244.67,10.69Zm4.43,16.67a4.43,4.43,0,1,1-8.86,0V19.65a4.43,4.43,0,1,1,8.86,0Z"></path>
<rect class="cls-1" height="34.28" width="4.5" x="227.95" y="1.48"></rect>
<rect class="cls-1" height="25.07" width="4.5" x="103.81" y="10.69"></rect><rect class="cls-1" height="34.28" width="4.5" x="94.81" y="1.48"></rect>
<path class="cls-1" d="M83.45,1.48H77.9L68.8,35.71v0h4.49l2.42-9.1,10,0,2.41,9v0h4.49L83.45,1.5Zm1,20.72H76.89L80.67,8Z"></path>
<path class="cls-1" d="M270.27,27.83a4.44,4.44,0,1,1-8.88,0V10.69h-4.51V28.57A7.76,7.76,0,0,0,266.94,36a6.21,6.21,0,0,0,1.24-.51,7.7,7.7,0,0,0,1.87-1.35l.2-.19v1.84h4.54V10.69h-4.52Z"></path>
<rect class="cls-1" height="4.51" width="4.5" x="103.81" y="1.48"></rect><path class="cls-1" d="M122.93,10.66a7.72,7.72,0,0,0-5.42,2.22l-.19.19V1.48h-4.51V35.76h4.51V33.92l.19.19a7.76,7.76,0,0,0,13.18-5.54V18.42A7.77,7.77,0,0,0,122.93,10.66Zm3.31,8.58v8.51a4.45,4.45,0,1,1-8.9,0V19.24a4.45,4.45,0,1,1,8.9,0Z"></path>
<path class="cls-1" d="M164.89,10.66a7.72,7.72,0,0,0-5.43,2.22l-.19.19V1.48h-4.5V35.76h4.5V33.92l.19.19a7.76,7.76,0,0,0,13.18-5.54V18.42A7.77,7.77,0,0,0,164.89,10.66Zm3.3,8.58v8.5a4.45,4.45,0,1,1-8.9,0v-8.5a4.45,4.45,0,1,1,8.9,0Z"></path>
<path class="cls-1" d="M291.42,1.48V13.07l-.19-.19a7.75,7.75,0,0,0-13.18,5.54V28.6a7.76,7.76,0,0,0,13.18,5.51l.19-.19v1.84h4.51V1.48Zm0,17.76v8.5a4.45,4.45,0,1,1-8.9,0v-8.5a4.45,4.45,0,1,1,8.9,0Z"></path>
<path class="cls-1" d="M151.53,19.17a7.51,7.51,0,0,0-.09-.88l0-.12a9.2,9.2,0,0,0-1.54-3.76,8.79,8.79,0,0,0-6.69-3.73l-.52,0A9,9,0,0,0,133.83,18v0h4.42v0a4.45,4.45,0,0,1,4.35-3.59A4.46,4.46,0,0,1,147,18.69v2.1h-6.39a7.75,7.75,0,0,0-2,15.25l.12,0,.43.1.54.08h.11a10.9,10.9,0,0,0,1.17.06,8.5,8.5,0,0,0,2.71-.39,7.61,7.61,0,0,0,3.07-1.85l.2-.19v1.84h4.5v-3h0Zm-10.06,5H147v3.17a5,5,0,0,1-4.09,4.92,4.47,4.47,0,0,1-1,.12,4.52,4.52,0,0,1-2.28-.64,4.79,4.79,0,0,1-.58-.37,4.5,4.5,0,0,1-.69-.69l-.05-.06a4,4,0,0,1,3.19-6.45Z"></path>
<path class="cls-1" d="M193.54,19.19a7.51,7.51,0,0,0-.09-.88l0-.12a9.16,9.16,0,0,0-1.54-3.75,8.85,8.85,0,0,0-6.69-3.74h-.52A9,9,0,0,0,175.84,18v0h4.41v0a4.43,4.43,0,0,1,8.78.68v2.1h-6.4a7.75,7.75,0,0,0-1.95,15.25l.12,0,.43.1.54.08h.11a10.82,10.82,0,0,0,1.17.07,8.5,8.5,0,0,0,2.71-.39,7.84,7.84,0,0,0,3.07-1.85l.2-.19v1.84h4.5v-3h0Zm-10.06,5H189V27.4a5,5,0,0,1-4.09,4.92,4.47,4.47,0,0,1-1,.12,4.52,4.52,0,0,1-2.28-.64,3.82,3.82,0,0,1-.58-.37,4.57,4.57,0,0,1-.7-.69l0-.06a3.94,3.94,0,0,1-.83-2.42A4,4,0,0,1,183.48,24.23Z"></path>
</g></g>
</svg>

Before

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -56,110 +56,81 @@ try {
</div>
<script is:inline define:vars={{ serverConfig: siteConfig.server || [] }}>
function createServerEntry(config, index) {
const div = document.createElement('div');
div.className = 'flex items-center justify-center';
div.id = `server-entry-${index}`;
const label = document.createElement('span');
label.className = 'text-black/30 dark:text-white/30 text-xs mr-1';
label.innerText = `${config.text}`;
div.appendChild(label);
(() => {
if (window.__footerServerInit) return;
window.__footerServerInit = true;
const valueSpan = document.createElement('span');
valueSpan.className = 'server-value text-black/30 dark:text-white/30 text-xs';
valueSpan.innerText = '检测中...';
div.appendChild(valueSpan);
function normalizeUrl(input) {
if (!input) return "";
return input.trim().replace(/:+$/, "");
}
const iconImg = document.createElement('img');
iconImg.className = 'server-icon h-5 ml-1 hidden bg-white rounded p-0.5';
iconImg.alt = 'Server Icon';
div.appendChild(iconImg);
function createServerEntry(config) {
const div = document.createElement('div');
div.className = 'flex items-center justify-center';
return { div, valueSpan, iconImg };
}
const label = document.createElement('span');
label.className = 'text-black/30 dark:text-white/30 text-xs mr-1';
label.innerText = `${config.text}`;
div.appendChild(label);
function updateEntryDisplay(elements, server) {
const { valueSpan, iconImg } = elements;
if (server) {
valueSpan.innerText = server;
const serverLower = server.toLowerCase();
if (serverLower === 'edgeone-pages' || serverLower.includes('edgeone')) {
iconImg.src = '/cdn/eo.png';
iconImg.classList.remove('hidden');
valueSpan.classList.add('hidden');
} else if (serverLower === 'cloudflare') {
iconImg.src = '/cdn/cf.webp';
iconImg.classList.remove('hidden');
valueSpan.classList.add('hidden');
} else if (serverLower === 'esa') {
iconImg.src = '/cdn/esa.svg';
iconImg.classList.remove('hidden');
valueSpan.classList.add('hidden');
} else {
iconImg.classList.add('hidden');
valueSpan.classList.remove('hidden');
const valueSpan = document.createElement('span');
valueSpan.className = 'server-value text-black/30 dark:text-white/30 text-xs';
valueSpan.innerText = '检测中...';
div.appendChild(valueSpan);
return { div, valueSpan };
}
function updateEntryDisplay(elements, server) {
elements.valueSpan.innerText = server || "未知";
}
async function checkServer(url) {
try {
const targetUrl = normalizeUrl(url) || window.location.href;
const response = await fetch(targetUrl, { method: "HEAD" });
return response.headers.get('server');
} catch (error) {
console.warn(`Failed to fetch server info for ${url}:`, error);
return null;
}
} else {
valueSpan.innerText = "未知";
valueSpan.classList.remove('hidden');
iconImg.classList.add('hidden');
}
}
async function checkServer(url) {
try {
const targetUrl = url || window.location.href;
const response = await fetch(targetUrl, { method: "HEAD" });
return response.headers.get('server');
} catch (error) {
console.warn(`Failed to fetch server info for ${url}:`, error);
return null;
}
}
async function initServerInfo() {
const containers = document.querySelectorAll('.server-info-container');
if (containers.length === 0) return;
async function initServerInfo() {
const containers = document.querySelectorAll('.server-info-container');
if (containers.length === 0) return;
// Cache fetched results to avoid duplicate requests
const results = {};
window.__serverInfoCache = window.__serverInfoCache || {};
const cache = window.__serverInfoCache;
// Helper to get or fetch server info
const getServerInfo = async (url) => {
if (results[url] !== undefined) return results[url];
const server = await checkServer(url);
results[url] = server;
return server;
};
const getServerInfo = (url) => {
const key = normalizeUrl(url);
if (cache[key]) return cache[key];
cache[key] = checkServer(key);
return cache[key];
};
containers.forEach(container => {
// Clear existing content
container.innerHTML = '';
containers.forEach(container => {
container.innerHTML = '';
if (!serverConfig || serverConfig.length === 0) {
// Default fallback
const { div, valueSpan, iconImg } = createServerEntry({ text: '访问节点' }, 0);
container.appendChild(div);
getServerInfo('').then(server => {
updateEntryDisplay({ valueSpan, iconImg }, server);
});
} else {
serverConfig.forEach((config, index) => {
const elements = createServerEntry(config, index);
if (!serverConfig || serverConfig.length === 0) {
const elements = createServerEntry({ text: '访问节点' });
container.appendChild(elements.div);
getServerInfo('').then(server => updateEntryDisplay(elements, server));
return;
}
getServerInfo(config.url).then(server => {
updateEntryDisplay(elements, server);
});
serverConfig.forEach((config) => {
const elements = createServerEntry(config);
container.appendChild(elements.div);
getServerInfo(config.url).then(server => updateEntryDisplay(elements, server));
});
}
});
}
});
}
initServerInfo();
document.addEventListener('astro:after-swap', initServerInfo);
document.addEventListener('content:replace', initServerInfo);
initServerInfo();
document.addEventListener('astro:after-swap', initServerInfo);
document.addEventListener('content:replace', initServerInfo);
})();
</script>