|
| 1 | +import type { RouterData } from "../types.js"; |
| 2 | +import { load } from "cheerio"; |
| 3 | +import { get } from "../utils/getData.js"; |
| 4 | +import { getTime } from "../utils/getTime.js"; |
| 5 | +import { RouterType } from "../router.types.js"; |
| 6 | + |
| 7 | +export const handleRoute = async (_: undefined, noCache: boolean) => { |
| 8 | + const listData = await getList(noCache); |
| 9 | + |
| 10 | + const routeData: RouterData = { |
| 11 | + name: "gameres", |
| 12 | + title: "GameRes 游资网", |
| 13 | + type: "最新资讯", |
| 14 | + description: |
| 15 | + "面向游戏从业者的游戏开发资讯,旨在为游戏制作人提供游戏研发类的程序技术、策划设计、艺术设计、原创设计等资讯内容。", |
| 16 | + link: "https://www.gameres.com", |
| 17 | + total: listData.data?.length || 0, |
| 18 | + ...listData, |
| 19 | + }; |
| 20 | + |
| 21 | + return routeData; |
| 22 | +}; |
| 23 | + |
| 24 | +const getList = async (noCache: boolean) => { |
| 25 | + const url = `https://www.gameres.com`; |
| 26 | + const result = await get({ url, noCache }); |
| 27 | + const $ = load(result.data); |
| 28 | + |
| 29 | + const container = $('div[data-news-pane-id="100000"]'); |
| 30 | + const listDom = container.find("article.feed-item"); |
| 31 | + |
| 32 | + const listData = Array.from(listDom).map((el) => { |
| 33 | + const dom = $(el); |
| 34 | + |
| 35 | + const titleEl = dom.find(".feed-item-title-a").first(); |
| 36 | + const title = titleEl.text().trim(); |
| 37 | + |
| 38 | + const href = titleEl.attr("href"); |
| 39 | + const url = href?.startsWith("http") ? href : `https://www.gameres.com${href ?? ""}`; |
| 40 | + |
| 41 | + const cover = dom.find(".thumb").attr("data-original") || ""; |
| 42 | + const desc = dom.find(".feed-item-right > p").first().text().trim(); |
| 43 | + |
| 44 | + const dateTime = dom.find(".mark-info").contents().first().text().trim(); |
| 45 | + const timestamp = getTime(dateTime); |
| 46 | + |
| 47 | + // 热度(列表暂无评论数) |
| 48 | + const hot = undefined; |
| 49 | + |
| 50 | + return { |
| 51 | + title, |
| 52 | + desc, |
| 53 | + cover, |
| 54 | + timestamp, |
| 55 | + hot, |
| 56 | + url, |
| 57 | + id: url, |
| 58 | + mobileUrl: url, |
| 59 | + } as RouterType["gameres"]; |
| 60 | + }); |
| 61 | + |
| 62 | + return { |
| 63 | + ...result, |
| 64 | + data: listData, |
| 65 | + }; |
| 66 | +}; |
0 commit comments