From bc8d4ce2fee61ef005df81f439d1386902a52241 Mon Sep 17 00:00:00 2001 From: zls <1460662245@qq.com> Date: Thu, 25 Jul 2024 17:28:29 +0800 Subject: [PATCH] add SITE SORT --- .env | 3 +++ src/utils/getSiteData.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.env b/.env index 06a656bf..2d2b6595 100644 --- a/.env +++ b/.env @@ -29,3 +29,6 @@ VITE_HOME_URL = "https://www.imsyy.top/" # 邮箱地址 VITE_EMAIL_URL = "one@imsyy.top" + +# 根据网站名称(friendly_name)排序,使用逗号分隔 +VITE_SITE_SORT = "主页,今日热榜,ruoxijun.uk" \ No newline at end of file diff --git a/src/utils/getSiteData.js b/src/utils/getSiteData.js index 79bccf41..62c2f04b 100644 --- a/src/utils/getSiteData.js +++ b/src/utils/getSiteData.js @@ -109,6 +109,19 @@ const getMonitorsData = async (postdata, status) => { * @returns {Array} - 处理后的数据 */ const dataProcessing = (data, dates) => { + try { + let siteSortArr = import.meta.env.VITE_SITE_SORT; + siteSortArr = siteSortArr.split(",").map(v => v.trim()).reverse(); + + data = data.sort((v1, v2) => { + const i1 = siteSortArr.indexOf(v1.friendly_name.trim()) + 1; + const i2 = siteSortArr.indexOf(v2.friendly_name.trim()) + 1; + return (i2 == -1 ? 0 : i2) - (i1 == -1 ? 0 : i1); + }); + } catch (error) { + console.error("处理监控数据网站排序时出错:", error); + } + return data?.map((monitor) => { const ranges = monitor.custom_uptime_ranges.split("-"); const average = formatNumber(ranges.pop());