diff --git a/server/sources/hupu.ts b/server/sources/hupu.ts index 87445d5..c5e66ed 100644 --- a/server/sources/hupu.ts +++ b/server/sources/hupu.ts @@ -1,20 +1,37 @@ -interface Res { - data: { - title: string - hot: string - url: string - mobil_url: string - }[] +interface HotItem { + id: string + title: string + url: string + mobileUrl: string } export default defineSource(async () => { - const r: Res = await myFetch(`https://api.vvhan.com/api/hotlist/huPu`) - return r.data.map((k) => { - return { - id: k.url, - title: k.title, - url: k.url, - mobileUrl: k.mobil_url, - } - }) + // 获取虎扑新热榜页面的HTML内容 + const html = await myFetch(`https://bbs.hupu.com/topic-daily-hot`) + + // 正则表达式匹配新的热榜项结构 + const regex = /
  • [\s\S]*?]*?class="p-title"[^>]*>([^<]+)<\/a>/g + + const result: HotItem[] = [] + let match + + // 将赋值操作移到循环内部,修复no-cond-assign警告 + while (true) { + match = regex.exec(html) + if (!match) break + + const [, path, title] = match + + // 构建完整URL + const url = `https://bbs.hupu.com${path}` + + result.push({ + id: path, + title: title.trim(), + url, + mobileUrl: url, + }) + } + + return result })