From edf603fbbe1bd16cbb1599b481bda27b66be8af3 Mon Sep 17 00:00:00 2001 From: SuperJeason <118799372+SuperJeason@users.noreply.github.com> Date: Sat, 12 Apr 2025 22:11:44 +0800 Subject: [PATCH] fix(route): fix swjtu/scai/bks route (#18832) * fix(route): fix swjtu/scai/bks route) * fix(route): fix swjtu/scai/bks route) * fix(route): fix swjtu/scai/bks route) * fix(route): fix swjtu/scai/bks route) * fix(route): fix swjtu/scai/bks route) * fix(route): fix swjtu/scai/bks route) * fix(route): fix swjtu/scai/bks route) --- lib/routes/swjtu/scai.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/routes/swjtu/scai.ts b/lib/routes/swjtu/scai.ts index 2e76f8d93..35fc42cf8 100644 --- a/lib/routes/swjtu/scai.ts +++ b/lib/routes/swjtu/scai.ts @@ -54,21 +54,36 @@ const partition = { const getItem = (item, cache) => { const title = item.find('a').text(); const link = `${rootURL}${item.find('a').attr('href').slice(2)}`; + // console.log(link); return cache.tryGet(link, async () => { const res = await ofetch(link); const $ = load(res); - + let pubDate: Date; let dateText = $('div.news-info span:nth-of-type(2)').text(); // 转教务通知时的时间获取方法 if (!dateText) { dateText = $('div.news-top-bar span:nth-of-type(1)').text(); } // 'date' may be undefined. and 'parseDate' will return current time. - const date = dateText.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)?.[0]; - const pubDate = parseDate(date); + // 转其他院的通知,获取不到具体时间,先从列表页获取具体信息 + if (dateText) { + const dateMatch = dateText.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/); + if (!dateMatch || !dateMatch[0]) { + return null; + } + pubDate = parseDate(dateMatch[0]); + } else { + const dateItem = item.find('.calendar'); // 注意 .calendar 是 class + const day = dateItem.find('.day').text().trim(); // "31" (文本需 trim 去空格) + const ymd = dateItem.find('.date').text().trim(); // "2025/03" + const [year, month] = ymd.split('/'); // ["2025", "03"] + const dateText = `${year}-${month}-${day.padStart(2, '0')}`; + pubDate = new Date(dateText); + } const description = $('div.content-main').html(); - + // 确实无法获取时间就以当前时间为准 + pubDate ||= new Date('2025-04-12'); // 使用当前时间作为默认值 return { title, pubDate,