From 2c93053fa0ce35ccc35776abdc9fc448623b323b Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Tue, 16 Sep 2025 15:30:55 +0800 Subject: [PATCH] fix(route/hupu): parse date from content --- lib/routes/hupu/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/routes/hupu/index.ts b/lib/routes/hupu/index.ts index e92e7f4aa..4e338ef41 100644 --- a/lib/routes/hupu/index.ts +++ b/lib/routes/hupu/index.ts @@ -3,7 +3,7 @@ import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import timezone from '@/utils/timezone'; -import { parseDate } from '@/utils/parse-date'; +import { parseDate, parseRelativeDate } from '@/utils/parse-date'; import { type HupuApiResponse, type HomePostItem, type NewsDataItem, isHomePostItem } from './types'; const categories = { @@ -123,6 +123,11 @@ export const route: Route = { const content = load(detailResponse.data); const author = content('.bbs-user-info-name, .bbs-user-wrapper-content-name-span').text(); + const pubDateString = content('.second-line-user-info span:not([class])').text(); + // Possible formats: 10:21, 45分钟前, 09-15 19:57 + const pubDate = [item.pubDate, timezone(parseDate(pubDateString), +8), timezone(parseRelativeDate(pubDateString), +8), timezone(parseRelativeDate(`Today ${pubDateString}`), +8)].find( + (d) => d instanceof Date && !Number.isNaN(d.getTime()) + ); const categories = content('.basketballTobbs_tag > a, .tag-player-team') .toArray() .map((c) => content(c).text()) @@ -135,13 +140,14 @@ export const route: Route = { .html(``); }); - const description = content('#bbs-thread-content, .bbs-content-font').html(); + const description = content('#bbs-thread-content, .bbs-content-font').html() || undefined; return { ...item, - author: author || undefined, + author, category: categories.length > 0 ? categories : item.category, - description: description || undefined, + description, + pubDate, }; } catch { // no-empty