fix(route/cna): Unify full text fetching method (#19346)
This commit is contained in:
parent
5458b06a85
commit
4c7840f6f7
|
|
@ -1,9 +1,9 @@
|
|||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { getFullText } from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/:id?',
|
||||
|
|
@ -53,29 +53,7 @@ async function handler(ctx) {
|
|||
pubDate: timezone(parseDate(item.CreateTime), +8),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = load(detailResponse.data);
|
||||
content('div.SubscriptionInner').remove();
|
||||
const topImage = content('.fullPic').html();
|
||||
|
||||
item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
|
||||
item.category = [
|
||||
...content("meta[property='article:tag']")
|
||||
.toArray()
|
||||
.map((e) => e.attribs.content),
|
||||
content('.active > a').text(),
|
||||
];
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
const items = await Promise.all(list.map((item) => cache.tryGet(item.link, async () => await getFullText(item))));
|
||||
|
||||
return {
|
||||
title: metadata.Title,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
|
||||
export async function getFullText(item) {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = load(detailResponse.data);
|
||||
content('div.SubscriptionInner').remove();
|
||||
content('.gmailNews').remove();
|
||||
const topImage = content('.fullPic').html();
|
||||
|
||||
item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
|
||||
item.category = [
|
||||
...content("meta[property='article:tag']")
|
||||
.toArray()
|
||||
.map((e) => e.attribs.content),
|
||||
content('.active > a').text(),
|
||||
];
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import got from '@/utils/got';
|
|||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { getFullText } from '../utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/web/:id?',
|
||||
|
|
@ -45,28 +46,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = load(detailResponse.data);
|
||||
const topImage = content('.fullPic').html();
|
||||
|
||||
item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
|
||||
item.category = [
|
||||
...content("meta[property='article:tag']")
|
||||
.toArray()
|
||||
.map((e) => e.attribs.content),
|
||||
content('.active > a').text(),
|
||||
];
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
const items = await Promise.all(list.map((item) => cache.tryGet(item.link, async () => await getFullText(item))));
|
||||
|
||||
return {
|
||||
title: $('title').text(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue