feat: bbc cache
This commit is contained in:
parent
4803718318
commit
c235f1e24a
|
|
@ -47,38 +47,40 @@ module.exports = async (ctx) => {
|
|||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map(async (item) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
feed.items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let description;
|
||||
let description;
|
||||
|
||||
if (response.request.options.url.pathname.startsWith('/news/av')) {
|
||||
description = item.content;
|
||||
} else {
|
||||
description = utils.ProcessFeed($);
|
||||
}
|
||||
if (response.request.options.url.pathname.startsWith('/news/av')) {
|
||||
description = item.content;
|
||||
} else {
|
||||
description = utils.ProcessFeed($);
|
||||
}
|
||||
|
||||
let section = 'sport';
|
||||
const urlSplit = item.link.split('/');
|
||||
const sectionSplit = urlSplit[urlSplit.length - 1].split('-');
|
||||
if (sectionSplit.length > 1) {
|
||||
section = sectionSplit[0];
|
||||
}
|
||||
section = section[0].toUpperCase() + section.slice(1);
|
||||
let section = 'sport';
|
||||
const urlSplit = item.link.split('/');
|
||||
const sectionSplit = urlSplit[urlSplit.length - 1].split('-');
|
||||
if (sectionSplit.length > 1) {
|
||||
section = sectionSplit[0];
|
||||
}
|
||||
section = section[0].toUpperCase() + section.slice(1);
|
||||
|
||||
const single = {
|
||||
title: `[${section}] ${item.title}`,
|
||||
description,
|
||||
pubDate: item.pubDate,
|
||||
link: item.link,
|
||||
};
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
return {
|
||||
title: `[${section}] ${item.title}`,
|
||||
description,
|
||||
pubDate: item.pubDate,
|
||||
link: item.link,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue