Files
RSSHub/lib/routes/aisixiang/utils.js
Henry Wang effce02a98 route: add 爱思想 aisixiang.com (#1572)
* route: add 爱思想 aisixiang.com

* route: add 爱思想排行榜

* docs
2019-02-19 12:06:22 +08:00

47 lines
1.1 KiB
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 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,
};