fix(route/hupu): parse date from content
This commit is contained in:
parent
0669d68a55
commit
2c93053fa0
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue