fix
This commit is contained in:
parent
4c2b462071
commit
bd6effd2e2
|
|
@ -1,7 +1,7 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
function getArticle(line) {
|
||||
function getArticle(ctx, line, tasks) {
|
||||
const article = ctx.cache.tryGet(line, async () => {
|
||||
const a_r = await got.get(`https://app3.rthk.hk/mediadigest/${line}`);
|
||||
const $ = cheerio.load(a_r.data);
|
||||
|
|
@ -11,7 +11,7 @@ function getArticle(line) {
|
|||
const author_list = $('div.story-author');
|
||||
const authors = author_list.map((_index, author) => $(author).text());
|
||||
const author = authors.map((_index, author) => `<b>${author}</b><br>`);
|
||||
const s_author = author.toArray().join("");
|
||||
const s_author = author.toArray().join('');
|
||||
const author_block = `<blockquote><p>${s_author}</p></blockquote>`;
|
||||
// date
|
||||
const date = $('div.story-calendar').text();
|
||||
|
|
@ -37,27 +37,37 @@ module.exports = async (ctx) => {
|
|||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.category-line');
|
||||
|
||||
list.map((_index, line) => $(line).find('a').first().attr('href'))
|
||||
.each((_index, line) => {
|
||||
getArticle(line);
|
||||
});
|
||||
list.map((_index, line) => $(line).find('a').first().attr('href')).each((_index, line) => {
|
||||
getArticle(ctx, line, tasks);
|
||||
});
|
||||
} else {
|
||||
let cids = [1, 2]; for (let i = 4; i < 28; ++i) {cids.push(i);};
|
||||
let urls = cids.map((cid) => `https://app3.rthk.hk/mediadigest/category.php?cid=${cid}`);
|
||||
const cids = [1, 2];
|
||||
for (let i = 4; i < 28; ++i) {
|
||||
cids.push(i);
|
||||
}
|
||||
const urls = cids.map((cid) => `https://app3.rthk.hk/mediadigest/category.php?cid=${cid}`);
|
||||
const list_allt = await Promise.all(
|
||||
urls.map(async (url) => {
|
||||
const response = await got.get(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.category-line').map((_index, line) => $(line).find('a').first().attr('href'));
|
||||
const list = $('div.category-line').map((_index, line) => $(line).find('a').first().attr('href'));
|
||||
return Promise.resolve(list.toArray());
|
||||
})
|
||||
);
|
||||
const list_all = [...new Set(list_allt.flat())];
|
||||
|
||||
list_all.forEach((line) => {
|
||||
getArticle(line);
|
||||
const list_recent_20 = list_all
|
||||
.sort((a, b) => {
|
||||
const aid_a = a.match(/aid=(\d+)/)[1];
|
||||
const aid_b = b.match(/aid=(\d+)/)[1];
|
||||
// reverse
|
||||
return aid_b - aid_a;
|
||||
})
|
||||
.slice(0, 20);
|
||||
list_recent_20.forEach((line) => {
|
||||
getArticle(ctx, line, tasks);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const rss = await Promise.all(tasks);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue