feat: add 有趣天文奇观年度天象 & 近期事件专题 (#6463)

This commit is contained in:
Ethan Shen
2020-12-18 16:55:58 +00:00
committed by GitHub
parent d3f9dafe31
commit 387c23852d
4 changed files with 95 additions and 0 deletions
+8
View File
@@ -1924,6 +1924,14 @@ column 为 third 时可选的 category:
<Route author="nczitzk" example="/interesting-sky" path="/interesting-sky"/>
### 年度天象(天文年历)
<Route author="nczitzk" example="/interesting-sky/astronomical_events" path="/interesting-sky/astronomical_events/:year?" :paramsDesc="['年份,默认为当前年份']"/>
### 近期事件专题
<Route author="nczitzk" example="/interesting-sky/recent-interesting" path="/interesting-sky/recent-interesting"/>
## 遠見
<Route author="laampui" example="/gvm/index/health" path="/gvm/index/:category?" :paramsDesc="['見下表, 默認爲 newest']">
+2
View File
@@ -3714,6 +3714,8 @@ router.get('/cmes/news/:category?', require('./routes/cmes/news'));
router.get('/craigslist/:location/:type', require('./routes/craigslist/search'));
// 有趣天文奇观
router.get('/interesting-sky/astronomical_events/:year?', require('./routes/interesting-sky/astronomical_events'));
router.get('/interesting-sky/recent-interesting', require('./routes/interesting-sky/recent-interesting'));
router.get('/interesting-sky', require('./routes/interesting-sky/index'));
// ACM
@@ -0,0 +1,38 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const year = ctx.params.year || new Date().getFullYear().toString();
const rootUrl = 'https://interesting-sky.china-vo.org';
const currentUrl = `${rootUrl}/category/year/${year}astronomical_events/`;
const response = await got({
method: 'get',
url: currentUrl,
});
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: $('title').text(),
link: currentUrl,
item: items,
};
};
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://interesting-sky.china-vo.org';
const currentUrl = `${rootUrl}/recent-interesting`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.sub-menu li p a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.entry-content').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};