2024-10-07 22:35:50 +08:00
|
|
|
import * as cheerio from "cheerio"
|
|
|
|
import type { NewsItem } from "@shared/types"
|
|
|
|
|
|
|
|
export default defineSource(async () => {
|
2024-10-21 03:05:50 +08:00
|
|
|
const response: any = await $fetch("https://www.ithome.com/list/")
|
2024-10-07 22:35:50 +08:00
|
|
|
const $ = cheerio.load(response)
|
|
|
|
const $main = $("#list > div.fl > ul > li")
|
|
|
|
const news: NewsItem[] = []
|
|
|
|
$main.each((_, el) => {
|
|
|
|
const $el = $(el)
|
|
|
|
const $a = $el.find("a.t")
|
|
|
|
const url = $a.attr("href")
|
|
|
|
const title = $a.text()
|
|
|
|
const date = $(el).find("i").text()
|
|
|
|
if (url && title && date) {
|
|
|
|
const isAd = url?.includes("lapin") || ["神券", "优惠", "补贴", "京东"].find(k => title.includes(k))
|
|
|
|
if (!isAd) {
|
|
|
|
news.push({
|
|
|
|
url,
|
|
|
|
title,
|
|
|
|
id: url,
|
|
|
|
extra: {
|
|
|
|
date: tranformToUTC(date),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2024-10-08 20:49:19 +08:00
|
|
|
return news.sort((m, n) => n.extra!.date > m.extra!.date ? 1 : -1)
|
2024-10-07 22:35:50 +08:00
|
|
|
})
|