feat: add interesting sky (#6453)

This commit is contained in:
Ethan Shen 2020-12-15 19:39:36 +08:00 committed by GitHub
parent de2bd58daa
commit 9790957b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -1918,6 +1918,12 @@ column 为 third 时可选的 category:
</Route>
## 有趣天文奇观
### 首页
<Route author="nczitzk" example="/interesting-sky" path="/interesting-sky"/>
## 遠見
<Route author="laampui" example="/gvm/index/health" path="/gvm/index/:category?" :paramsDesc="['見下表, 默認爲 newest']">

View File

@ -3710,4 +3710,7 @@ router.get('/cmes/news/:category?', require('./routes/cmes/news'));
// Craigslist
router.get('/craigslist/:location/:type', require('./routes/craigslist/search'));
// 有趣天文奇观
router.get('/interesting-sky', require('./routes/interesting-sky/index'));
module.exports = router;

View File

@ -0,0 +1,34 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://interesting-sky.china-vo.org';
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
const items = $('article')
.map((_, item) => {
item = $(item);
const title = item.find('.entry-title a');
return {
title: title.text(),
link: title.attr('href'),
author: item.find('.author').text(),
description: item.find('.article_content').html(),
pubDate: new Date(item.find('time.entry-date').attr('datetime')).toUTCString(),
};
})
.get();
ctx.state.data = {
title: '有趣天文奇观 - Interesting Sky',
link: rootUrl,
item: items,
};
};