From 9790957b200b3550f62fd1f25ec5b5a0c3553bb2 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 15 Dec 2020 19:39:36 +0800 Subject: [PATCH] feat: add interesting sky (#6453) --- docs/new-media.md | 6 +++++ lib/router.js | 3 +++ lib/routes/interesting-sky/index.js | 34 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/routes/interesting-sky/index.js diff --git a/docs/new-media.md b/docs/new-media.md index acd342748..c55808bfe 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1918,6 +1918,12 @@ column 为 third 时可选的 category: +## 有趣天文奇观 + +### 首页 + + + ## 遠見 diff --git a/lib/router.js b/lib/router.js index 4207fe98b..dce70e035 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/interesting-sky/index.js b/lib/routes/interesting-sky/index.js new file mode 100644 index 000000000..babf1d2bb --- /dev/null +++ b/lib/routes/interesting-sky/index.js @@ -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, + }; +};