feat(route): add react-native-weekly (#7068)

This commit is contained in:
xixi
2021-03-07 18:12:43 +08:00
committed by GitHub
parent 8e9a2afd1b
commit 2eebd17f6c
4 changed files with 49 additions and 0 deletions

View File

@@ -239,3 +239,9 @@ Website: https://news.ycombinator.com/
| featured | trending | trending_m | trending_d | popular | new |
</RouteEn>
## react
### react-native
<RouteEn author="xixi" example="/react/react-native-weekly" path="/react/react-native-weekly" />

View File

@@ -322,6 +322,12 @@ GitHub 官方也提供了一些 RSS:
<Route author="hellodword" example="/project-zero-issues" path="/project-zero-issues" />
## react
### react-native
<Route author="xixi" example="/react/react-native-weekly" path="/react/react-native-weekly" />
## Scala
### Scala Blog

View File

@@ -4024,4 +4024,6 @@ router.get('/gf-cn/news/:category?', require('./routes/gf-cn/news'));
// Eagle
router.get('/eagle/changelog/:language?', require('./routes/eagle/changelog'));
// react
router.get('/react/react-native-weekly', require('./routes/react/react-native-weekly'));
module.exports = router;

35
lib/routes/react/react-native-weekly.js vendored Normal file
View File

@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const host = 'https://reactnative.cc';
const response = await got({
method: 'get',
url: `${host}/issues.html`,
});
const data = response.data;
const $ = cheerio.load(data);
const newestHref = $('.past-issues-header>ul').first().find('li a').attr('href');
const detailResponse = await got({
method: 'get',
url: `${host}${newestHref}`,
});
const $2 = cheerio.load(detailResponse.data);
const list = $2('.mcnCaptionBottomContent .mcnTextContent a', 'body');
ctx.state.data = {
title: 'react-native-weekly',
link: 'https://reactnative.cc',
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.text().replace(/\s{2}/g, ''),
link: item.attr('href'),
};
})
.get(),
};
};