mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-12 16:20:27 +08:00
feat: add NASA中文每日一图 (#5518)
This commit is contained in:
@@ -101,6 +101,18 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="nczitzk" example="/nasa/apod-ncku" path="/nasa/apod-ncku" />
|
<Route author="nczitzk" example="/nasa/apod-ncku" path="/nasa/apod-ncku" />
|
||||||
|
|
||||||
|
### NASA 中文
|
||||||
|
|
||||||
|
<Route author="nczitzk" example="/nasa/apod-cn" path="/nasa/apod-cn">
|
||||||
|
|
||||||
|
::: tip 提示
|
||||||
|
|
||||||
|
[NASA 中文](https://www.nasachina.cn/) 提供了每日天文图的中英双语图文说明,但在更新上偶尔略有一两天的延迟。
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## nHentai
|
## nHentai
|
||||||
|
|
||||||
### 分类筛选
|
### 分类筛选
|
||||||
|
|||||||
@@ -3102,6 +3102,7 @@ router.get('/soomal/topics/:category/:language?', require('./routes/soomal/topic
|
|||||||
// NASA
|
// NASA
|
||||||
router.get('/nasa/apod', require('./routes/nasa/apod'));
|
router.get('/nasa/apod', require('./routes/nasa/apod'));
|
||||||
router.get('/nasa/apod-ncku', require('./routes/nasa/apod-ncku'));
|
router.get('/nasa/apod-ncku', require('./routes/nasa/apod-ncku'));
|
||||||
|
router.get('/nasa/apod-cn', require('./routes/nasa/apod-cn'));
|
||||||
|
|
||||||
// 爱Q生活网
|
// 爱Q生活网
|
||||||
router.get('/iqshw/latest', require('./routes/iqshw/latest'));
|
router.get('/iqshw/latest', require('./routes/iqshw/latest'));
|
||||||
|
|||||||
64
lib/routes/nasa/apod-cn.js
Normal file
64
lib/routes/nasa/apod-cn.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const rootUrl = `https://www.nasachina.cn/apotd`;
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: rootUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
const list = $('div.post-archive article')
|
||||||
|
.slice(0, 3)
|
||||||
|
.map((_, item) => {
|
||||||
|
item = $(item);
|
||||||
|
const a = item.find('h2.entry-title a');
|
||||||
|
return {
|
||||||
|
title: a.text(),
|
||||||
|
link: a.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);
|
||||||
|
|
||||||
|
content('#wpd-post-rating').remove();
|
||||||
|
|
||||||
|
item.description = content('#main article').html();
|
||||||
|
|
||||||
|
let date;
|
||||||
|
|
||||||
|
if (content('h4').text()) {
|
||||||
|
date = content('h4').text().replace(/(年|月)/g, '-').replace(/日/, '');
|
||||||
|
item.title += ` | ${content('h4').text()}`;
|
||||||
|
} else {
|
||||||
|
date = new Date(content('time.entry-date').attr('datetime'));
|
||||||
|
const year = date.getFullYear().toString();
|
||||||
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||||
|
const day = date.getDate().toString().padStart(2, '0');
|
||||||
|
item.title += ` | ${year}年${month}月${day}日`;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.pubDate = new Date(date).toUTCString();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'NASA中文 - 天文·每日一图',
|
||||||
|
link: rootUrl,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -2,7 +2,7 @@ const got = require('@/utils/got');
|
|||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const date = new Date();
|
const date = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + -5 * 60 * 60 * 1000);
|
||||||
const year = date.getFullYear().toString();
|
const year = date.getFullYear().toString();
|
||||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||||
const day = date.getDate().toString().padStart(2, '0');
|
const day = date.getDate().toString().padStart(2, '0');
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const got = require('@/utils/got');
|
|||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const date = new Date();
|
const date = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + -5 * 60 * 60 * 1000);
|
||||||
const year = date.getFullYear().toString();
|
const year = date.getFullYear().toString();
|
||||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||||
const day = date.getDate().toString().padStart(2, '0');
|
const day = date.getDate().toString().padStart(2, '0');
|
||||||
|
|||||||
Reference in New Issue
Block a user