Files
RSSHub/lib/v2/aisixiang/column.js
T
Ethan Shen cbca59f390 fix(route): 爱思想栏目 & 排行 & 思想库 (#12541)
* fix(route): 爱思想栏目

* remove unnecessary await

---------
2023-05-20 03:10:24 +08:00

37 lines
990 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { rootUrl, ProcessFeed } = require('./utils');
module.exports = async (ctx) => {
const id = ctx.params.id;
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
const currentUrl = `${rootUrl}/data/search?column=${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const title = $('div.article-title a').first().text().replace(/\[|\]/g, '');
const items = $('div.search_list a[title]')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text().split(':').pop(),
link: new URL(item.attr('href'), rootUrl).href,
};
});
ctx.state.data = {
title: `爱思想 - ${title}`,
link: currentUrl,
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
};
};