feat: add iCity用户动态 (#5796)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-10-08 15:17:45 +01:00
committed by GitHub
co-authored by Henry Wang
parent bb3f9cde6b
commit 35f37a6d62
3 changed files with 39 additions and 0 deletions
+6
View File
@@ -298,6 +298,12 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
<Route author="maple3142" example="/facebook/page/SonetPCR" path="/facebook/page/:id" :paramsDesc="['專頁 id']" anticrawler="1"/>
## iCity
### 用户动态
<Route author="nczitzk" example="/icity/sai" path="/icity/:id" :paramsDesc="['用户 id']"/>
## Keep
### 运动日记
+3
View File
@@ -3260,6 +3260,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index'));
// CGTN
router.get('/cgtn/top', require('./routes/cgtn/top'));
// iCity
router.get('/icity/:id', require('./routes/icity/index'));
// Anki
router.get('/anki/changes', require('./routes/anki/changes'));
+30
View File
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = `https://icity.ly/u/${ctx.params.id}`;
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
const items = $('li.diary')
.map((_, item) => {
item = $(item);
return {
link: rootUrl,
title: item.prev('li.day-cut').text(),
description: item.find('div.line').html(),
pubDate: new Date(item.find('time.hours').attr('datetime')).toUTCString(),
};
})
.get();
ctx.state.data = {
title: $('title').text(),
link: rootUrl,
item: items,
description: $('div.bio').text(),
};
};