fix(route/hupu): parse date from content

This commit is contained in:
Stephen Zhou 2025-09-16 15:30:55 +08:00
parent 0669d68a55
commit 2c93053fa0
No known key found for this signature in database
1 changed files with 10 additions and 4 deletions

View File

@ -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(`<img src="${content(this).attr('data-origin')}">`);
});
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