mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
feat(route): add 爱思想专题 (#12845)
This commit is contained in:
@@ -182,6 +182,18 @@ For instance, when doing search at <https://magazinelib.com/> and you get url <h
|
||||
|
||||
<Route author="HenryQW nczitzk" example="/aisixiang/column/722" path="/aisixiang/column/:id" :paramsDesc="['栏目 ID, 可在对应栏目 URL 中找到']"/>
|
||||
|
||||
### 专题
|
||||
|
||||
<Route author="nczitzk" example="/aisixiang/zhuanti/211" path="/aisixiang/zhuanti/:id" :paramsDesc="['专题 ID, 可在对应专题 URL 中找到']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
更多专题请见 [关键词](http://www.aisixiang.com/zhuanti/)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
### 排行
|
||||
|
||||
<Route author="HenryQW nczitzk" example="/aisixiang/toplist/1/7" path="/aisixiang/toplist/:id?/:period?" :paramsDesc="['类型', '范围, 仅适用于点击排行榜, 可选一天(1),一周(7),一月(30),所有(-1),默认为一天']">
|
||||
|
||||
+22
-13
@@ -1,36 +1,45 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { rootUrl, ProcessFeed } = require('./utils');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
|
||||
const { id } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const currentUrl = `${rootUrl}/data/search?column=${id}`;
|
||||
const currentUrl = new URL(`/data/search?column=${id}`, rootUrl).href;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const title = $('div.article-title a').first().text().replace(/\[|\]/g, '');
|
||||
|
||||
const items = $('div.search_list a[title]')
|
||||
const items = $('div.article-title')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('a[title]');
|
||||
|
||||
return {
|
||||
title: item.text().split(':').pop(),
|
||||
link: new URL(item.attr('href'), rootUrl).href,
|
||||
title: a.text(),
|
||||
link: new URL(a.prop('href'), rootUrl).href,
|
||||
author: a.text().split(':')[0],
|
||||
pubDate: timezone(parseDate(item.find('span').text()), +8),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
description: $('div.tips').text(),
|
||||
language: 'zh-cn',
|
||||
image: new URL('images/logo.jpg', ossUrl).href,
|
||||
subtitle: title,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,4 +3,5 @@ module.exports = {
|
||||
'/ranking/:id?/:period?': ['HenryQW', 'nczitzk'],
|
||||
'/toplist/:id?/:period?': ['nczitzk'],
|
||||
'/thinktank/:id/:type?': ['hoilc', 'nczitzk'],
|
||||
'/zhuanti/:id': ['nczitzk'],
|
||||
};
|
||||
|
||||
@@ -8,6 +8,12 @@ module.exports = {
|
||||
source: ['/data/search', '/'],
|
||||
target: (params, url) => `/aisixiang/column/${new URL(url).searchParams.get('column')}`,
|
||||
},
|
||||
{
|
||||
title: '专题',
|
||||
docs: 'https://docs.rsshub.app/reading.html#ai-si-xiang',
|
||||
source: ['/zhuanti', '/'],
|
||||
target: (params, url) => `/aisixiang/zhuanti/${new URL(url).href.match(/\/zhuanti\/(.*?)\.html/)[1]}`,
|
||||
},
|
||||
{
|
||||
title: '排行',
|
||||
docs: 'https://docs.rsshub.app/reading.html#ai-si-xiang',
|
||||
|
||||
@@ -3,4 +3,5 @@ module.exports = function (router) {
|
||||
router.get('/ranking/:id?/:period?', require('./toplist'));
|
||||
router.get('/toplist/:id?/:period?', require('./toplist'));
|
||||
router.get('/thinktank/:id/:type?', require('./thinktank'));
|
||||
router.get('/zhuanti/:id', require('./zhuanti'));
|
||||
};
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { rootUrl, ProcessFeed } = require('./utils');
|
||||
|
||||
const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const type = ctx.params.type ?? '';
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
|
||||
const { id, type = '' } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const currentUrl = `${rootUrl}/thinktank/${id}.html`;
|
||||
const currentUrl = new URL(`thinktank/${id}.html`, rootUrl).href;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const title = `${$('h2').first().text().trim()}${type}`;
|
||||
|
||||
@@ -31,19 +28,22 @@ module.exports = async (ctx) => {
|
||||
items = [...items, ...$(l).parent().find('ul li a').toArray()];
|
||||
}
|
||||
|
||||
items = items.map((item) => {
|
||||
items = items.slice(0, limit).map((item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
title: item.text().split(':').pop(),
|
||||
link: new URL(item.attr('href'), rootUrl).href,
|
||||
link: new URL(item.prop('href'), rootUrl).href,
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
description: $('div.thinktank-author-description-box p').text(),
|
||||
language: 'zh-cn',
|
||||
image: new URL('images/logo_thinktank.jpg', ossUrl).href,
|
||||
subtitle: title,
|
||||
};
|
||||
};
|
||||
|
||||
+21
-15
@@ -1,37 +1,43 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { rootUrl, ProcessFeed } = require('./utils');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id ?? '1';
|
||||
const period = ctx.params.period ?? '1';
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
|
||||
const { id = '1', period = '1' } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const currentUrl = `${rootUrl}/toplist${id ? `?id=${id}${id === '1' ? `&period=${period}` : ''}` : ''}`;
|
||||
const currentUrl = new URL(`toplist${id ? `?id=${id}${id === '1' ? `&period=${period}` : ''}` : ''}`, rootUrl).href;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const title = `${$('.hl').text() || ''}${$('title').text().split('_')[0]}`;
|
||||
const title = `${$('a.hl').text() || ''}${$('title').text().split('_')[0]}`;
|
||||
|
||||
const items = $('div.tips a')
|
||||
const items = $('div.tops_list')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('div.tips a');
|
||||
|
||||
return {
|
||||
title: item.text().split(':').pop(),
|
||||
link: new URL(item.attr('href'), rootUrl).href,
|
||||
title: a.text(),
|
||||
link: new URL(a.prop('href'), rootUrl).href,
|
||||
author: item.find('div.name').text(),
|
||||
pubDate: parseDate(item.find('div.times').text()),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
language: 'zh-cn',
|
||||
image: new URL('images/logo_toplist.jpg', ossUrl).href,
|
||||
subtitle: title,
|
||||
};
|
||||
};
|
||||
|
||||
+16
-10
@@ -3,28 +3,33 @@ const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const rootUrl = 'http://www.aisixiang.com';
|
||||
const ossUrl = 'https://oss.aisixiang.com';
|
||||
const rootUrl = 'https://www.aisixiang.com';
|
||||
|
||||
const ProcessFeed = (limit, tryGet, items) =>
|
||||
Promise.all(
|
||||
items.slice(0, limit).map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const { data: detailResponse } = await got(item.link);
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
const content = cheerio.load(detailResponse);
|
||||
|
||||
item.author = content('strong').first().text();
|
||||
item.description = content('.article-content').html();
|
||||
item.pubDate = timezone(parseDate(content('.info').text().split('时间:').pop()), +8);
|
||||
const commentMatches = content('h3.comment-header')
|
||||
.text()
|
||||
.match(/评论(\d+)/);
|
||||
|
||||
item.title = content('h3').first().text().split(':').pop();
|
||||
item.description = content('div.article-content').html();
|
||||
item.author = content('div.about strong').first().text();
|
||||
item.category = content('u')
|
||||
.first()
|
||||
.parent()
|
||||
.find('u')
|
||||
.toArray()
|
||||
.map((a) => content(a).text());
|
||||
.map((c) => content(c).text());
|
||||
item.pubDate = timezone(parseDate(content('div.info').text().split('时间:').pop()), +8);
|
||||
item.upvotes = content('span.like-num').text() ? parseInt(content('span.like-num').text(), 10) : 0;
|
||||
item.comments = commentMatches ? parseInt(commentMatches[1], 10) : 0;
|
||||
|
||||
return item;
|
||||
})
|
||||
@@ -33,5 +38,6 @@ const ProcessFeed = (limit, tryGet, items) =>
|
||||
|
||||
module.exports = {
|
||||
rootUrl,
|
||||
ossUrl,
|
||||
ProcessFeed,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const currentUrl = new URL(`zhuanti/${id}.html`, rootUrl).href;
|
||||
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const title = $('div.tips h2').first().text();
|
||||
|
||||
const items = $('div.article-title')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('a');
|
||||
|
||||
return {
|
||||
title: a.text(),
|
||||
link: new URL(a.prop('href'), rootUrl).href,
|
||||
author: a.text().split(':')[0],
|
||||
pubDate: timezone(parseDate(item.find('span').text()), +8),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
item: await ProcessFeed(limit, ctx.cache.tryGet, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
description: $('div.tips p').text(),
|
||||
language: 'zh-cn',
|
||||
image: new URL('images/logo_zhuanti.jpg', ossUrl).href,
|
||||
subtitle: title,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user