feat: hpoi banner-item details
This commit is contained in:
parent
590dffab2b
commit
1041cfdcaa
|
|
@ -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),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue