route: add 爱思想 aisixiang.com (#1572)
* route: add 爱思想 aisixiang.com * route: add 爱思想排行榜 * docs
This commit is contained in:
parent
6f0a80fcd4
commit
effce02a98
|
|
@ -2506,6 +2506,18 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
|
|||
|
||||
<route name="章节" author="zsakvo" example="/wenku8/chapter/74" path="/wenku8/chapter/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到']"/>
|
||||
|
||||
### 爱思想
|
||||
|
||||
<route name="栏目" author="HenryQW" example="/aisixiang/column/722" path="/aisixiang/column/:id" :paramsDesc="['栏目 ID, 可在对应栏目 URL 中找到']"/>
|
||||
|
||||
<route name="排行榜" author="HenryQW" example="/aisixiang/column/1/7" path="/aisixiang/ranking/:type?/:range?" :paramsDesc="['排行榜类型', '排行榜范围, 仅适用于点击排行榜, 可选日(1),周(7),月(30)']">
|
||||
|
||||
| 文章点击排行 | 文章推荐排行 | 最近更新文章 |
|
||||
| ------------ | ------------ | ------------ |
|
||||
| 1 | 10 | 11 |
|
||||
|
||||
</route>
|
||||
|
||||
## 政务消息
|
||||
|
||||
### 中国驻外使领馆
|
||||
|
|
|
|||
|
|
@ -1045,6 +1045,10 @@ router.get('/gaoqing/latest', require('./routes/gaoqing/latest'));
|
|||
// 轻小说文库
|
||||
router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter'));
|
||||
|
||||
// 爱思想
|
||||
router.get('/aisixiang/column/:id', require('./routes/aisixiang/column'));
|
||||
router.get('/aisixiang/ranking/:type?/:range?', require('./routes/aisixiang/ranking'));
|
||||
|
||||
// LeetCode
|
||||
router.get('/leetcode/articles', require('./routes/leetcode/articles'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
const util = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
|
||||
const host = `http://www.aisixiang.com/data/search.php?lanmu=${id}`;
|
||||
|
||||
const response = await axios.get(host, {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
response.data = iconv.decode(response.data, 'gbk');
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.search_list > ul > li > a:nth-child(2)')
|
||||
.slice(0, 10)
|
||||
.get();
|
||||
|
||||
const columnName = $('.search_list > ul > li:nth-child(1) > a:nth-child(1)').text();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (e) => {
|
||||
const link = $(e).attr('href');
|
||||
return await ctx.cache.tryGet(link, async () => await util.ProcessFeed(link));
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `爱思想栏目 - ${columnName}`,
|
||||
link: host,
|
||||
description: `爱思想栏目 - ${columnName}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
const util = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { type = 1, range = 1 } = ctx.params;
|
||||
|
||||
const host = `http://www.aisixiang.com/toplist/index.php?id=${type}&period=${range}`;
|
||||
|
||||
const response = await axios.get(host, {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
response.data = iconv.decode(response.data, 'gbk');
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.tops_list > .tips > a')
|
||||
.slice(0, 10)
|
||||
.get();
|
||||
|
||||
const columnName = $('.tops_text > h3')[0].firstChild.nodeValue;
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (e) => {
|
||||
const link = $(e).attr('href');
|
||||
return await ctx.cache.tryGet(link, async () => await util.ProcessFeed(link));
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `爱思想 - ${columnName}`,
|
||||
link: host,
|
||||
description: `爱思想 - ${columnName}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
const axios = require('../../utils/axios');
|
||||
const date = require('../../utils/date');
|
||||
|
||||
const ProcessFeed = async (link) => {
|
||||
const id = link
|
||||
.split('/')
|
||||
.pop()
|
||||
.split('.')[0];
|
||||
|
||||
let response = await axios.get(`http://www.aisixiang.com/data/view_json.php?id=${id}`, {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
const description = JSON.parse(iconv.decode(response.data, 'gbk')).content;
|
||||
|
||||
response = await axios.get(`http://www.aisixiang.com${link}`, {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
response.data = iconv.decode(response.data, 'gbk');
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const title = $('.show_text > h3').text();
|
||||
|
||||
const pubDate = date(
|
||||
$('.show_text > .info')
|
||||
.text()
|
||||
.split(':')
|
||||
.pop(),
|
||||
8
|
||||
);
|
||||
|
||||
return {
|
||||
title: title.split('/')[1] || title,
|
||||
author: title.split('/')[0] || '',
|
||||
description,
|
||||
pubDate,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ProcessFeed,
|
||||
};
|
||||
Loading…
Reference in New Issue