Skip to content

Commit

Permalink
Merge pull request #970 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Jul 4, 2023
2 parents 924c85b + c3d3374 commit 164c040
Show file tree
Hide file tree
Showing 17 changed files with 215 additions and 162 deletions.
8 changes: 4 additions & 4 deletions docs/en/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ Parameters can be obtained from the official website, for instance:

### Category/Topic/Author

<RouteEn author="HenryQW proletarius101 LyleLee" example="/reuters/world/us" path="/reuters/:category/:topic?" :paramsDesc="['find it in the URL, or tables below', 'find it in the URL, or tables below']">
<RouteEn author="HenryQW proletarius101 LyleLee nczitzk" example="/reuters/world/us" path="/reuters/:category/:topic?" :paramsDesc="['find it in the URL, or tables below', 'find it in the URL, or tables below']">

- `:category`:
| World | Business | Legal | Markets | Breakingviews | Technology |
| -------- | ------- | ----- | -------- | ------------- | ---------- |
| world | business | legal | markets | breakingviews | technology |
| World | Business | Legal | Markets | Breakingviews | Technology | Graphics |
| ----- | -------- | ----- | ------- | ------------- | ---------- | -------- |
| world | business | legal | markets | breakingviews | technology | graphics |

- `world/:topic`:

Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@vuepress/plugin-pwa": "1.9.9",
"@vuepress/shared-utils": "1.9.9",
"markdown-it": "13.0.1",
"pinyin-pro": "3.15.2",
"pinyin-pro": "3.15.4",
"remark": "13.0.0",
"remark-frontmatter": "3.0.0",
"remark-gfm": "1.0.0",
Expand Down
12 changes: 8 additions & 4 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1524,12 +1524,12 @@ category 对应的关键词有

### 分类 / 话题 / 作者

<Route author="HenryQW proletarius101 LyleLee" example="/reuters/world/us" path="/reuters/:category/:topic?" :paramsDesc="['可在 URL 中找到,或参考下面的表格', '可在 URL 中找到,或参考下面的表格']">
<Route author="HenryQW proletarius101 LyleLee nczitzk" example="/reuters/world/us" path="/reuters/:category/:topic?" :paramsDesc="['可在 URL 中找到,或参考下面的表格', '可在 URL 中找到,或参考下面的表格']">

- `:category`:
| World | Business | Legal | Markets | Breakingviews | Technology |
| ----- | -------- | ----- | ------- | ------------- | ---------- |
| world | business | legal | markets | breakingviews | technology |
| World | Business | Legal | Markets | Breakingviews | Technology | Graphics |
| ----- | -------- | ----- | ------- | ------------- | ---------- | -------- |
| world | business | legal | markets | breakingviews | technology | graphics |

- `world/:topic`:

Expand Down
6 changes: 3 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3078,9 +3078,9 @@ router.get('/bioon/latest', lazyloadRouteHandler('./routes/bioon/latest'));
router.get('/soomal/topics/:category/:language?', lazyloadRouteHandler('./routes/soomal/topics'));

// NASA
router.get('/nasa/apod', lazyloadRouteHandler('./routes/nasa/apod'));
router.get('/nasa/apod-ncku', lazyloadRouteHandler('./routes/nasa/apod-ncku'));
router.get('/nasa/apod-cn', lazyloadRouteHandler('./routes/nasa/apod-cn'));
// router.get('/nasa/apod', lazyloadRouteHandler('./routes/nasa/apod'));
// router.get('/nasa/apod-ncku', lazyloadRouteHandler('./routes/nasa/apod-ncku'));
// router.get('/nasa/apod-cn', lazyloadRouteHandler('./routes/nasa/apod-cn'));

// 爱Q生活网
// router.get('/iqshw/latest', lazyloadRouteHandler('./routes/3k8/latest'));
Expand Down
66 changes: 0 additions & 66 deletions lib/routes/nasa/apod-cn.js

This file was deleted.

30 changes: 0 additions & 30 deletions lib/routes/nasa/apod-ncku.js

This file was deleted.

30 changes: 0 additions & 30 deletions lib/routes/nasa/apod.js

This file was deleted.

24 changes: 24 additions & 0 deletions lib/v2/nasa/apod-cn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;
const rootUrl = `https://www.nasachina.cn/wp-json/wp/v2/posts?categories=2&per_page=${limit}`;
const { data } = await got({
method: 'get',
url: rootUrl,
});

const items = data.map((item) => ({
title: item.title.rendered,
description: item.content.rendered,
pubDate: parseDate(item.date_gmt),
link: item.link,
}));

ctx.state.data = {
title: 'NASA中文 - 天文·每日一图',
link: 'https://www.nasachina.cn/nasa-image-of-the-day',
item: items,
};
};
51 changes: 51 additions & 0 deletions lib/v2/nasa/apod-ncku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;
const rootUrl = 'http://sprite.phys.ncku.edu.tw/astrolab/mirrors/apod/archivepix.html';
const response = await got({
method: 'get',
url: rootUrl,
});

const $ = cheerio.load(response.data);

const list = $('body > b > a')
.slice(0, limit)
.map((_, el) => ({
title: $(el).text(),
link: `http://sprite.phys.ncku.edu.tw/astrolab/mirrors/apod/${$(el).attr('href')}`,
}))
.get();

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

const description = `<img src="${content('img').attr('src')}"> <br> ${content('body > center').eq(1).html()} <br> ${content('body > p').eq(0).html()}`;
const pubDate = parseDate(item.link.slice(-11, -5), 'YYMMDD');

const single = {
title: item.title,
description,
pubDate,
link: item.link,
};
return single;
})
)
);

ctx.state.data = {
title: 'NASA 每日一天文圖 (成大物理分站) ',
link: rootUrl,
item: items,
};
};
51 changes: 51 additions & 0 deletions lib/v2/nasa/apod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;
const rootUrl = 'https://apod.nasa.gov/apod/archivepix.html';
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);

const list = $('body > b > a')
.slice(0, limit)
.map((_, el) => ({
title: $(el).text(),
link: `https://apod.nasa.gov/apod/${$(el).attr('href')}`,
}))
.get();

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

const description = `<img src="${content('img').attr('src')}"> <br> ${content('body > center').eq(1).html()} <br> ${content('body > p').eq(0).html()}`;
const pubDate = timezone(parseDate(item.link.slice(-11, -5), 'YYMMDD'), -5);

const single = {
title: item.title,
description,
pubDate,
link: item.link,
};
return single;
})
)
);

ctx.state.data = {
title: 'NASA Astronomy Picture of the Day',
link: rootUrl,
item: items,
};
};
5 changes: 5 additions & 0 deletions lib/v2/nasa/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'/apod': ['nczitzk', 'williamgateszhao'],
'/apod-ncku': ['nczitzk', 'williamgateszhao'],
'/apod-cn': ['nczitzk', 'williamgateszhao'],
};
22 changes: 22 additions & 0 deletions lib/v2/nasa/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
'nasa.gov': {
_name: 'NASA 每日天文图片',
apod: [
{
title: 'NASA',
docs: 'https://docs.rsshub.app/picture.html#nasa-mei-ri-tian-wen-tu-pian',
target: '/nasa/apod',
},
{
title: '台湾成功大学镜像',
docs: 'https://docs.rsshub.app/picture.html#nasa-mei-ri-tian-wen-tu-pian',
target: '/nasa/apod-ncku',
},
{
title: 'NASA 中文',
docs: 'https://docs.rsshub.app/picture.html#nasa-mei-ri-tian-wen-tu-pian',
target: '/nasa/apod-cn',
},
],
},
};
5 changes: 5 additions & 0 deletions lib/v2/nasa/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/apod', require('./apod'));
router.get('/apod-ncku', require('./apod-ncku'));
router.get('/apod-cn', require('./apod-cn'));
};
Loading

1 comment on commit 164c040

@vercel
Copy link

@vercel vercel bot commented on 164c040 Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.