feat: add lwn.net security alerts (#2491)
This commit is contained in:
parent
a9b6380461
commit
ed2046981b
|
|
@ -172,6 +172,36 @@ GitHub 官方也提供了一些 RSS:
|
|||
|
||||
<Route author="ysc3839" example="/patchwork.kernel.org/comments/10723629" path="/patchwork.kernel.org/comments/:id" :paramsDesc="['Patch ID']"/>
|
||||
|
||||
## LWN.net
|
||||
|
||||
### Security alerts
|
||||
|
||||
<Route author="zengxs" example="/lwn/alerts/CentOS" path="/lwn/alerts/:distributor" :paramsDesc="['对应发行版标识']">
|
||||
|
||||
| 发行版 | 标识 |
|
||||
| :--------------- | :----------------- |
|
||||
| Arch Linux | `Arch_Linux` |
|
||||
| CentOS | `CentOS` |
|
||||
| Debian | `Debian` |
|
||||
| Fedora | `Fedora` |
|
||||
| Gentoo | `Gentoo` |
|
||||
| Mageia | `Mageia` |
|
||||
| openSUSE | `openSUSE` |
|
||||
| Oracle | `Oracle` |
|
||||
| Red Hat | `Red_Hat` |
|
||||
| Scientific Linux | `Scientific_Linux` |
|
||||
| Slackware | `Slackware` |
|
||||
| SUSE | `SUSE` |
|
||||
| Ubuntu | `Ubuntu` |
|
||||
|
||||
::: tip 提示
|
||||
|
||||
注意标识大小写
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## segmentfault
|
||||
|
||||
### 频道
|
||||
|
|
|
|||
|
|
@ -1439,4 +1439,7 @@ router.get('/8btc/:authorid', require('./routes/8btc/author'));
|
|||
// VueVlog
|
||||
router.get('/vuevideo/:userid', require('./routes/vuevideo/user'));
|
||||
|
||||
// LWN.net Alerts
|
||||
router.get('/lwn/alerts/:distributor', require('./routes/lwn/alerts'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const date = require('@/utils/date');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const distributor = ctx.params.distributor;
|
||||
const listUrl = `https://lwn.net/Alerts/${distributor}/`;
|
||||
const res = await got({
|
||||
method: 'get',
|
||||
url: listUrl,
|
||||
});
|
||||
const $ = cheerio.load(res.data);
|
||||
const title = $('.PageHeadline').text();
|
||||
const list = $('.ArticleText').find('table tbody tr:not(:first-of-type)');
|
||||
const count = [];
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
count.push(i);
|
||||
}
|
||||
const resultItem = await Promise.all(
|
||||
count.map(async (i) => {
|
||||
const each = $(list[i]);
|
||||
const originalUrl = each.find('td > a').attr('href');
|
||||
const link = url.resolve('https://lwn.net', originalUrl);
|
||||
const pubDate = date(each.find('td:nth-of-type(3)').text());
|
||||
|
||||
const cacheKey = `LWN.net:${link}`;
|
||||
const cacheValue = await ctx.cache.get(cacheKey);
|
||||
|
||||
let item;
|
||||
if (cacheValue) {
|
||||
item = JSON.parse(cacheValue);
|
||||
} else {
|
||||
const detail = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const content = cheerio.load(detail.data);
|
||||
item = {
|
||||
title: content('.PageHeadline').text(),
|
||||
description: content('.ArticleText').html(),
|
||||
link: link,
|
||||
pubDate: pubDate,
|
||||
};
|
||||
ctx.cache.set(cacheKey, JSON.stringify(item));
|
||||
}
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: listUrl,
|
||||
item: resultItem,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue