feat: hpoi banner-item details

This commit is contained in:
DIYgod 2025-09-10 21:26:40 +08:00
parent 590dffab2b
commit 1041cfdcaa
No known key found for this signature in database
1 changed files with 28 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
@ -33,19 +34,35 @@ async function handler() {
url: link,
});
const $ = load(response.data);
const items = await Promise.all(
$('#content .item')
.toArray()
.map(async (_item) => {
const $item = $(_item);
const link = new URL($item.find('a').attr('href') ?? '', 'https://www.hpoi.net').href;
if (!link.startsWith('https://www.hpoi.net')) {
return;
}
return await cache.tryGet(link, async () => {
const detailResponse = await got(link);
const $$ = load(detailResponse.data);
$$('.hpoi-album-content .album-ibox').remove();
$$('.hpoi-album-content .row').remove();
$$('.hpoi-album-content .hpoi-hr-line').remove();
return {
title: $item.find('.title').text(),
link,
description: $$('.hpoi-album-content').html() || `<img src="${$item.find('img').attr('src')}">`,
pubDate: new Date($item.find('.time').text().replace('发布时间:', '')).toUTCString(),
};
});
})
);
return {
title: `Hpoi 手办维基 - 热门推荐`,
link,
item: $('#content .item')
.toArray()
.map((_item) => {
_item = $(_item);
return {
title: _item.find('.title').text(),
link: 'https://www.hpoi.net/' + _item.find('a').attr('href'),
description: `<img src="${_item.find('img').attr('src')}">`,
pubDate: new Date(_item.find('.time').text().replace('发布时间:', '')).toUTCString(),
};
}),
item: items.filter((item) => !!item),
};
}